Skip to content

chahatsagarmain/SongSnatch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🎵 Spotify Downloader API + CLI + WORKER QUEUE

This project provides an integrated FastAPI backend and Typer CLI tool to download songs from Spotify links (track, album, or playlist) by searching for the corresponding YouTube audio and saving it locally as .mp3.

Apart from the above methods the whole application can be run as a scalable backend using Worker Queue (in our case RabbitMQ) . NodeJS server produces messages which is consumed by our python program to download songs .


📦 Features

✅ FastAPI Backend (HTTP API)

  • /v1/spotify/find – Accepts Spotify URL, fetches metadata, downloads from YouTube.
  • /v1/song/list – Lists downloaded songs.
  • /v1/song/download/{song_name} – Serves MP3 file for download or playback.

✅ Typer CLI Tool

  • spotify-find <url> – Downloads from Spotify track/album/playlist link.
  • list-songs – Lists locally saved MP3s.
  • download-song <name> – Prints absolute path to downloaded MP3.
  • install-completion – Enables shell autocomplete for CLI.

🚀 Getting Started

🛠 Prerequisites

  • Python 3.9+
  • ffmpeg installed and in PATH
  • YouTube-dl / yt-dlp compatible backend for downloading
  • Optional: .env file for environment variables like port

🧪 Running the API

Install dependencies

pip install -r requirements.txt

Run the API

python main.py

Default: http://localhost:8000

API Endpoints

Method Endpoint Description
POST /v1/spotify/find?url=... Download audio from Spotify URL
GET /v1/song/list List all downloaded songs
GET /v1/song/download/{song_name} Stream or download specific MP3
GET / Root health check

🔧 Using the CLI Tool

Install typer if not already:

pip install typer[all]

Run CLI commands

python cli.py spotify-find "<spotify-url>"
python cli.py list-songs
python cli.py download-song "song1.mp3"

⚙️ Configuration (Optional)

Set the port in .env: Enter the spotify dev account credentials

WORKER_PORT=8000
SPOTIFY_CLIENT_ID=clientid_here
SPOTIFY_CLIENT_SECRET=secret_here

📚 Example

Download from Spotify

python cli.py spotify-find "https://open.spotify.com/track/xyz"

Or via API:

curl -X POST "http://localhost:8000/v1/spotify/find?url=https://open.spotify.com/track/xyz"

🛠️ Setup: SongSnatch with Worker Queue

This project allows users to download songs from Spotify (track, album, or playlist) using a background worker architecture with:

  • Node.js (API producer)
  • Python (worker/consumer)
  • Redis (job tracking)
  • RabbitMQ (task queue)

✅ Prerequisites

Ensure the following are installed:


🐇 1. Start RabbitMQ (with Management UI)

docker run -it --rm -d \
  --name rabbitmq \
  -p 5672:5672 \
  -p 15672:15672 \
  rabbitmq:3-management

🧠 2. Start Redis

docker run -d \
  --name redis \
  -p 6379:6379 \
  redis:latest

🚀 3. Start the Node.js Producer (API Server)

cd producer
npm install
npm start

⚙️ 4. Start the Python Worker (Consumer)

cd worker
pip3 install -r requirements.txt
python3 consumer.py

🌐 API Endpoints

Method Route Description
GET /v1/find?url=<spotify_url> Queue a Spotify download job
GET /v1/status?jobId=<job_id> Check job status in Redis
GET /v1/download/:song_name Download a completed MP3 file

📦 Example API Requests

🎶 Queue a song/album/playlist for download

GET http://localhost:8000/v1/find?url=https://open.spotify.com/album/6AyUVv7MnxxTuijp4WmrhO

📊 Check job status

GET http://localhost:8000/v1/status?jobId=0197fe57-6334-767e-aae2-0dd415799d46

Response from Redis (example):

{
  "jobId": "0197fe57-6334-767e-aae2-0dd415799d46",
  "status": "completed",
  "songs": ["Muse - Unintended.mp3"]
}

📥 Download a specific MP3 file

GET http://localhost:8000/v1/download/Muse%20-%20Unintended.mp3

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published