A Python library and command-line tool to download songs from various streaming platforms.
Project description
Universal Music Downloader
A Python library and command-line tool to download songs from various streaming platforms.
This tool works by fetching track metadata (artist, title) from platforms like Apple Music, Tidal, and Spotify, and then uses that metadata to find and download the corresponding track from YouTube. For YouTube and SoundCloud, it downloads directly.
⚙️ How it Works
The library provides a unified function for each platform, handling the different download strategies automatically.
- Direct Download (YouTube, SoundCloud): Uses
yt-dlpto download and convert the audio to MP3. - Metadata-Based Download (Spotify, Apple Music, Tidal):
- Scrapes the provided URL to get the track's Artist and Title.
- Performs a search on YouTube for
"Artist - Title audio". - Downloads the first search result as an MP3.
🚀 Installation
You can install the package directly from PyPI:
pip install universal-music-downloader
Usage
You can use this project in two ways: as a command-line tool or as a Python library.
1. As a Command-Line Tool (CLI)
After installation, the umd command will be available in your terminal.
Format
umd <platform> <url> [options]
Arguments
<platform>: The source platform.spotifyappletidalyoutubesoundcloud
<url>: The full URL of the track (it's best to use quotes).
Options
-o, --output <folder>: Specify a folder to save the MP3. (Default: current directory)
Examples
# Download a Spotify track to the current folder
umd spotify "https://open.spotify.com/intl-es/track/0FIDCNYYjNvPVimz5icugS?si=e83ededc95564c0a"
# Download an Apple Music track to a specific 'downloads' folder
umd apple "https://music.apple.com/es/song/timeless/1770380890" -o ./my-music
# Download a YouTube video
umd youtube "https://youtu.be/16jA-6hiSUo?si=pBhCn4ezIj7917E2"
2. As a Python Library
You can import and use the download functions directly in your Python code for full control.
Available Functions
from universal_music_downloader.spotify import download_spotify_track
from universal_music_downloader.youtube import download_youtube_url, download_youtube_search
from universal_music_downloader.apple import download_apple_music_track
from universal_music_downloader.tidal import download_tidal_track
from universal_music_downloader.soundcloud import download_soundcloud_track
Example: Downloading a Spotify Track
import os
from universal_music_downloader.spotify import download_spotify_track
from universal_music_downloader.exceptions import DownloaderError
DOWNLOAD_FOLDER = "my_song_collection"
os.makedirs(DOWNLOAD_FOLDER, exist_ok=True)
url = "[https://open.spotify.com/track/](https://open.spotify.com/track/)..."
try:
print(f"Downloading from {url}...")
# All download functions follow the same (url, folder) signature
mp3_path = download_spotify_track(url, DOWNLOAD_FOLDER)
print(f"\nSuccess! File saved to: {mp3_path}")
except DownloaderError as e:
print(f"\nDownload Failed: {e}")
Error Handling
The library uses custom exceptions for easy error management. It is highly recommended to wrap your calls in a try...except block.
exceptions.DownloaderError: The base exception for all errors.exceptions.InvalidURLError: The provided URL is invalid or malformed.exceptions.MetadataError: Failed to scrape/fetch metadata (e.g., from Tidal/Apple).exceptions.DownloadFailedError: The download process itself failed (e.g.,yt-dlporspotdlfailed).
from universal_music_downloader import exceptions
try:
# ... call a download function ...
except exceptions.InvalidURLError:
print("That URL doesn't look right.")
except exceptions.MetadataError:
print("Could not find that song's details.")
except exceptions.DownloadFailedError as e:
print(f"The download failed: {e}")
except exceptions.DownloaderError as e:
print(f"A general error occurred: {e}")
⚖️ License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file universal_music_downloader-0.1.0.tar.gz.
File metadata
- Download URL: universal_music_downloader-0.1.0.tar.gz
- Upload date:
- Size: 8.8 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d9c38edd62a61516f132c73b38d7fab3d82091ad99bb29c78004f0567f207e2a
|
|
| MD5 |
54674a63d7856671625128a376b85ea7
|
|
| BLAKE2b-256 |
1bed4d1028341c9476d6071710a6a6a8b159073a0744e7009dd5f1d4944812bb
|
File details
Details for the file universal_music_downloader-0.1.0-py3-none-any.whl.
File metadata
- Download URL: universal_music_downloader-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.9 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
94ea5a776ea1654b95349dc8e9905f2eb7cb896a876fd8ead4a282bfc59ced61
|
|
| MD5 |
bf60fe02755be7aea22121af0062ea42
|
|
| BLAKE2b-256 |
d5c67fb39d7568870581a7ac32b7c39d68f405a316e5c2afc42aedac1f42efaf
|