mirror of
https://github.com/cooperhammond/irs.git
synced 2024-11-08 18:38:33 +00:00
Merge pull request #18 from kepoorhampond/artist-and-album
Added feature to use the -a flag with -A
This commit is contained in:
commit
04909589cf
10
irs/cli.py
10
irs/cli.py
|
@ -14,7 +14,7 @@ def main():
|
|||
parser = argparse.ArgumentParser()
|
||||
|
||||
# Single Song
|
||||
parser.add_argument("-a", "--artist", dest="artist", help="Specify artist name. Must be used with -s/--song")
|
||||
parser.add_argument("-a", "--artist", dest="artist", help="Specify artist name. Must be used with -s/--song or -A/--album")
|
||||
parser.add_argument("-s", "--song", dest="song", help="Specify song name. Must be used with -a/--artist")
|
||||
|
||||
# Album
|
||||
|
@ -39,7 +39,6 @@ def main():
|
|||
print (os.path.dirname(irs.__file__) + "/config.py")
|
||||
sys.exit()
|
||||
|
||||
|
||||
ripper_args = {
|
||||
"post_processors": {
|
||||
"custom_directory": args.location,
|
||||
|
@ -47,12 +46,17 @@ def main():
|
|||
}
|
||||
}
|
||||
|
||||
# Combiner args from argparse and the ripper_args as above and then
|
||||
# remove all keys with the value of "None"
|
||||
ripper_args.update(vars(args))
|
||||
ripper_args = dict((k, v) for k, v in ripper_args.iteritems() if v)
|
||||
|
||||
ripper = Ripper(ripper_args)
|
||||
|
||||
if args.artist and args.song:
|
||||
ripper.song(args.song, args.artist)
|
||||
elif args.album:
|
||||
ripper.spotify_list("album", args.album)
|
||||
ripper.spotify_list("album", args.album, artist=args.artist)
|
||||
elif args.username and args.playlist:
|
||||
ripper.spotify_list("playlist", args.playlist, args.username)
|
||||
else:
|
||||
|
|
|
@ -11,6 +11,7 @@ CONFIG = dict(
|
|||
# You can either specify Spotify keys here, or in environment variables.
|
||||
|
||||
additional_search_terms = 'lyrics',
|
||||
# Search terms for youtube
|
||||
|
||||
organize = True,
|
||||
# True always forces organization.
|
||||
|
|
|
@ -79,7 +79,6 @@ class Ripper:
|
|||
new_loc = new_loc.replace("//", "/")
|
||||
os.rename(loc, new_loc)
|
||||
locations[index] = new_loc
|
||||
print (new_loc)
|
||||
elif self.type == "playlist":
|
||||
for index, loc in enumerate(locations):
|
||||
new_loc = ""
|
||||
|
@ -113,7 +112,7 @@ class Ripper:
|
|||
link = "http://www.youtube.com/results?" + query_string
|
||||
|
||||
html_content = urlopen(link).read()
|
||||
soup = BeautifulSoup(html_content, 'html.parser')#.prettify
|
||||
soup = BeautifulSoup(html_content, 'html.parser')#.prettify()
|
||||
|
||||
def find_link(link):
|
||||
try:
|
||||
|
@ -125,22 +124,30 @@ class Ripper:
|
|||
|
||||
results = list(filter(None, (map(find_link, soup.find_all("a")))))
|
||||
|
||||
garbage_phrases = "cover album live clean rare version".split(" ")
|
||||
garbage_phrases = "cover album live clean rare version full full album".split(" ")
|
||||
|
||||
self.code = None
|
||||
for link in results:
|
||||
if blank_include(link["title"], song) and blank_include(link["title"], artist):
|
||||
if check_garbage_phrases: continue
|
||||
self.code = link
|
||||
break
|
||||
counter = 0
|
||||
|
||||
if self.code == None:
|
||||
|
||||
while self.code == None and counter <= 10:
|
||||
counter += 1
|
||||
for link in results:
|
||||
if check_garbage_phrases: continue
|
||||
if individual_word_match(song, link["title"]) >= 0.8 and blank_include(link["title"], artist):
|
||||
if blank_include(link["title"], song) and blank_include(link["title"], artist):
|
||||
if check_garbage_phrases(garbage_phrases, link["title"], song): continue
|
||||
self.code = link
|
||||
break
|
||||
|
||||
if self.code == None:
|
||||
for link in results:
|
||||
if check_garbage_phrases(garbage_phrases, link["title"], song): continue
|
||||
if individual_word_match(song, link["title"]) >= 0.8 and blank_include(link["title"], artist):
|
||||
self.code = link
|
||||
break
|
||||
|
||||
if self.code == None:
|
||||
song = limit_song_name(song)
|
||||
|
||||
if self.code == None:
|
||||
if additional_search == "lyrics":
|
||||
return self.find_yt_url(song, artist, "")
|
||||
|
@ -155,7 +162,7 @@ class Ripper:
|
|||
def playlist(self, title, username): # Alias for `spotify_list("playlist", ...)`
|
||||
return self.spotify_list("playlist", title, username)
|
||||
|
||||
def spotify_list(self, type=None, title=None, username=None):
|
||||
def spotify_list(self, type=None, title=None, username=None, artist=None):
|
||||
try:
|
||||
if not type: type = self.args["type"]
|
||||
if not title: title = self.args["list_title"]
|
||||
|
@ -179,9 +186,9 @@ class Ripper:
|
|||
the_list = None
|
||||
for list_ in list_of_lists:
|
||||
if blank_include(list_["name"], title):
|
||||
if "artist" in self.args:
|
||||
if blank_include(list_["artists"][0]["name"], self.args["artist"]):
|
||||
the_list = list_
|
||||
if parse_artist(self):
|
||||
if blank_include(list_["artists"][0]["name"], parse_artist(self)):
|
||||
the_list = self.spotify.album(list_["uri"])
|
||||
break
|
||||
else:
|
||||
if type == "album":
|
||||
|
@ -196,6 +203,7 @@ class Ripper:
|
|||
compilation = ""
|
||||
if type == "album":
|
||||
tmp_artists = []
|
||||
|
||||
for track in the_list["tracks"]["items"]:
|
||||
tmp_artists.append(track["artists"][0]["name"])
|
||||
tmp_artists = list(set(tmp_artists))
|
||||
|
|
19
irs/utils.py
19
irs/utils.py
|
@ -28,6 +28,15 @@ def my_hook(d):
|
|||
# Object Manipulation and Checking
|
||||
#=================================
|
||||
|
||||
def limit_song_name(song):
|
||||
bad_phrases = "remaster remastered master".split(" ")
|
||||
# I have "master" here because Spotify actually sometimes mispells stuff
|
||||
# and it is hella annoying, so this was my solution
|
||||
for phrase in bad_phrases:
|
||||
if blank_include(song.split(" - ")[-1], phrase):
|
||||
return song.split(" - ")[0]
|
||||
return song
|
||||
|
||||
def check_garbage_phrases(phrases, string, title):
|
||||
for phrase in phrases:
|
||||
if phrase in blank(string):
|
||||
|
@ -57,7 +66,7 @@ def individual_word_match(match_against, match):
|
|||
for word in match:
|
||||
if match_ag == word:
|
||||
matched.append(word)
|
||||
return (float(matched.uniq.size) / float(match_against.size))
|
||||
return (float(len(set(matched))) / float(len(match_against)))
|
||||
|
||||
def flatten(l):
|
||||
flattened_list = []
|
||||
|
@ -300,7 +309,7 @@ from .config import CONFIG
|
|||
def check_sources(ripper, key, default=None, environment=False, where=None):
|
||||
tmp_args = ripper.args
|
||||
if where != None and ripper.args.get(where):
|
||||
tmp_args = ripper.args.get("where")
|
||||
tmp_args = ripper.args.get("where")
|
||||
|
||||
if ripper.args.get(key):
|
||||
return ripper.args.get(key)
|
||||
|
@ -320,6 +329,10 @@ def parse_search_terms(ripper):
|
|||
search_terms = check_sources(ripper, "additional_search_terms", "lyrics")
|
||||
return search_terms
|
||||
|
||||
def parse_artist(ripper):
|
||||
artist = check_sources(ripper, "artist")
|
||||
return artist
|
||||
|
||||
def parse_directory(ripper):
|
||||
directory = check_sources(ripper, "custom_directory", where="post_processors")
|
||||
if directory == None:
|
||||
|
@ -342,4 +355,4 @@ def parse_organize(ripper):
|
|||
|
||||
def parse_search_terms(ripper):
|
||||
search_terms = check_sources(ripper, "additional_search_terms", "lyrics")
|
||||
return search_terms
|
||||
return search_terms
|
Loading…
Reference in a new issue