mirror of
https://github.com/cooperhammond/irs.git
synced 2025-01-08 20:05:27 +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:
|
else:
|
||||||
soup = BeautifulSoup(CaptchaCheat.cheat_it(link), 'html.parser')
|
soup = BeautifulSoup(CaptchaCheat.cheat_it(link), 'html.parser')
|
||||||
|
|
||||||
|
# print(soup.prettify())
|
||||||
# with open("index.html", "w") as f:
|
# with open("index.html", "w") as f:
|
||||||
# f.write(soup.prettify().encode('utf-8'))
|
# f.write(soup.prettify().encode('utf-8'))
|
||||||
|
|
||||||
|
@ -166,6 +167,7 @@ init, or in method arguments.")
|
||||||
try:
|
try:
|
||||||
if "yt-simple-endpoint style-scope ytd-video-renderer" in str(" ".join(link["class"])) or \
|
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"])):
|
"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"]:
|
if "&list=" not in link["href"]:
|
||||||
return link
|
return link
|
||||||
except KeyError:
|
except KeyError:
|
||||||
|
@ -223,14 +225,14 @@ album row at @ session".split(" ")
|
||||||
try:
|
try:
|
||||||
return ("https://youtube.com" + self.code["href"], self.code["title"])
|
return ("https://youtube.com" + self.code["href"], self.code["title"])
|
||||||
except TypeError:
|
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)
|
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", ..)
|
def album(self, title, artist=None): # Alias for spotify_list("album", ..)
|
||||||
return self.spotify_list("album", title=title, artist=artist)
|
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")
|
where="post_processors")
|
||||||
else:
|
else:
|
||||||
return True
|
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