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.2.tar.gz (33.0 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.2-py3-none-any.whl (28.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pymusic_downloader-0.1.2.tar.gz
  • Upload date:
  • Size: 33.0 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.2.tar.gz
Algorithm Hash digest
SHA256 6712cc9190ae4d9f438df57c5be7a417a734dec6c2c494ec97c28ec86100c788
MD5 dc7af255d91d188d11c329dc7ba64878
BLAKE2b-256 98936c505077ea19f2eb77c2f9a1fe4cd16ebe57bd80a24e8a861ed5ba9ef713

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pymusic_downloader-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e7a478747ad8ed54410c29106d8f319c863b129b43650573ba65303ddd962c78
MD5 c04188519a7a66e2aa267fe417bba9fd
BLAKE2b-256 63e66119496b5f51866e919284fa62bdcb6356c39aa6a095de2425ffc7944502

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