mirror of
https://github.com/cooperhammond/irs.git
synced 2024-12-22 17:35:28 +00:00
Ability to place songs from playlists all into one folder. Use flag.
This commit is contained in:
parent
a28525f144
commit
ca5cbea5ea
11
README.md
11
README.md
|
@ -30,15 +30,16 @@ irs -A "Sadnecessary" # -a "Milky Chance"
|
|||
Full usage:
|
||||
```
|
||||
usage:
|
||||
irs (-h | -v)
|
||||
irs [-l]
|
||||
irs -p PLAYLIST [-c COMMAND] [-l]
|
||||
irs -A ALBUM [-c COMMAND] [-l]
|
||||
irs (-h | -v | -C)
|
||||
irs [-l] [-sa]
|
||||
irs -p PLAYLIST [-c COMMAND] [-l] [-sa]
|
||||
irs -A ALBUM [-c COMMAND] [-l] [-sa]
|
||||
irs -a ARTIST -s SONG [-c COMMAND] [-l]
|
||||
|
||||
Options:
|
||||
-h, --help show this help message and exit
|
||||
-v, --version Display the version and exit.
|
||||
-C, --config Return location of configuration file.
|
||||
-A ALBUM, --album ALBUM
|
||||
Search spotify for an album.
|
||||
-p PLAYLIST, --playlist PLAYLIST
|
||||
|
@ -53,6 +54,8 @@ Options:
|
|||
-a/--artist
|
||||
-l, --choose-link If supplied, will bring up a console choice for what
|
||||
link you want to download based off a list of titles.
|
||||
-sa, --start-at A song index to start at if something goes wrong while
|
||||
downloading and you have to restart.
|
||||
```
|
||||
Make a note that capitalization and spelling matters a lot in this program.
|
||||
|
||||
|
|
|
@ -3,9 +3,9 @@ HELP = \
|
|||
"""
|
||||
usage:
|
||||
irs (-h | -v | -C)
|
||||
irs [-l]
|
||||
irs -p PLAYLIST [-c COMMAND] [-l]
|
||||
irs -A ALBUM [-c COMMAND] [-l]
|
||||
irs [-l] [-sa]
|
||||
irs -p PLAYLIST [-c COMMAND] [-l] [-sa]
|
||||
irs -A ALBUM [-c COMMAND] [-l] [-sa]
|
||||
irs -a ARTIST -s SONG [-c COMMAND] [-l]
|
||||
|
||||
Options:
|
||||
|
@ -35,6 +35,12 @@ Options:
|
|||
|
||||
-l, --choose-link If supplied, will bring up a console choice for what
|
||||
link you want to download based off a list of titles.
|
||||
|
||||
-sa, --start-at A song index to start at if something goes wrong while
|
||||
downloading and you have to restart.
|
||||
|
||||
-of, --one-folder To place all songs downloaded from a playlist into one
|
||||
folder.
|
||||
"""
|
||||
|
||||
# For exiting
|
||||
|
@ -62,9 +68,14 @@ def main():
|
|||
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('-sa', '--start-at', dest="start_at", help="An index to start at if downloading a list.")
|
||||
|
||||
parser.add_argument('-p', '--playlist', dest="playlist", \
|
||||
help="Specify playlist filename. Each line should be formatted like so: SONGNAME - ARTIST")
|
||||
|
||||
parser.add_argument('-of', '--one-folder', action="store_true", dest="one_folder", \
|
||||
help="Place all downloaded playlist songs into one folder")
|
||||
|
||||
media = parser.add_mutually_exclusive_group()
|
||||
media.add_argument('-s', '--song', dest="song", help="Specify song name of the artist.")
|
||||
|
||||
|
|
|
@ -6,12 +6,14 @@ CONFIG = dict(
|
|||
# default_flags = '-c rhythmbox %(loc)s',
|
||||
# To make choosing of links default:
|
||||
# default_flags = '-l',
|
||||
# To place all playlist songs into one folder:
|
||||
# default_flags = '-of',
|
||||
default_flags = '',
|
||||
|
||||
|
||||
# These are necessary to download Spotify playlists
|
||||
client_id = '',
|
||||
client_secret = '',
|
||||
client_id = 'e4198f6a3f7b48029366f22528b5dc66',
|
||||
client_secret = '69adc699f79e4640a6fd7610635b025f',
|
||||
|
||||
# For a custom directory. Note that `~` will not work as a shortcut.
|
||||
directory = str(expanduser("~")) + "/Music",
|
||||
|
@ -20,5 +22,5 @@ CONFIG = dict(
|
|||
numbered_file_names = True,
|
||||
|
||||
# Downloaded file names
|
||||
download_file_names = True,
|
||||
download_file_names = False,
|
||||
)
|
||||
|
|
|
@ -164,6 +164,7 @@ class Manager:
|
|||
spotify_list = choose_from_spotify_list(items, length=length)
|
||||
|
||||
list_type = spotify_list["type"]
|
||||
name = spotify_list["name"]
|
||||
if list_type != "playlist":
|
||||
spotify_list = eval("spotify.%s" % list_type)(spotify_list["uri"])
|
||||
else:
|
||||
|
@ -195,10 +196,10 @@ class Manager:
|
|||
album = spotify_list
|
||||
|
||||
songs.append({
|
||||
"name": song["name"],
|
||||
"name": song["name"].split(" - ")[0],
|
||||
"artist": artist["name"],
|
||||
"album": album["name"],
|
||||
"tracknum": song["track_number"],
|
||||
"tracknum": increment,
|
||||
"album_cover": album["images"][0]["url"]
|
||||
})
|
||||
|
||||
|
@ -209,9 +210,41 @@ class Manager:
|
|||
print ("\t" + song["name"] + " - " + song["artist"])
|
||||
print (bc.ENDC + "\n")
|
||||
|
||||
for song in songs:
|
||||
self.rip_mp3(song["name"], song["artist"], album=song["album"], \
|
||||
tracknum=song["tracknum"], album_art_url=song["album_cover"])
|
||||
if self.args.start_at:
|
||||
start_at = int(self.args.start_at) - 1
|
||||
if start_at < 0:
|
||||
start_at = 0
|
||||
else:
|
||||
start_at = 0
|
||||
|
||||
for song in songs[start_at:]:
|
||||
|
||||
already_there = False
|
||||
if os.path.isdir(CONFIG["directory"] + "/" + song["artist"]):
|
||||
already_there = True
|
||||
|
||||
song_loc = self.rip_mp3(song["name"], song["artist"], album=song["album"], \
|
||||
tracknum=song["tracknum"], album_art_url=song["album_cover"], \
|
||||
out_of="%s/%s - " % (song["tracknum"], len(songs)))
|
||||
|
||||
if self.args.one_folder:
|
||||
|
||||
one_folder = CONFIG["directory"] + "/" + strip_special_chars(name[:30])
|
||||
|
||||
if not os.path.isdir(one_folder):
|
||||
os.makedirs(one_folder)
|
||||
|
||||
new_loc = one_folder + "/" + song_loc.split("/")[-1]
|
||||
|
||||
os.rename(song_loc, new_loc)
|
||||
|
||||
if not already_there:
|
||||
import shutil
|
||||
shutil.rmtree(CONFIG["directory"] + "/" + song["artist"])
|
||||
|
||||
if self.args.command:
|
||||
os.system((self.args.command.replace("%(loc)s", '"%s"' % new_loc) + " &"))
|
||||
|
||||
|
||||
else:
|
||||
print (bc.FAIL + "No results were found. Make sure to use proper spelling and capitalization." + bc.ENDC)
|
||||
|
@ -221,7 +254,7 @@ class Manager:
|
|||
album=None, # if you want to specify an album and save a bit of time.
|
||||
tracknum=None, # to specify the tracknumber in the album.
|
||||
album_art_url=None, # if you want to save a lot of time trying to find album cover.
|
||||
organize=True
|
||||
out_of="", # For a string to put before the song title.
|
||||
):
|
||||
|
||||
|
||||
|
@ -231,6 +264,8 @@ class Manager:
|
|||
if not artist:
|
||||
artist = self.args.artist
|
||||
|
||||
|
||||
print (color(out_of, ["UNDERLINE"]), end="")
|
||||
audio_code = self.find_mp3(song=song, artist=artist)
|
||||
|
||||
if CONFIG["numbered_file_names"] and tracknum:
|
||||
|
|
|
@ -123,7 +123,7 @@ def fail_oauth():
|
|||
print (get_config_file_path())
|
||||
exit(1)
|
||||
|
||||
def choose_from_spotify_list(thelist, length=10):
|
||||
def choose_from_spotify_list(thelist, length=100000):
|
||||
spotify = spotipy.Spotify()
|
||||
|
||||
thelist = list(thelist)
|
||||
|
|
Loading…
Reference in a new issue