Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature to download multiple playlists #231

Merged
merged 3 commits into from
Jan 24, 2022
Merged
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
33 changes: 22 additions & 11 deletions GETTING_STARTED.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ You need Python 3.6+. To download songs as MP3, you will need ffmpeg.
- Linux users can get them by installing libav-tools by using apt-get `sudo apt-get install -y libav-tools`) or a package manager which comes with your distro
- Windows users can download FFMPEG pre-built binaries from [here](http://ffmpeg.zeranoe.com/builds/). Extract the file using [7-zip](http://7-zip.org/) to a foldrer and [add the folder to your PATH environment variable](http://www.wikihow.com/Install-FFmpeg-on-Windows)

1. Install using pip
1. Install using pip

pip3 install spotify_dl

2. Login to [Spotify developer console](https://developer.spotify.com/my-applications/#!/applications) and click on "Create an App". Fill in details for name and description
2. Login to [Spotify developer console](https://developer.spotify.com/my-applications/#!/applications) and click on "Create an App". Fill in details for name and description

3. Make a note of Client ID and Client Secret. These values need to be then set `SPOTIPY_CLIENT_ID`, `SPOTIPY_CLIENT_SECRET` environment variables respectively.
3. Make a note of Client ID and Client Secret. These values need to be then set `SPOTIPY_CLIENT_ID`, `SPOTIPY_CLIENT_SECRET` environment variables respectively.

You can set environment variables as mentioned below:

Expand All @@ -37,11 +37,20 @@ You need Python 3.6+. To download songs as MP3, you will need ffmpeg.
For most users `spotify_dl -l spotify_playlist_link -o download_directory` should do where

- `spotify_playlist_link` is a link to Spotify's playlist. You can get it from the 3-dot menu.

![image](images/spotify-playlist.png)

spotify_dl also supports downloading multiple playlist, you can pass them like below:

`spotify_dl -l spotify_playlist1 spotify_playlist2 -o download_directory`

- `download_directory` is the location where the songs must be downloaded to. If you give a `.` then it will download to the current directory.

![image](images/spotify-playlist.png)
5. To retrieve download songs as MP3, you will need to install ffmpeg. If you prefer to skip MP3 conversion, pass `-m` or `--skip_mp3` as a parameter when running the script

- Linux users can get them by installing libav-tools by using apt-get (`sudo apt-get install -y libav-tools`) if you'rte using a Debian/Ubuntu or a package manager which comes with your distro
- Windows users can download FFMPEG pre-built binaries from [here](http://ffmpeg.zeranoe.com/builds/). Extract the file using [7-zip](http://7-zip.org/) to a foldrer and [add the folder to your PATH environment variable](http://www.wikihow.com/Install-FFmpeg-on-Windows)

If the Spotify playlist link is skipped then it will download songs from your "My Music" collection

- `download_directory` is the location where the songs must be downloaded to. If you give a `.` then it will download to the current directory.

6. If you prefer to skip MP3 conversion, pass `-m` or `--skip_mp3` as a parameter when running the script
Expand All @@ -51,7 +60,8 @@ You need Python 3.6+. To download songs as MP3, you will need ffmpeg.
Build the Docker image from the Dockerfile, run the following command in the spotify_dl root directory: `docker build -t spotify_dl .`

Run the Docker image with your client ID and secret:
``` bash

```bash
docker run -d --rm \
-e SPOTIPY_CLIENT_ID=client_id \
-e SPOTIPY_CLIENT_SECRET=client_secret \
Expand All @@ -67,10 +77,11 @@ You can also run the bulk downloading script, make sure to configure it first: `
### How do I set defaults?

You can set defaults per user by creating a file at `~/.spotify_dl_settings`. Create a key with value for every argument you want a default for. Example:
``` json

```json
{
"output" : "/home/foo/spotify-dl-output"
, "verbose" : "true"
, "skip_mp3" : "t"
"output": "/home/foo/spotify-dl-output",
"verbose": "true",
"skip_mp3": "t"
}
```
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
## spotify_dl

Downloads songs from any Spotify playlist, album or track.

[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
Expand All @@ -12,7 +13,6 @@ Downloads songs from any Spotify playlist, album or track.
[![Awesome Badges](https://img.shields.io/badge/badges-awesome-green.svg)](https://github.com/Naereen/badges)
[![ko-fi](https://ko-fi.com/img/githubbutton_sm.svg)](https://ko-fi.com/E1E55G3EI)


### Tell me more!

I wanted an easy way to grab the songs present in my library so I can download it & use it offline. [spotify_to_mp3](https://github.com/frosas/spotify-to-mp3) worked well but it relied on grooveshark, which unfortunately is no more. So I wrote this script which mimics that library, but instead of downloading from grooveshark, it searches YouTube and downloads the song using [youtube-dl](https://rg3.github.io/youtube-dl/).
Expand All @@ -23,9 +23,9 @@ Install using pip

pip3 install spotify_dl

Run the program
Run the program

spotify_dl -l spotify_playlist_link -o download_directory
spotify_dl -l spotify_playlist_link/s -o download_directory

For running in verbose mode, append `-V`

Expand All @@ -37,14 +37,13 @@ For more details and other arguments, issue `-h`

See [the getting started guide](https://github.com/SathyaBhat/spotify-dl/blob/master/GETTING_STARTED.md) for more details.


### Contributing and Local development
### Contributing and Local development

Pull requests and any contributions are always welcome. Please open an issue with your proposal before you start with something.

#### Running tests

At the moment, there are barely any tests but PRs always welcome to improve this. Tests are setup and run with pytest, run
At the moment, there are barely any tests but PRs always welcome to improve this. Tests are setup and run with pytest, run

make tests

Expand All @@ -56,4 +55,4 @@ Take a look at [CONTRIBUTORS](/CONTRIBUTORS.md) for a list of all people who hav

### Issues, Feedback, Contact details

Feel free to raise any bugs/issues under Github issues. Pull requests are also more than welcome.
Feel free to raise any bugs/issues under Github issues. Pull requests are also more than welcome.
40 changes: 20 additions & 20 deletions spotify_dl/spotify_dl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def spotify_dl():
"""Main entry point of the script."""
parser = argparse.ArgumentParser(prog='spotify_dl')
parser.add_argument('-l', '--url', action="store",
help="Spotify Playlist link URL", type=str, required=False)
help="Spotify Playlist link URL", type=str, nargs='+', required=True)
parser.add_argument('-o', '--output', type=str, action='store',
help='Specify download directory.', required=False)
parser.add_argument('-d', '--download', action='store_true',
Expand Down Expand Up @@ -71,27 +71,27 @@ def spotify_dl():
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials())
log.debug('Arguments: {}'.format(args))

if args.url:
valid_item = validate_spotify_url(args.url)
for url in args.url:
if url:
valid_item = validate_spotify_url(url)

if not valid_item:
sys.exit(1)
if not valid_item:
sys.exit(1)

if args.output:
item_type, item_id = parse_spotify_url(url)
directory_name = get_item_name(sp, item_type, item_id)
save_path = Path(PurePath.joinpath(Path(args.output), Path(directory_name)))
save_path.mkdir(parents=True, exist_ok=True)
console.print(f"Saving songs to [bold green]{directory_name}[/bold green] directory")

songs = fetch_tracks(sp, item_type, url)
if args.download is True:
file_name_f = default_filename
if args.keep_playlist_order:
file_name_f = playlist_num_filename

if args.output:
item_type, item_id = parse_spotify_url(args.url)
directory_name = get_item_name(sp, item_type, item_id)
save_path = Path(PurePath.joinpath(Path(args.output), Path(directory_name)))
save_path.mkdir(parents=True, exist_ok=True)
console.print(f"Saving songs to [bold green]{directory_name}[/bold green] directory")

songs = fetch_tracks(sp, item_type, args.url)
if args.download is True:
file_name_f = default_filename
if args.keep_playlist_order:
file_name_f = playlist_num_filename

download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites,
file_name_f)
download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites, file_name_f)


if __name__ == '__main__':
Expand Down