Skip to main content

A Python package to download Spotify playlists locally including the cover art, metadata and lyrics by leveraging the Spotify, YouTube and Genius APIs.

Project description

Spotube

PyPi PyPI - Downloads Sonar Logo Sonar Quality Gate Sonar Coverage Snyk Logo PyPI - License Spotify Logo Youtube Logo

Spotube is a Python package that allows the user to download local .mp3 copies of Spotify playlists, including cover art, artist information and lyrics.

Description

The package can be used to download Spotify playlists, retrieving and pairing each song with the cover art as seen on Spotify, as well as any relevant metadata. The user provides the link to a public spotify playlist, API keys for Spotify and Genius, and, optionally the directory to save the downloaded songs. The application will then:

  • Query the Spotify API for information on each song in the playlist, including the official name, artists, album cover art etc.
  • Using the song name and artist(s), search for, and select the most relevant song video on Youtube. If possible, the application will avoid remixes, covers and video clip versions.
  • Using the most relevant link, download the video in the highest possible quality, and convert to .mp3 format.
  • Query the LyricsGenius API to retrieve the song lyrics, if available.
  • Edit the .mp3 tags of the downloaded song to set the artist and album information, add the lyrics and set the cover art.
  • Optionally, normalize the volume level of all downloaded .mp3 files, to remedy the possible volume difference of YouTube videos from one another.

Obtaining API keys

For instructions on how to generate the two sets of API keys needed to run the application, please refer to:

Dependencies

In order to utilize all the features provided by Spotube, it is necessary to have ffmpeg installed and configured in your system`s PATH variable. If no ffmpeg installation is detected, Spotube will attempt to download the prebuilt ffmpeg binaries kindly provided by the yt-dlp team. This will allow Spotube to function, but will disable some advanced features like volume normalization.

To install ffmpeg manually, follow the instructions relevant to your system:

Ubuntu:

sudo apt install software-properties-common
sudo apt update
sudo add-apt-repository ppa:jonathonf/ffmpeg-4
sudo apt install ffmpeg

Windows:

  • Download ffmpeg from the ffmpeg downloads page
  • Extract the downloaded archive
  • Add the directory where ffmpeg was extracted to the PATH

Installation

To install the package using pip:

pip install spotube

Instructions and Examples

Simple Use Case

The simplest way to use Spotube involves creating a downloader object using the Spotify Client ID and Spotify Client Secret and the Genius API Token, and then calling start_downloader with the link of a Spotify Playlist as the argument. The downloaded songs will be stored in the directory ./Songs by default. This simple use case looks like this:

from spotube import downloader

SPOTIFY_ID = {YOUR SPOTIFY API CLIENT ID}
SPOTIFY_SECRET = {YOUR SPOTIFY API CLIENT SECRET}
GENIUS_TOKEN = {YOUR GENIUS API TOKEN}
PLAYLIST_LINK = {THE LINK TO A SPOTIFY PLAYLIST}

my_downloaded = downloader(SPOTIFY_ID, SPOTIFY_SECRET, GENIUS_TOKEN)

my_downloaded.start_downloader(VALID_PLAYLIST)

Download Directory

You can set the directory to download the songs to, in one of two ways:

By passing the optional argument directory in the downloaded constructor:

my_downloaded = downloader(SPOTIFY_ID, SPOTIFY_SECRET, GENIUS_TOKEN, directory = "./Songs")

By setting the directory after the downloader object has been created:

my_downloaded = set_directory("./Songs")

Stopping the Downloader

You can stop the download process using the cancel_downloader method on a downloader object:

my_downloaded = cancel_downloader()

This will reset all download information, like the ETA and progress.

Validate Playlist URL

You can examine if a Spotify playlist URL is valid by using the validate_playlist_url method:

my_downloaded = validate_playlist_url({LINK TO A PLAYLIST})

This method will return True for a valid link, False otherwise.

Status Methods

The downloader class implements various methods to track the status of the downloader. These include:

  • get_progress(): This method returns the number of songs processed.
  • get_total(): This method returns the total number of songs in the playlist.
  • get_current_song(): This method returns the title and artist(s) of the song currently being downloaded.
  • get_eta(): This method returns the estimated time remaining for the download to finish, in seconds.
  • downloader_active(): Returns True if there is an active download in progress, False otherwise.

Disclaimer

Spotube is aimed strictly at personal use, as per the YouTube, Spotify and LyricsGenius license agreements. Sharing the content collected by using this application, or using it for profit is strictly prohibited. For more information, please read the LICENSE file included with this distribution.

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

spotube-0.5.16.tar.gz (12.5 kB view details)

Uploaded Source

Built Distribution

spotube-0.5.16-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

Details for the file spotube-0.5.16.tar.gz.

File metadata

  • Download URL: spotube-0.5.16.tar.gz
  • Upload date:
  • Size: 12.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.13 Linux/6.2.0-1018-azure

File hashes

Hashes for spotube-0.5.16.tar.gz
Algorithm Hash digest
SHA256 b9b7aa740e1d9f7bc734754ab35db21d52d17bfdb078bd261b6835bff0590476
MD5 dd0872df90847e984870d5f0d7c3e470
BLAKE2b-256 1d5622fb36c64ae08cd464b32dfb3a9677c093241fa8d32d955271f5cfcb078c

See more details on using hashes here.

Provenance

File details

Details for the file spotube-0.5.16-py3-none-any.whl.

File metadata

  • Download URL: spotube-0.5.16-py3-none-any.whl
  • Upload date:
  • Size: 12.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.10.13 Linux/6.2.0-1018-azure

File hashes

Hashes for spotube-0.5.16-py3-none-any.whl
Algorithm Hash digest
SHA256 ae4a6d0ea4169f69e1e490e0d010a097175f5222f9a817afbc3bd04d27e6a1ae
MD5 5d323b652c9f29267999e423bebe9e75
BLAKE2b-256 6acfdfa2eb80c3b851898a16eaadee13a7ae91b4d7cbd88de082773a1bbb445a

See more details on using hashes here.

Provenance

Supported by

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