From 65c7709e39d9d7202523cc1060e5e56bec7dd1f6 Mon Sep 17 00:00:00 2001 From: Kepoor Hampond Date: Tue, 31 Jan 2017 19:08:04 -0800 Subject: [PATCH] Added feature based off of https://github.com/kepoorhampond/irs/issues/8 --- irs/config.py | 5 ++++- irs/manager.py | 10 ++++++++-- setup.py | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/irs/config.py b/irs/config.py index e427e1e..29a4fd3 100644 --- a/irs/config.py +++ b/irs/config.py @@ -15,7 +15,10 @@ CONFIG = dict( client_id = '', client_secret = '', - # For a custom directory. Note that `~` will not work as a shortcut. + additional_search_terms = 'lyrics', + + # For a custom directory. Note that `~` will not work as a shortcut in a + # plain text manner. directory = str(expanduser("~")) + "/Music", # If you want numbered file names diff --git a/irs/manager.py b/irs/manager.py index 7596a92..3502240 100644 --- a/irs/manager.py +++ b/irs/manager.py @@ -64,7 +64,7 @@ class Manager: print (color(song, ["BOLD", "UNDERLINE"]) + ' by ' + color(artist, ["BOLD", "UNDERLINE"])) - search_terms = song + " " + artist + " lyrics" + search_terms = song + " " + artist + " " + CONFIG["additional_search_terms"] query_string = urlencode({"search_query" : (search_terms)}) html_content = urlopen("http://www.youtube.com/results?" + query_string) @@ -86,7 +86,7 @@ class Manager: audio_url = ("http://www.youtube.com/watch?v=" + search_results[i]) except Exception: print (bc.FAIL + "Could not find song." + bc.ENDC) - exit(1) + return False title = strip_special_chars((BeautifulSoup(urlopen(audio_url), 'html.parser')).title.string.lower()) song_title = song.lower().split("/") @@ -227,6 +227,9 @@ class Manager: tracknum=song["tracknum"], album_art_url=song["album_cover"], \ out_of="%s/%s - " % (song["tracknum"], len(songs))) + if song_loc == False: + continue + if self.args.one_folder: one_folder = CONFIG["directory"] + "/" + strip_special_chars(name[:30]) @@ -268,6 +271,9 @@ class Manager: print (color(out_of, ["UNDERLINE"]), end="") audio_code = self.find_mp3(song=song, artist=artist) + if audio_code == False: + return False + if CONFIG["numbered_file_names"] and tracknum: track = str(tracknum) + " - " else: diff --git a/setup.py b/setup.py index 7df4634..d225006 100644 --- a/setup.py +++ b/setup.py @@ -2,7 +2,7 @@ from setuptools import setup setup( name='irs', - version='3.1.1', + version='3.2.1', description='A music downloader that just gets metadata.', url='https://github.com/kepoorhampond/irs', author='Kepoor Hampond',