Skip to content

Commit 8d48ab7

Browse files
Feature to download multiple playlists (#231)
Co-authored-by: Sathyajith Bhat <[email protected]>
1 parent 8ac3bf2 commit 8d48ab7

File tree

3 files changed

+48
-38
lines changed

3 files changed

+48
-38
lines changed

GETTING_STARTED.md

+22-11
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,13 @@ You need Python 3.6+. To download songs as MP3, you will need ffmpeg.
77
- 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
88
- 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)
99

10-
1. Install using pip
10+
1. Install using pip
1111

1212
pip3 install spotify_dl
1313

14-
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
14+
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
1515

16-
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.
16+
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.
1717

1818
You can set environment variables as mentioned below:
1919

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

3939
- `spotify_playlist_link` is a link to Spotify's playlist. You can get it from the 3-dot menu.
40+
41+
![image](images/spotify-playlist.png)
42+
43+
spotify_dl also supports downloading multiple playlist, you can pass them like below:
44+
45+
`spotify_dl -l spotify_playlist1 spotify_playlist2 -o download_directory`
46+
47+
- `download_directory` is the location where the songs must be downloaded to. If you give a `.` then it will download to the current directory.
4048

41-
![image](images/spotify-playlist.png)
49+
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
50+
51+
- 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
52+
- 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)
4253

43-
If the Spotify playlist link is skipped then it will download songs from your "My Music" collection
44-
4554
- `download_directory` is the location where the songs must be downloaded to. If you give a `.` then it will download to the current directory.
4655

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

5362
Run the Docker image with your client ID and secret:
54-
``` bash
63+
64+
```bash
5565
docker run -d --rm \
5666
-e SPOTIPY_CLIENT_ID=client_id \
5767
-e SPOTIPY_CLIENT_SECRET=client_secret \
@@ -67,10 +77,11 @@ You can also run the bulk downloading script, make sure to configure it first: `
6777
### How do I set defaults?
6878

6979
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:
70-
``` json
80+
81+
```json
7182
{
72-
"output" : "/home/foo/spotify-dl-output"
73-
, "verbose" : "true"
74-
, "skip_mp3" : "t"
83+
"output": "/home/foo/spotify-dl-output",
84+
"verbose": "true",
85+
"skip_mp3": "t"
7586
}
7687
```

README.md

+6-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
## spotify_dl
2+
23
Downloads songs from any Spotify playlist, album or track.
34

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

15-
1616
### Tell me more!
1717

1818
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/).
@@ -23,9 +23,9 @@ Install using pip
2323

2424
pip3 install spotify_dl
2525

26-
Run the program
26+
Run the program
2727

28-
spotify_dl -l spotify_playlist_link -o download_directory
28+
spotify_dl -l spotify_playlist_link/s -o download_directory
2929

3030
For running in verbose mode, append `-V`
3131

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

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

40-
41-
### Contributing and Local development
40+
### Contributing and Local development
4241

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

4544
#### Running tests
4645

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

4948
make tests
5049

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

5756
### Issues, Feedback, Contact details
5857

59-
Feel free to raise any bugs/issues under Github issues. Pull requests are also more than welcome.
58+
Feel free to raise any bugs/issues under Github issues. Pull requests are also more than welcome.

spotify_dl/spotify_dl.py

+20-20
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ def spotify_dl():
1818
"""Main entry point of the script."""
1919
parser = argparse.ArgumentParser(prog='spotify_dl')
2020
parser.add_argument('-l', '--url', action="store",
21-
help="Spotify Playlist link URL", type=str, required=False)
21+
help="Spotify Playlist link URL", type=str, nargs='+', required=True)
2222
parser.add_argument('-o', '--output', type=str, action='store',
2323
help='Specify download directory.', required=False)
2424
parser.add_argument('-d', '--download', action='store_true',
@@ -71,27 +71,27 @@ def spotify_dl():
7171
sp = spotipy.Spotify(auth_manager=SpotifyClientCredentials())
7272
log.debug('Arguments: {}'.format(args))
7373

74-
if args.url:
75-
valid_item = validate_spotify_url(args.url)
74+
for url in args.url:
75+
if url:
76+
valid_item = validate_spotify_url(url)
7677

77-
if not valid_item:
78-
sys.exit(1)
78+
if not valid_item:
79+
sys.exit(1)
80+
81+
if args.output:
82+
item_type, item_id = parse_spotify_url(url)
83+
directory_name = get_item_name(sp, item_type, item_id)
84+
save_path = Path(PurePath.joinpath(Path(args.output), Path(directory_name)))
85+
save_path.mkdir(parents=True, exist_ok=True)
86+
console.print(f"Saving songs to [bold green]{directory_name}[/bold green] directory")
87+
88+
songs = fetch_tracks(sp, item_type, url)
89+
if args.download is True:
90+
file_name_f = default_filename
91+
if args.keep_playlist_order:
92+
file_name_f = playlist_num_filename
7993

80-
if args.output:
81-
item_type, item_id = parse_spotify_url(args.url)
82-
directory_name = get_item_name(sp, item_type, item_id)
83-
save_path = Path(PurePath.joinpath(Path(args.output), Path(directory_name)))
84-
save_path.mkdir(parents=True, exist_ok=True)
85-
console.print(f"Saving songs to [bold green]{directory_name}[/bold green] directory")
86-
87-
songs = fetch_tracks(sp, item_type, args.url)
88-
if args.download is True:
89-
file_name_f = default_filename
90-
if args.keep_playlist_order:
91-
file_name_f = playlist_num_filename
92-
93-
download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites,
94-
file_name_f)
94+
download_songs(songs, save_path, args.format_str, args.skip_mp3, args.keep_playlist_order, args.no_overwrites, file_name_f)
9595

9696

9797
if __name__ == '__main__':

0 commit comments

Comments
 (0)