Skip to content

Instantly share code, notes, and snippets.

@HirbodBehnam
Last active August 8, 2025 18:19
Show Gist options
  • Select an option

  • Save HirbodBehnam/4e9c11f874ae925375b8dbbe4d8a27d6 to your computer and use it in GitHub Desktop.

Select an option

Save HirbodBehnam/4e9c11f874ae925375b8dbbe4d8a27d6 to your computer and use it in GitHub Desktop.
This script will help you download tracks from http://www.spotmybackup.com/
import json
import os
import requests
import shutil
import spotipy
import sys
from bs4 import BeautifulSoup
from deezloader import Login # https://github.com/An0nimia/deezloader
from glob import glob
headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.182 Safari/537.36'} # Mimic chrome. If we don't do this, the og:description will be a bit different
downloa = Login("") # Fill this with deezer api
# Usage python3 dl.py backup.json [--liked] [playlist_name]
# Parse json
f = open(sys.argv[1], "r")
jsonObj = json.loads(f.read())
f.close()
# Parse arguments
if sys.argv[2] == "--liked":
jsonObj = jsonObj["saved"]
else:
jsonObj = jsonObj["playlists"][sys.argv[2]]["tracks"]
# Make folder for playlist
playlist_folder = sys.argv[2]
if playlist_folder == "--liked":
playlist_folder = "Liked Songs"
# Create playlist directory
try:
os.makedirs("Songs/" + playlist_folder, exist_ok=True)
except OSError as error:
print(error)
# Download each track
for track in jsonObj:
try:
downloa.download_trackspo("https://open.spotify.com/track/" + track["id"], "Songs/tmp","MP3_320", False, False, False)
except:
continue
# Get song info from spotify
r = requests.get('https://open.spotify.com/track/' + track["id"], headers=headers)
soup = BeautifulSoup(r.content, "lxml")
tempSoup = soup.find("meta", property="og:title")
title = tempSoup["content"] if tempSoup else "NA"
tempSoup = soup.find("meta", property="og:description")
artist = tempSoup["content"].split('·')[0].strip() if tempSoup else "NA"
# Move data
g = list(glob("Songs/tmp/*/*"))
filename = title + " - " + artist
filenameSafe = "".join(x for x in filename if (x.isalnum() or x == " " or x == "-")) # Some of the files have unsafe names
os.rename(g[0],"Songs/" + playlist_folder + "/" + filenameSafe +".mp3")
shutil.rmtree("Songs/tmp/")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment