Wallpaper-gen

go back / p4p1


Created on Mon. 20 April 2020



I was in need of a new wallpaper, and I wanted to make one from my album collection, I have around 400 albums saved in my youtube music gallery so that's clearly enough for a wallpaper,

How I built it

I have no prior knowledge of Image processing in any programming language, so after some googling I found a nice python library called PIL. That library looked good enough for me, I just needed to crop the images to a fitting size and place them on a blank canvas.

I started by downloading 4 sample Images and wanted to do a basic square canvas of 1000x1000 pixels. In my script I first enumerate each file and save them inside of an array as so:

          
            onlyfiles=[f for f in os.listdir(DIR) if os.path.isfile(os.path.join(DIR, f))]
          
        

I then created a new image using the python library:

With the new image set I then looped through the 4 sample files and used the paste function of the PIL library to paste inside of the destination main picture.

Now I need some arithmetic to have the picture size scale accoridingly to the resolution passed in parameter to the function so that I could work with x amount of images.

          
                one_side=math.trunc(math.sqrt((screen_size[0]*screen_size[1]) / number_files))
          
        

Because each album artwork is a square I just had to calculate only one side of the square without taking account weird width of screens and such.

Now with the python script ready I now need a way to download every single album artwork from YoutubeMusic. I looked online for a bit to see if youtube music has an API, but with no solution on the horizon I decided to extract them myself. With the Network Monitor builtin of most modern browsers I can create a .har file that keeps track of all of the requests my browser sent to music.youtube.com with that in mind, I built a python script that downloads Images from a .har file.

Tutorial

You first have to dump the youtube music album covers to do that, I visited the page music.youtube.com/library/playlists. Opened my Network Inspector, I then clicked on the Album link and scrolled all the way down so that my browser picked up all of the artworks.

I then exported the .har into the folder I had the ytm_extractor.py script in and ran the script:

The output should be similar to this with a bunch of output corresponding to each file downloaded. You then have to run the wallpaper-gen script with the corresponding arguments and the wallpaper should be generated:

Web version

If you don't want to bother with the python scripts you can still use the web version I made here.


Thank you for reading, please follow me on github and check out this forum a bit more I work on some cool projects. Share the page to your rice crazy friends.


Questions / Feedback
For any questions or feedback you can contact me on LinkedIn or twitter / X. I also use twitter as a platform to update on new posts!
Donate
sponsor me image

If you like the content of my website you can help me out by donating through my github sponsors page.