Skip to main content

A Python library to download music from YouTube, SoundCloud, Spotify and more

Project description

pyMusic Downloader

PyPI version Python 3.8+ License: MIT

A powerful Python library and CLI tool to download music from YouTube, SoundCloud, Spotify, Bandcamp, and more.

Features

  • YouTube: Download single tracks or entire playlists
  • SoundCloud: Download tracks and playlists
  • Spotify: Resolve Spotify metadata and download via YouTube
  • Bandcamp: Download tracks and albums
  • Generic: Download from any yt-dlp supported source
  • Formats: MP3, M4A, FLAC, WAV, OGG
  • Metadata: Automatic ID3 tag embedding (title, artist, album, artwork)
  • CLI: Full-featured command-line interface
  • Python API: Clean, intuitive programmatic interface

Installation

pip install pymusic-downloader

Note: ffmpeg must be installed on your system for audio conversion.

  • macOS: brew install ffmpeg
  • Ubuntu/Debian: sudo apt install ffmpeg
  • Windows: Download from ffmpeg.org

Install from source:

git clone https://github.com/ransjnr/pymusic
cd pymusic
pip install -e .

Quick Start

CLI Usage

# Download a YouTube video as MP3
pymusic download "https://www.youtube.com/watch?v=dQw4w9WgXcQ"

# Download a YouTube playlist
pymusic download "https://www.youtube.com/playlist?list=PLxxxxxx"

# Download from SoundCloud
pymusic download "https://soundcloud.com/artist/track"

# Download a Spotify track (resolves via YouTube)
pymusic download "https://open.spotify.com/track/xxxxxx" \
  --spotify-id YOUR_CLIENT_ID --spotify-secret YOUR_CLIENT_SECRET

# Specify output format and directory
pymusic download "https://www.youtube.com/watch?v=dQw4w9WgXcQ" \
  --format mp3 --quality 320 --output ~/Music

# Search and download
pymusic search "Never Gonna Give You Up Rick Astley" --download

# Browse results and pick interactively
pymusic search "Daft Punk" --pick

# Show metadata without downloading
pymusic info "https://www.youtube.com/playlist?list=PLxxxxxx"

Python API Usage

from pymusic import PyMusic

# Initialize
pm = PyMusic(output_dir="~/Music", format="mp3", quality=320)

# Download a single YouTube track
track = pm.download("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(f"Downloaded: {track.title} by {track.artist}")
print(f"Saved to:   {track.file_path}")

# Download a YouTube playlist
playlist = pm.download("https://www.youtube.com/playlist?list=PLxxxxxx")
print(f"{playlist.title}: {len(playlist.downloaded_tracks)}/{playlist.total_tracks} tracks")

# Search YouTube and download
results = pm.search("Never Gonna Give You Up", limit=5)
for i, r in enumerate(results, 1):
    print(f"{i}. {r.display_name} [{r.duration_str}]")

track = pm.search_and_download("Never Gonna Give You Up Rick Astley")

# Download from SoundCloud
track = pm.download("https://soundcloud.com/artist/track")

# Download from Spotify (resolves via YouTube)
pm2 = PyMusic(
    spotify_client_id="your_id",
    spotify_client_secret="your_secret",
)
track = pm2.download("https://open.spotify.com/track/xxxxxx")

# Get metadata without downloading
info = pm.get_info("https://www.youtube.com/watch?v=dQw4w9WgXcQ")
print(f"{info.title}{info.duration_str}")

Advanced Configuration

from pymusic import PyMusic
from pymusic.config import Config

config = Config(
    output_dir="~/Music",
    format="mp3",
    quality=320,
    embed_metadata=True,
    embed_thumbnail=True,
    create_subdirs=True,        # Organise as Artist/Album/Track
    overwrite=False,
    playlist_start=1,
    playlist_end=50,
    rate_limit="1M",            # Limit download speed
    proxy="socks5://127.0.0.1:1080",
    spotify_client_id="your_id",
    spotify_client_secret="your_secret",
)

pm = PyMusic(config=config)

Environment Variables

export SPOTIFY_CLIENT_ID=your_spotify_client_id
export SPOTIFY_CLIENT_SECRET=your_spotify_client_secret
export PYMUSIC_OUTPUT_DIR=~/Music
export PYMUSIC_FORMAT=mp3
export PYMUSIC_QUALITY=320

Supported Sources

Source Singles Playlists Metadata Artwork
YouTube
SoundCloud
Spotify*
Bandcamp
Generic

* Spotify audio is sourced from YouTube — only metadata comes from Spotify.

Audio Formats

Format Quality Options
MP3 64, 96, 128, 192, 256, 320 kbps
M4A Best available
FLAC Lossless
WAV Lossless
OGG Variable bitrate

CLI Reference

Usage: pymusic [OPTIONS] COMMAND [ARGS]...

Commands:
  download  Download a track or playlist from URL
  search    Search for music and optionally download
  info      Show metadata for a URL without downloading

Options:
  -V, --version  Show version and exit
  --help         Show help message and exit

pymusic download options

Flag Default Description
-o, --output ~/Music Output directory
-f, --format mp3 Audio format (mp3/m4a/flac/wav/ogg)
-q, --quality 192 Bitrate in kbps (MP3 only)
--start 1 Playlist start index
--end Playlist end index
--reverse false Download playlist in reverse
--shuffle false Download playlist shuffled
--subdirs false Create Artist/Album subdirectories
--overwrite false Overwrite existing files
--rate-limit Speed limit (e.g. 500K, 1M)
--proxy HTTP/SOCKS proxy URL
--cookies Path to Netscape cookies file
-v, --verbose false Verbose output
--quiet false Suppress all output

License

MIT License — see LICENSE for details.

Contributing

Contributions are welcome! Please open an issue or pull request on GitHub.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pymusic_downloader-0.1.1.tar.gz (32.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pymusic_downloader-0.1.1-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file pymusic_downloader-0.1.1.tar.gz.

File metadata

  • Download URL: pymusic_downloader-0.1.1.tar.gz
  • Upload date:
  • Size: 32.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pymusic_downloader-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3e9627f1449f42c56c5d0e62e322edb698ca1cae292004b386bd7b873cc073ad
MD5 76842cecdbe9e618e404cd907d705e43
BLAKE2b-256 873a9cd9d5c6ad15d78f5830ca0de39e87c5625fe73d0843e9ebed054f64fb44

See more details on using hashes here.

File details

Details for the file pymusic_downloader-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for pymusic_downloader-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1854cc248b28e1fd2ac51ca357f8b8ecf423e469014c3a8db4f493d1f593db81
MD5 62d6a15447c3a948af211e5d9df9fe36
BLAKE2b-256 3550d090ffc609e1ed495fade09cde3fd2b50ecb1c31903dc62d308fd7986e19

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page