mirror of
https://github.com/cooperhammond/irs.git
synced 2024-12-22 17:35:28 +00:00
Merge pull request #38 from kepoorhampond/captcha-cheat
Bypass captcha in case google catches onto you abusing their special child youtube 😉
This commit is contained in:
commit
a1da7869ad
|
@ -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,13 +225,13 @@ 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)
|
||||
|
|
27
irs/utils.py
27
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
|
||||
|
|
Loading…
Reference in a new issue