How to Download Music From Deezer (in Python)

Downloading music from Deezer is incredibly easy in Python, all you’ll need is a Deezer account and some extra storage space. To get started, you’ll need to install pydeezer:

pip3 install pydeezer

Next, let’s log into deezer and get our authentication token, known as the “arl”. After you’ve signed in (this works best on Chrome/Brave), click the security lock icon, then click cookies. Select “deezer.com”, and find your arl token in the list of cookies.

It’s time to code. Open your favorite editor, and paste the following starter code in:

from pydeezer import Deezer
from pydeezer import Downloader
from pydeezer.constants import track_formats

arl = "YOUR_ARL_HERE"

Make sure to replace YOUR_ARL_HERE with the ARL token that you just wrote down. Next, let’s create a function that scrapes the Deezer search results to find your song.

def rip(songs, dir):
    deezer = Deezer(arl=arl)
    song_list = []
    for song in songs:
        track_search_results = deezer.search_tracks(song)
        sl.append(track_search_results[0]['id'])

This function will take a list of songs and the save directory as arguments. It will go song by song, and take the first result from the Deezer search API, and add it too the list. Next, we can add code to download each song from the list in high quality.

downloader = Downloader(deezer, song_list, dir,
                            quality=track_formats.MP3_320, concurrent_downloads=2)
downloader.start()

You can tweak the arguments of this downloader function if you would like to change the quality or number of songs that can download at the same time. It’s time to test it out, let’s run the function!

rip(["Once in a lifetime", "take me to the river", "psycho killer"], "/home/trent/Music")

If you have the correct ARL set earlier in your code, this should run well. In all your code should look like this:

from pydeezer import Deezer
from pydeezer import Downloader
from pydeezer.constants import track_formats

arl = "YOUR_ARL_HERE"

def rip(songs, dir):
    deezer = Deezer(arl=arl)
    song_list = []
    for song in songs:
        track_search_results = deezer.search_tracks(song)
        sl.append(track_search_results[0]['id'])
    downloader = Downloader(deezer, song_list, dir,
                            quality=track_formats.MP3_320, concurrent_downloads=2)
    downloader.start()

rip(["Once in a lifetime", "take me to the river", "psycho killer"], "/home/trent/Music")

If you’ve enjoyed or have questions, let me know!

Leave a Reply

Your email address will not be published. Required fields are marked *