Skip to content

Commit

Permalink
Downloading of spotify playlists is a go. Just I forgot a significant…
Browse files Browse the repository at this point in the history
… detail of it.
  • Loading branch information
cooperhammond committed Jan 26, 2017
1 parent b145b5d commit 6aa8555
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 21 deletions.
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
___
Expand All @@ -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"
Expand All @@ -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)

Expand All @@ -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"`
Expand Down
16 changes: 7 additions & 9 deletions irs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
-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"`
Expand Down Expand Up @@ -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.")
Expand All @@ -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:
Expand All @@ -93,17 +92,16 @@ 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)

elif args.playlist:
manager.rip_spotify_list("playlist")

elif args.user:
manager.rip_spotify_list("user")

elif args.album:
manager.rip_spotify_list("album")

Expand Down
4 changes: 2 additions & 2 deletions irs/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


# 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 = '',
Expand Down
12 changes: 9 additions & 3 deletions irs/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,18 @@ def rip_spotify_list(self, type):
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":
Expand Down
8 changes: 4 additions & 4 deletions irs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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]
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='irs',
version='4.7.20',
version='4.7.21',
description='A music downloader that just gets metadata.',
url='https://github.com/kepoorhampond/irs',
author='Kepoor Hampond',
Expand Down

0 comments on commit 6aa8555

Please sign in to comment.