mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-02 19:15:26 +00:00
Fixed bug with playlists where they would all be of the same album.
This commit is contained in:
parent
03ad538239
commit
f1436637f8
|
@ -1 +0,0 @@
|
||||||
import argparse
|
|
31
irs/cli.py
Normal file
31
irs/cli.py
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
# Arguments
|
||||||
|
import argparse
|
||||||
|
|
||||||
|
# System
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
|
||||||
|
# Powered by:
|
||||||
|
from .ripper import Ripper
|
||||||
|
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-a", "--artist", dest="artist", help="Specify artist name")
|
||||||
|
parser.add_argument("-s", "--song", dest="song", help="Specify song name")
|
||||||
|
|
||||||
|
parser.add_argument("-A", "--album", dest="album", help="Specify album name")
|
||||||
|
|
||||||
|
parser.add_argument("-u", "--username", dest="username", help="Specify username")
|
||||||
|
parser.add_argument("-p", "--playlist", dest="playlist", help="Specify playlist name")
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
|
if args.artist and args.song:
|
||||||
|
Ripper().song(args.song, args.artist)
|
||||||
|
elif args.album:
|
||||||
|
Ripper().spotify_list("album", args.album)
|
||||||
|
elif args.username and args.playlist:
|
||||||
|
Ripper().spotify_list("playlist", args.playlist, args.username)
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -22,7 +22,7 @@ from re import match
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
|
||||||
# Local utils
|
# Local utils
|
||||||
import .utils
|
from .utils import *
|
||||||
|
|
||||||
# Powered by...
|
# Powered by...
|
||||||
import spotipy
|
import spotipy
|
||||||
|
@ -55,8 +55,8 @@ class Metadata:
|
||||||
def find_album_and_track(song, artist):
|
def find_album_and_track(song, artist):
|
||||||
tracks = spotipy.Spotify().search(q=song, type="track")["tracks"]["items"]
|
tracks = spotipy.Spotify().search(q=song, type="track")["tracks"]["items"]
|
||||||
for track in tracks:
|
for track in tracks:
|
||||||
if utils.blank_include(track["name"], song):
|
if blank_include(track["name"], song):
|
||||||
if utils.blank_include(track["artists"][0]["name"], artist):
|
if blank_include(track["artists"][0]["name"], artist):
|
||||||
return track["album"], track
|
return track["album"], track
|
||||||
return False, False
|
return False, False
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@ else:
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Local utilities
|
# Local utilities
|
||||||
import .utils
|
from .utils import *
|
||||||
from .metadata import *
|
from .metadata import *
|
||||||
|
|
||||||
class Ripper:
|
class Ripper:
|
||||||
|
@ -64,15 +64,15 @@ class Ripper:
|
||||||
|
|
||||||
self.code = None
|
self.code = None
|
||||||
for link in results:
|
for link in results:
|
||||||
if utils.blank_include(link["title"], song) and utils.blank_include(link["title"], artist):
|
if blank_include(link["title"], song) and blank_include(link["title"], artist):
|
||||||
if utils.check_garbage_phrases: continue
|
if check_garbage_phrases: continue
|
||||||
self.code = link
|
self.code = link
|
||||||
break
|
break
|
||||||
|
|
||||||
if self.code == None:
|
if self.code == None:
|
||||||
for link in results:
|
for link in results:
|
||||||
if utils.check_garbage_phrases: continue
|
if check_garbage_phrases: continue
|
||||||
if utils.individual_word_match(song, link["title"]) >= 0.8 and utils.blank_include(link["title"], artist):
|
if individual_word_match(song, link["title"]) >= 0.8 and blank_include(link["title"], artist):
|
||||||
self.code = link
|
self.code = link
|
||||||
break
|
break
|
||||||
|
|
||||||
|
@ -104,9 +104,9 @@ class Ripper:
|
||||||
if len(list_of_lists) > 0:
|
if len(list_of_lists) > 0:
|
||||||
the_list = None
|
the_list = None
|
||||||
for list_ in list_of_lists:
|
for list_ in list_of_lists:
|
||||||
if utils.blank_include(list_["name"], title):
|
if blank_include(list_["name"], title):
|
||||||
if "artist" in self.args:
|
if "artist" in self.args:
|
||||||
if utils.blank_include(list_["artists"][0]["name"], self.args["artist"]):
|
if blank_include(list_["artists"][0]["name"], self.args["artist"]):
|
||||||
the_list = list_
|
the_list = list_
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
|
@ -137,14 +137,17 @@ class Ripper:
|
||||||
elif type == "album":
|
elif type == "album":
|
||||||
file_prefix = str(track["track_number"]) + " - "
|
file_prefix = str(track["track_number"]) + " - "
|
||||||
|
|
||||||
|
#print (track)
|
||||||
|
album = self.spotify.album(track["album"]["uri"])
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
"name": track["name"],
|
"name": track["name"],
|
||||||
"artist": track["artists"][0]["name"],
|
"artist": track["artists"][0]["name"],
|
||||||
"album": the_list["name"],
|
"album": album["name"],
|
||||||
"genre": parse_genre(self.spotify.artist(track["artists"][0]["uri"])["genres"]),
|
"genre": parse_genre(self.spotify.artist(track["artists"][0]["uri"])["genres"]),
|
||||||
"track_number": track["track_number"],
|
"track_number": track["track_number"],
|
||||||
"disc_number": track["disc_number"],
|
"disc_number": track["disc_number"],
|
||||||
"album_art": the_list["images"][0]["url"],
|
"album_art": album["images"][0]["url"],
|
||||||
"compilation": compilation,
|
"compilation": compilation,
|
||||||
"file_prefix": file_prefix,
|
"file_prefix": file_prefix,
|
||||||
}
|
}
|
||||||
|
@ -161,13 +164,13 @@ class Ripper:
|
||||||
def list(self, list_data):
|
def list(self, list_data):
|
||||||
locations = []
|
locations = []
|
||||||
#with open(".irs-download-log", "w+") as file:
|
#with open(".irs-download-log", "w+") as file:
|
||||||
# file.write(utils.format_download_log_data(list_data))
|
# file.write(format_download_log_data(list_data))
|
||||||
|
|
||||||
for track in list_data:
|
for track in list_data:
|
||||||
loc = self.song(track["name"], track["artist"], track)
|
loc = self.song(track["name"], track["artist"], track)
|
||||||
|
|
||||||
if loc != False:
|
if loc != False:
|
||||||
#utils.update_download_log_line_status(track, "downloaded")
|
#update_download_log_line_status(track, "downloaded")
|
||||||
locations.append(loc)
|
locations.append(loc)
|
||||||
|
|
||||||
#os.remove(".irs-download-log")
|
#os.remove(".irs-download-log")
|
||||||
|
@ -212,7 +215,7 @@ class Ripper:
|
||||||
|
|
||||||
print ('Downloading "%s" by "%s" ...' % (song, artist))
|
print ('Downloading "%s" by "%s" ...' % (song, artist))
|
||||||
|
|
||||||
file_name = data["file_prefix"] + utils.blank(song, False) + ".mp3"
|
file_name = data["file_prefix"] + blank(song, False) + ".mp3"
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestaudio/best',
|
'format': 'bestaudio/best',
|
||||||
|
@ -222,8 +225,8 @@ class Ripper:
|
||||||
'preferredcodec': 'mp3',
|
'preferredcodec': 'mp3',
|
||||||
'preferredquality': '192',
|
'preferredquality': '192',
|
||||||
}],
|
}],
|
||||||
'logger': utils.MyLogger(),
|
'logger': MyLogger(),
|
||||||
'progress_hooks': [utils.my_hook],
|
'progress_hooks': [my_hook],
|
||||||
}
|
}
|
||||||
|
|
||||||
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
||||||
|
|
Loading…
Reference in a new issue