mirror of
https://github.com/cooperhammond/irs.git
synced 2025-02-01 08:01:00 +00:00
Downloading of spotify playlists is a go. Just I forgot a significant detail of it.
This commit is contained in:
parent
b145b5d173
commit
6aa8555735
|
@ -2,7 +2,7 @@
|
|||
[![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)
|
||||
|
||||
<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.
|
||||
___
|
||||
|
@ -11,6 +11,10 @@ To download Spotify playlists, you need to supply client_ids. To do this, you'll
|
|||
```bash
|
||||
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.
|
||||
```bash
|
||||
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
|
||||
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)
|
||||
|
||||
|
@ -39,6 +43,7 @@ Options:
|
|||
Search spotify for an album.
|
||||
-p PLAYLIST, --playlist PLAYLIST
|
||||
Search spotify for a playlist.
|
||||
-u USER, --user USER Download a user playlist.
|
||||
-c COMMAND, --command COMMAND
|
||||
Run a background command with each song's location.
|
||||
Example: `-c "rhythmbox %(loc)s"`
|
||||
|
|
|
@ -21,6 +21,8 @@ Options:
|
|||
-p PLAYLIST, --playlist PLAYLIST
|
||||
Search spotify for a playlist.
|
||||
|
||||
-u USER, --user USER Download a user playlist.
|
||||
|
||||
-c COMMAND, --command COMMAND
|
||||
Run a background command with each song's location.
|
||||
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('-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", \
|
||||
help="Whether or not to choose the link from a list of titles.")
|
||||
|
||||
parser.add_argument('-p', '--playlist', dest="playlist", \
|
||||
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.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])
|
||||
|
||||
if args.organize == None:
|
||||
args.organize = True
|
||||
|
||||
manager = Manager(args)
|
||||
|
||||
if args.help:
|
||||
|
@ -93,10 +92,6 @@ def main():
|
|||
elif args.config:
|
||||
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):
|
||||
# parser.error("error: must supply -A/--album or -s/--song if specifying -a/--artist")
|
||||
# exit(1)
|
||||
|
@ -104,6 +99,9 @@ def main():
|
|||
elif args.playlist:
|
||||
manager.rip_spotify_list("playlist")
|
||||
|
||||
elif args.user:
|
||||
manager.rip_spotify_list("user")
|
||||
|
||||
elif args.album:
|
||||
manager.rip_spotify_list("album")
|
||||
|
||||
|
|
|
@ -8,8 +8,8 @@ CONFIG = dict(
|
|||
|
||||
|
||||
# These are necessary to download Spotify playlists
|
||||
client_id = '',
|
||||
client_secret = '',
|
||||
client_id = 'e4198f6a3f7b48029366f22528b5dc66',
|
||||
client_secret = 'fa96b67d223547e88c931a978b2fcecc',
|
||||
|
||||
# For a custom directory. Note that `~` will not work as a shortcut.
|
||||
directory = '',
|
||||
|
|
|
@ -150,12 +150,18 @@ class Manager:
|
|||
except spotipy.oauth2.SpotifyOauthError:
|
||||
spotify = spotipy.Spotify()
|
||||
|
||||
results = spotify.search(q=search, type=type)
|
||||
items = results[type + "s"]['items']
|
||||
if type == "user":
|
||||
items = spotify.user_playlists(self.args.user)["items"]
|
||||
length = None
|
||||
else:
|
||||
results = spotify.search(q=search, type=type)
|
||||
items = results[type + "s"]['items']
|
||||
length = 10
|
||||
|
||||
songs = []
|
||||
|
||||
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"]
|
||||
if list_type != "playlist":
|
||||
|
|
|
@ -123,14 +123,14 @@ def fail_oauth():
|
|||
print (get_config_file_path())
|
||||
exit(1)
|
||||
|
||||
def choose_from_spotify_list(thelist):
|
||||
def choose_from_spotify_list(thelist, length=10):
|
||||
spotify = spotipy.Spotify()
|
||||
|
||||
thelist = list(thelist)
|
||||
print ("Results:")
|
||||
choice = ""
|
||||
while choice not in tuple(range(0, len(thelist[:10]))):
|
||||
for index, result in enumerate(thelist[:10]):
|
||||
while choice not in tuple(range(0, len(thelist[:length]))):
|
||||
for index, result in enumerate(thelist[:length]):
|
||||
type = result["type"]
|
||||
|
||||
if type == "playlist":
|
||||
|
@ -145,7 +145,7 @@ def choose_from_spotify_list(thelist):
|
|||
info = spotify.album(result["id"])
|
||||
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))
|
||||
|
||||
return thelist[choice]
|
||||
|
|
Loading…
Reference in a new issue