Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 36 additions & 26 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,51 +22,62 @@ Open a terminal session and navigate to this folder, using `cd`.
cd spotify-to-mp3-python/
```

### 2. Installing dependencies
### 2. Install dependencies

We will be installing dependencies using `pip`, the official Python package manager. If you do not have `pip`, I'd recommend checking this [thread](https://stackoverflow.com/questions/6587507/how-to-install-pip-with-python-3/) to install it.
We will be installing dependencies using `uv`, the super fast Python package manager. If you do not have `uv`, I'd recommend checking this [thread](https://open.spotify.com/playlist/2FekNrO1rasjSaIndayN7O?si=66ef762c945e4f0a) to install it.

Copy and paste (and run) the following line in your terminal session to install all necessary packages.

```bash
pip3 install spotipy && pip3 install youtube_dl && pip3 install youtube_search && pip3 install yt_dlp && pip3 install ffprobe && pip3 install ffmpeg
uv venv venv && source .venv/bin/activate
uv pip install setuptools -e .
```

### 3. Setting up Spotify
### 2.1 Install ffmpeg
You will be needing `ffmpeg` to convert the downloaded audio files to MP3.
You can download it:

* Ubuntu and Debian: `sudo apt-get install ffmpeg`

* macOS: `brew install ffmpeg`

* Windows: `choco install ffmpeg`




### 3. Set up Spotify

Unfortunately, I could not find a workaround for this step - it seems like we're forced to go through the Spotify API to fetch information about playlists. But, it doesn't take long at all.

Go to the Spotify [dashboard](https://developer.spotify.com/dashboard/). Log in. Once at the Dashboard, click the green button labeled "Create App". Don't worry - you're not signing up for anything or commiting to something from Spotify. Here, **it really doesn't matter what you put** for "App name" and "App description". For me, I just put "Testing" for both. Make sure to check both agreement boxes and click "Create".
Go to the Spotify [dashboard](https://developer.spotify.com/dashboard/). Log in. Once at the Dashboard, click the green button labeled "Create App". Don't worry - you're not signing up for anything or commiting to something from Spotify.

You should see this:
Here **it really doesn't matter what you put** for "App name" and "App description."
I just put "Testing" for both.

![Spotify App Screen](https://miro.medium.com/max/1400/1*8c7agz6nxmez9-bm2NFCxQ.jpeg)
The next section is "Redirect URIs", which is a bit more important.
You can put anything here, but I'd recommend putting `http://localhost:8888/callback`.
The script won't be using this URL, but it's necessary to put something here.

You will see the "Client ID" field on the left (it's redacted here). Copy and save your Client ID somewhere - you'll need it later. Click "Show client secret" under Client ID and it should show you another long list of characters. Also copy and save your Client Secret.
Make sure to check "I understand and agree with Spotify's Developer Terms of Service and Design Guidelines" and click "Create".

Next, we need your playlist URI. To do this, simply open Spotify, right-click on the playlist you want to download, hover over "Share", and click "Copy Spotify URI". It should look something like this: `spotify:playlist:37i9dQZEVXbJiZcmkrIHGU`. When inputting this into the script, make sure to *only input the characters after "spotify:playlist:"*. So for this example, input `37i9dQZEVXbJiZcmkrIHGU`. Save your URI somewhere handy.

Alternatively, you can find the URI as follows:
1. Right-click on the playlist you want to download
2. Click "Share"
3. Click "Embed Playlist"
4. Click "Show Code"
5. The URI is the code between "https://open.spotify.com/embed/playlist/" and the first "?"
You should see this:

For example in this code snippet:
![Spotify App Screen](https://miro.medium.com/max/1400/1*8c7agz6nxmez9-bm2NFCxQ.jpeg)

```html
<iframe style="border-radius:12px" src="https://open.spotify.com/embed/playlist/11cPCycyvvpL0MDLO648vE?utm_source=generator" width="100%" height="352" frameBorder="0" allowfullscreen="" allow="autoplay; clipboard-write; encrypted-media; fullscreen; picture-in-picture" loading="lazy"></iframe>
```
You will see the "Client ID" field on the left (it's redacted here). Copy and save your Client ID somewhere - you'll need it later. Click "Show client secret" under Client ID and it should show you another long list of characters. Also copy and save your Client Secret.

Next, we need your playlist URI. To do this, simply open Spotify, right-click on the playlist you want to download, hover over "Share", and click "Copy link to playlist".

The code is 11cPCycyvvpL0MDLO648vE
It should look something like this: `https://open.spotify.com/playlist/2FekNrO1rasjSaIndayN7O?si=6666762ba5421f0a`.

### 4. Running

Running this script is straightforward. Simply run in your terminal session:

```bash
python3 spotify_to_mp3.py
spotify_to_mp3
```

If you run into an error saying something like "ffprobe or avprobe not found", check out this [solution](https://stackoverflow.com/questions/30770155/ffprobe-or-avprobe-not-found-please-install-one).
Expand All @@ -75,12 +86,11 @@ If all goes well, you should see your playlist beginning to download in a folder

## Modifications

If you don't like inputting your Client ID, Client Secret, Username, and URI every time, you can edit lines 96-99 in `spotify_to_mp3.py` to set the respective variables into a string containing your credentials instead of prompting with `input()`. For example, line 98 would become
If you don't like inputting your Client ID and Client Secret every time, you can edit `config.ini` to set the respective variables.

```python
username = "YourUserName"
```

## Debugging

This script was made in the better part of an afternoon and so it's not, by far, bug-free. Personally, I've run into no problems using this script on any of my playlists, however, your mileage may vary. The most promenant bug I've run into involves the `youtube-search` package not consistantly turning up results, and most of the time, the best solution is to simply try running the script again and giving it more chances to get the search right.
This script was made in the better part of an afternoon, and so it's not by far bug-free.

Personally, I've run into no problems using this script on any of my playlists, however, your mileage may vary. The most promenant bug I've run into involves the `youtube-search` package not consistantly turning up results, and most of the time, the best solution is to simply try running the script again and giving it more chances to get the search right.
23 changes: 23 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from setuptools import setup, find_packages

setup(
name='spotify_to_mp3',
version='1.0.0',
description='A tool to download Spotify playlists as MP3 files',
author='Haim Daniel',
packages=find_packages(),
install_requires=[
'spotipy',
'configparser',
'youtube_dl',
'youtube_search',
'yt_dlp',
'ffprobe',
'ffmpeg',
],
entry_points={
'console_scripts': [
'spotify_to_mp3=spotify_to_mp3.spotify_to_mp3:main',
],
},
)
Empty file added spotify_to_mp3/__init__.py
Empty file.
Loading