diff --git a/irs/ripper.py b/irs/ripper.py index 44e9d54..875e300 100644 --- a/irs/ripper.py +++ b/irs/ripper.py @@ -47,6 +47,10 @@ class Ripper: "list": '{0}: "{1}" by "{2}"', "song": 'Downloading "{0}" by "{1}"', "converting": "Converting to mp3 ...", + "list-fail": "Could not find any lists.", + "bypass-captcha": "Trying to bypass google captcha", + "list-no-user-found": "No user was found by that name", + "metadata-fail": "Could not find any metadata." } if self.args["hook-text"].get("converting") is not None: CONFIG["converting"] = self.args["hook-text"]["converting"] @@ -136,7 +140,8 @@ class Ripper: def find_yt_url(self, song=None, artist=None, additional_search=None, caught_by_google=False, first=False, tries=0): if additional_search is None: additional_search = Config.parse_search_terms(self) - print(str(self.args["hook-text"].get("youtube"))) + if Config.parse_fprint(self) == False: + print(str(self.args["hook-text"].get("youtube"))) try: if not song: @@ -231,7 +236,7 @@ album row at @ session how to npr music reimagined hr version".split(" except TypeError: if caught_by_google is not True: # Assuming Google catches you trying to search youtube for music ;) - print("Trying to bypass google captcha.") + print(self.args["hook-text"]["bypass-captcha"]) return self.find_yt_url(song=song, artist=artist, additional_search=additional_search, caught_by_google=True, tries=tries + 1) elif caught_by_google is True and first is not True: return self.find_yt_url(song, artist, additional_search, caught_by_google, first=True, tries=tries + 1) @@ -268,7 +273,7 @@ with init, or in method arguments.") try: list_of_lists = self.spotify.user_playlists(username)["items"] except spotipy.client.SpotifyException: - print("No user was found by that name.") + print(self.args["hook-text"]["list-no-user-found"]) return False if len(list_of_lists) > 0: @@ -308,9 +313,10 @@ with init, or in method arguments.") if the_list is not None: YdlUtils.clear_line() - print(self.args["hook-text"].get("list") - .format(type.title(), the_list["name"].encode("utf-8"), - the_list["artists"][0]["name"].encode("utf-8"))) + if Config.parse_fprint(self) == False: + print(self.args["hook-text"].get("list") + .format(type.title(), the_list["name"].encode("utf-8"), + the_list["artists"][0]["name"].encode("utf-8"))) compilation = "" if type == "album": @@ -358,7 +364,7 @@ with init, or in method arguments.") return locations # return self.post_processing(locations) - print("Could not find any lists.") + print(self.args["hook-text"]["list-fail"]) return False def list(self, list_data): @@ -475,7 +481,7 @@ init, or in method arguments.") m.add_tag("compilation", data["compilation"]) m.add_album_art(str(data["album_art"])) else: - print("Could not find metadata.") + print(self.args["hook-text"]["metadata-fail"]) m.add_tag("title", song) m.add_tag("artist", artist) diff --git a/irs/utils.py b/irs/utils.py index 32830fa..2c03832 100644 --- a/irs/utils.py +++ b/irs/utils.py @@ -22,6 +22,8 @@ if sys.version_info[0] == 2: else: from irs.config import CONFIG +# CLI +import draftlog # ================== # Static Method Hook @@ -269,8 +271,9 @@ def flush_puts(msg, time=0.01): print("") -BOLD = code(1) END = code(0) +BOLD = code(1) +DIM = code(2) RED = code(31) GREEN = code(32) YELLOW = code(33) @@ -370,20 +373,48 @@ def console(ripper): sys.exit(0) -""" -# ===================== -# Config File and Flags -# ===================== +class FancyPrinting: + def __init__(self, media): + # `media` takes a dict: + # { + # "type": , + # "list-data": {"list_title": , "user-or-artist": }, + # "contents": [{"title": , "artist": , "album": }, {...}, ...] + # } + self.draft = draftlog.inject() + self.frames = "⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏".split(" ") + self.frame = -1 -def check_sources(ripper, key, default=None, environment=False, where=None): - if where is not None: - tmp_args = ripper.args.get(where) - else: - tmp_args = ripper.args + self.media_drafts = [] - if tmp_args.get(key): - return tmp_args.get(key) -""" + self.songs = [] + self.phrases = [] + self.media = media + + if self.media.type == "song": + song = self.media.contents[0] + self.title = (BYELLOW + "{0} " + END + YELLOW + "{1} " + DIM + "{2} ") + .format(song["title"], song["artist"], song["album"]) + elif self.media.type in ("playlist", "album"): + data = self.media["list_data"] + self.title = (YELLOW + "Playlist: " + BOLD + "{0} " + DIM + "{2} ") + .format(data["list_title"], data["user-or-artist"]) + + def start(self): + loader_draft = self.draft.log() + loader_draft.set_interval(self.loader_interval, 0.05, loader=True) + + # TODO: Get the logs to start w/ diff content depending on media type + # for song in self.media["contents"]: + # self.media_drafts.append(self.draft.log(song["title"])) + + + def loader_interval(self): + if self.frame > len(self.frames) - 2: + self.frame = -1 + self.frame += 1 + return (BCYAN + "{0} " + END + self.title + END + BCYAN + " {0}" + END) + .format(self.frames[self.frame]) # =========== @@ -451,6 +482,9 @@ class Config: if exact in (True, False): return exact + def parse_fprint(ripper): # fprint: fancy print + fprint = check_sources(ripper, "fancy_print") + return fprint #==============