Created
August 7, 2025 23:09
-
-
Save Ssenseii/9bf5b2b0059d0f369fc9208e10ba46c1 to your computer and use it in GitHub Desktop.
Download your spotify tracks using your spotify data and python (requires python, ffmpeg, ytd-lp)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| import subprocess | |
| import time | |
| import os | |
| import math | |
| # ===== CONFIG ===== | |
| JSON_FILE = "tracks.json" | |
| OUTPUT_DIR = "music" | |
| AUDIO_FORMAT = "mp3" | |
| SLEEP_BETWEEN = 5 # seconds between downloads | |
| AVERAGE_DOWNLOAD_TIME = 20 # estimated seconds per track (adjust if needed) | |
| # ================== | |
| # Create music folder if not exists | |
| os.makedirs(OUTPUT_DIR, exist_ok=True) | |
| # Load track list | |
| with open(JSON_FILE, "r", encoding="utf-8") as f: | |
| data = json.load(f) | |
| total_tracks = len(data["tracks"]) | |
| # Estimate total time | |
| estimated_total_seconds = (AVERAGE_DOWNLOAD_TIME + SLEEP_BETWEEN) * total_tracks | |
| estimated_minutes = math.ceil(estimated_total_seconds / 60) | |
| print(f"\nπ΅ Found {total_tracks} tracks in {JSON_FILE}") | |
| print(f"π Output folder: {OUTPUT_DIR}") | |
| print(f"β³ Estimated total time: ~{estimated_minutes} minutes " | |
| f"({AVERAGE_DOWNLOAD_TIME + SLEEP_BETWEEN} sec per track)") | |
| print("=" * 50, "\n") | |
| # Loop through tracks | |
| for i, entry in enumerate(data["tracks"], start=1): | |
| artist = entry['artist'].strip() | |
| track = entry['track'].strip() | |
| query = f"{artist} - {track}" | |
| filename = f"{artist} - {track}".replace("/", "-") # avoid folder issues | |
| print(f"[{i}/{total_tracks}] πΆ Starting download: {query}") | |
| # yt-dlp command | |
| cmd = [ | |
| "yt-dlp", | |
| f"ytsearch1:{query}", | |
| "-x", | |
| "--audio-format", AUDIO_FORMAT, | |
| "-o", os.path.join(OUTPUT_DIR, f"{filename}.%(ext)s") | |
| ] | |
| print(f"π Searching & downloading from YouTube...") | |
| print(f"πΎ Saving as {filename}.{AUDIO_FORMAT} in {OUTPUT_DIR}/") | |
| print("-" * 50) | |
| # Run command and stream output directly to terminal | |
| process = subprocess.Popen(cmd) | |
| process.wait() # Wait until finished | |
| if process.returncode == 0: | |
| print(f"β Downloaded successfully: {query}") | |
| else: | |
| print(f"β Failed to download: {query}") | |
| print("-" * 50) | |
| time.sleep(SLEEP_BETWEEN) | |
| print("\nπ All downloads completed!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment