diff --git a/irs/ripper.py b/irs/ripper.py index 331a7b0..c98bfc1 100644 --- a/irs/ripper.py +++ b/irs/ripper.py @@ -159,6 +159,7 @@ init, or in method arguments.") else: soup = BeautifulSoup(CaptchaCheat.cheat_it(link), 'html.parser') + # print(soup.prettify()) # with open("index.html", "w") as f: # f.write(soup.prettify().encode('utf-8')) @@ -166,6 +167,7 @@ init, or in method arguments.") try: if "yt-simple-endpoint style-scope ytd-video-renderer" in str(" ".join(link["class"])) or \ "yt-uix-tile-link yt-ui-ellipsis yt-ui-ellipsis-2 yt-uix-sessionlink spf-link " in str(" ".join(link["class"])): + if "&list=" not in link["href"]: return link except KeyError: @@ -223,14 +225,14 @@ album row at @ session".split(" ") try: return ("https://youtube.com" + self.code["href"], self.code["title"]) except TypeError: - if first is not True: + if caught_by_google is not True: + # Assuming Google catches you trying to search youtube for music ;) + print("Trying to bypass google captcha.") + return self.find_yt_url(song=song, artist=artist, additional_search=additional_search, caught_by_google=True) + 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) - - # # Assuming Google catches you trying to search youtube for music ;) - # print("Trying to bypass google captcha.") - # return self.find_yt_url(song=song, artist=artist, additional_search=additional_search, caught_by_google=True) - - + + def album(self, title, artist=None): # Alias for spotify_list("album", ..) return self.spotify_list("album", title=title, artist=artist) diff --git a/irs/utils.py b/irs/utils.py index ff13995..caef49f 100644 --- a/irs/utils.py +++ b/irs/utils.py @@ -442,3 +442,30 @@ class Config: where="post_processors") else: return True + + +#============== +# Captcha Cheat +#============== +# I basically consider myself a genius for this snippet. + +from splinter import Browser +from time import sleep + + +@staticmethods +class CaptchaCheat: + def cheat_it(url, t=1): + executable_path = {'executable_path': '/usr/local/bin/chromedriver'} + with Browser('chrome', **executable_path) as b: + b.visit(url) + sleep(t) + while CaptchaCheat.strip_it(b.evaluate_script("document.URL")) != CaptchaCheat.strip_it(url): + sleep(t) + return b.evaluate_script("document.getElementsByTagName('html')[0].innerHTML") + + def strip_it(s): + s = s.encode("utf-8") + s = s.strip("http://") + s = s.strip("https://") + return s