Downloading of spotify playlists is a go. Just I forgot a significant detail of it.

This commit is contained in:
Kepoor Hampond 2017-01-25 21:34:11 -08:00
parent b145b5d173
commit 6aa8555735
6 changed files with 30 additions and 21 deletions

View file

@ -2,7 +2,7 @@
[![License: GNU](https://img.shields.io/badge/License-GNU-yellow.svg)](http://www.gnu.org/licenses/gpl.html) [![License: GNU](https://img.shields.io/badge/License-GNU-yellow.svg)](http://www.gnu.org/licenses/gpl.html)
[![PyPI](https://img.shields.io/badge/PyPi-Python_3.x-blue.svg)](https://pypi.python.org/pypi/irs) [![PyPI](https://img.shields.io/badge/PyPi-Python_3.x-blue.svg)](https://pypi.python.org/pypi/irs)
<em>Spotify playlists are now downloadable!</em> <em>Spotify playlists are now downloadable! Just use the `-u` flag and your username!</em>
An ironically named program to download audio from youtube and then parse metadata for the downloaded file. An ironically named program to download audio from youtube and then parse metadata for the downloaded file.
___ ___
@ -11,6 +11,10 @@ To download Spotify playlists, you need to supply client_ids. To do this, you'll
```bash ```bash
irs -p "Brain Food" irs -p "Brain Food"
``` ```
If you are looking for one of *your* playlists, you'll want to use the `-u` flag and put your username in:
```bash
irs -u "prakkillian"
```
If you download a specific song, you'll want to use the `-s` and `-a` flag. If you download a specific song, you'll want to use the `-s` and `-a` flag.
```bash ```bash
irs -a "David Bowie" -s "Ziggy Stardust" irs -a "David Bowie" -s "Ziggy Stardust"
@ -19,7 +23,7 @@ To download an entire album, you'll want to use the `-A` flag. If the album you
```bash ```bash
irs -A "Sadnecessary" # -a "Milky Chance" irs -A "Sadnecessary" # -a "Milky Chance"
``` ```
[![asciicast](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug.png)](https://asciinema.org/a/bcs7i0sjmka052wsdyxg5xrug?speed=3&autoplay=true) [![asciicast](https://asciinema.org/a/5aijmkdux6nk8ckhke0jmzlyq.png)](https://asciinema.org/a/5aijmkdux6nk8ckhke0jmzlyq?speed=3&autoplay=true)
[![asciicast](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia.png)](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia?speed=3) [![asciicast](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia.png)](https://asciinema.org/a/8kb9882j4cbtd4hwbsbb7h0ia?speed=3)
@ -39,6 +43,7 @@ Options:
Search spotify for an album. Search spotify for an album.
-p PLAYLIST, --playlist PLAYLIST -p PLAYLIST, --playlist PLAYLIST
Search spotify for a playlist. Search spotify for a playlist.
-u USER, --user USER Download a user playlist.
-c COMMAND, --command COMMAND -c COMMAND, --command COMMAND
Run a background command with each song's location. Run a background command with each song's location.
Example: `-c "rhythmbox %(loc)s"` Example: `-c "rhythmbox %(loc)s"`

View file

@ -21,6 +21,8 @@ Options:
-p PLAYLIST, --playlist PLAYLIST -p PLAYLIST, --playlist PLAYLIST
Search spotify for a playlist. Search spotify for a playlist.
-u USER, --user USER Download a user playlist.
-c COMMAND, --command COMMAND -c COMMAND, --command COMMAND
Run a background command with each song's location. Run a background command with each song's location.
Example: `-c "rhythmbox %(loc)s"` Example: `-c "rhythmbox %(loc)s"`
@ -55,13 +57,13 @@ def main():
parser.add_argument('-c', '--command', dest="command", help="Run a background command with each song's location.") parser.add_argument('-c', '--command', dest="command", help="Run a background command with each song's location.")
parser.add_argument('-a', '--artist', dest="artist", help="Specify the artist name.") parser.add_argument('-a', '--artist', dest="artist", help="Specify the artist name.")
parser.add_argument('-u', '--user', dest="user", help="Specify user to download playlists from.")
parser.add_argument('-l', '--choose-link', action='store_true', dest="link", \ parser.add_argument('-l', '--choose-link', action='store_true', dest="link", \
help="Whether or not to choose the link from a list of titles.") help="Whether or not to choose the link from a list of titles.")
parser.add_argument('-p', '--playlist', dest="playlist", \ parser.add_argument('-p', '--playlist', dest="playlist", \
help="Specify playlist filename. Each line should be formatted like so: SONGNAME - ARTIST") help="Specify playlist filename. Each line should be formatted like so: SONGNAME - ARTIST")
parser.add_argument('-ng', '--no-organize', action="store_false", dest="organize", \
help="Only use if calling -p/--playlist. Forces all files downloaded to be organizes normally.")
media = parser.add_mutually_exclusive_group() media = parser.add_mutually_exclusive_group()
media.add_argument('-s', '--song', dest="song", help="Specify song name of the artist.") media.add_argument('-s', '--song', dest="song", help="Specify song name of the artist.")
@ -71,9 +73,6 @@ def main():
args = parser.parse_args(sys.argv[1:] + CONFIG["default_flags"].split(" ")[:-1]) args = parser.parse_args(sys.argv[1:] + CONFIG["default_flags"].split(" ")[:-1])
if args.organize == None:
args.organize = True
manager = Manager(args) manager = Manager(args)
if args.help: if args.help:
@ -93,10 +92,6 @@ def main():
elif args.config: elif args.config:
print (get_config_file_path()) print (get_config_file_path())
elif not args.organize and not args.playlist:
parser.error("error: must supply -p/--playlist if specifying -ng/--no-organize")
exit(1)
#elif args.artist and not (args.album or args.song): #elif args.artist and not (args.album or args.song):
# parser.error("error: must supply -A/--album or -s/--song if specifying -a/--artist") # parser.error("error: must supply -A/--album or -s/--song if specifying -a/--artist")
# exit(1) # exit(1)
@ -104,6 +99,9 @@ def main():
elif args.playlist: elif args.playlist:
manager.rip_spotify_list("playlist") manager.rip_spotify_list("playlist")
elif args.user:
manager.rip_spotify_list("user")
elif args.album: elif args.album:
manager.rip_spotify_list("album") manager.rip_spotify_list("album")

View file

@ -8,8 +8,8 @@ CONFIG = dict(
# These are necessary to download Spotify playlists # These are necessary to download Spotify playlists
client_id = '', client_id = 'e4198f6a3f7b48029366f22528b5dc66',
client_secret = '', client_secret = 'fa96b67d223547e88c931a978b2fcecc',
# For a custom directory. Note that `~` will not work as a shortcut. # For a custom directory. Note that `~` will not work as a shortcut.
directory = '', directory = '',

View file

@ -150,12 +150,18 @@ class Manager:
except spotipy.oauth2.SpotifyOauthError: except spotipy.oauth2.SpotifyOauthError:
spotify = spotipy.Spotify() spotify = spotipy.Spotify()
if type == "user":
items = spotify.user_playlists(self.args.user)["items"]
length = None
else:
results = spotify.search(q=search, type=type) results = spotify.search(q=search, type=type)
items = results[type + "s"]['items'] items = results[type + "s"]['items']
length = 10
songs = [] songs = []
if len(items) > 0: if len(items) > 0:
spotify_list = choose_from_spotify_list(items) spotify_list = choose_from_spotify_list(items, length=length)
list_type = spotify_list["type"] list_type = spotify_list["type"]
if list_type != "playlist": if list_type != "playlist":

View file

@ -123,14 +123,14 @@ def fail_oauth():
print (get_config_file_path()) print (get_config_file_path())
exit(1) exit(1)
def choose_from_spotify_list(thelist): def choose_from_spotify_list(thelist, length=10):
spotify = spotipy.Spotify() spotify = spotipy.Spotify()
thelist = list(thelist) thelist = list(thelist)
print ("Results:") print ("Results:")
choice = "" choice = ""
while choice not in tuple(range(0, len(thelist[:10]))): while choice not in tuple(range(0, len(thelist[:length]))):
for index, result in enumerate(thelist[:10]): for index, result in enumerate(thelist[:length]):
type = result["type"] type = result["type"]
if type == "playlist": if type == "playlist":
@ -145,7 +145,7 @@ def choose_from_spotify_list(thelist):
info = spotify.album(result["id"]) info = spotify.album(result["id"])
display_info = " - " + info["artists"][0]["name"] display_info = " - " + info["artists"][0]["name"]
print ("\t" + str(index) + ") " + result["name"] + display_info) print ("\t" + str(index) + ") " + bc.HEADER + result["name"] + display_info + bc.ENDC)
choice = int(input(bc.YELLOW + "\nEnter result number: " + bc.ENDC)) choice = int(input(bc.YELLOW + "\nEnter result number: " + bc.ENDC))
return thelist[choice] return thelist[choice]

View file

@ -2,7 +2,7 @@ from setuptools import setup
setup( setup(
name='irs', name='irs',
version='4.7.20', version='4.7.21',
description='A music downloader that just gets metadata.', description='A music downloader that just gets metadata.',
url='https://github.com/kepoorhampond/irs', url='https://github.com/kepoorhampond/irs',
author='Kepoor Hampond', author='Kepoor Hampond',