mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-29 15:01:11 -05:00
YouTube/Lyrics/IMDb: add retries
This commit is contained in:
parent
022743711c
commit
009d6ceaa3
@ -55,6 +55,9 @@ class IMDb(callbacks.Plugin):
|
||||
threaded = True
|
||||
|
||||
def dosearch(self, query):
|
||||
url = None
|
||||
i = 0
|
||||
while i < 3 and not url:
|
||||
try:
|
||||
searchurl = "https://www.google.com/search?&q={0} site:imdb.com/title/".format(query)
|
||||
ua = UserAgent()
|
||||
@ -62,11 +65,10 @@ class IMDb(callbacks.Plugin):
|
||||
data = requests.get(searchurl, headers=header)
|
||||
soup = BeautifulSoup(data.text)
|
||||
elements = soup.select('.r a')
|
||||
url = elements[0]['href']
|
||||
url = urljoin(url, urlparse(url).path)
|
||||
url = urljoin(elements[0]['href'], urlparse(url).path)
|
||||
i += 1
|
||||
except Exception:
|
||||
return
|
||||
else:
|
||||
continue
|
||||
return url
|
||||
|
||||
def imdb(self, irc, msg, args, query):
|
||||
|
@ -53,6 +53,9 @@ class Lyrics(callbacks.Plugin):
|
||||
threaded = True
|
||||
|
||||
def dosearch(self, lyric):
|
||||
url = None
|
||||
i = 0
|
||||
while i < 3 and not url:
|
||||
try:
|
||||
searchurl = "https://www.google.com/search?&q={0} site:lyrics.fandom.com/wiki/".format(lyric)
|
||||
ua = UserAgent()
|
||||
@ -60,12 +63,11 @@ class Lyrics(callbacks.Plugin):
|
||||
data = requests.get(searchurl, headers=header)
|
||||
soup = BeautifulSoup(data.text)
|
||||
elements = soup.select('.r a')
|
||||
url = elements[0]['href']
|
||||
urljoin(url, urlparse(url).path)
|
||||
title = soup.find("h3").getText().replace(":", " - ").split('|')[0]
|
||||
url = urljoin(elements[0]['href'], urlparse(url).path)
|
||||
i += 1
|
||||
except Exception:
|
||||
return
|
||||
else:
|
||||
continue
|
||||
return title, url
|
||||
|
||||
def getlyrics(self, url):
|
||||
|
@ -59,6 +59,8 @@ class YouTube(callbacks.Plugin):
|
||||
|
||||
def dosearch(self, query):
|
||||
url = None
|
||||
k = 0
|
||||
while k < 3 and not url:
|
||||
try:
|
||||
searchurl = "https://www.google.com/search?&q={0} site:youtube.com".format(query)
|
||||
ua = UserAgent()
|
||||
@ -70,12 +72,9 @@ class YouTube(callbacks.Plugin):
|
||||
if 'watch?v=' in elements[i]['href']:
|
||||
url = elements[i]['href']
|
||||
break
|
||||
k += 1
|
||||
except Exception:
|
||||
try:
|
||||
self.dosearch(query)
|
||||
except Exception:
|
||||
return None
|
||||
else:
|
||||
continue
|
||||
return url
|
||||
|
||||
def get_video_id_from_url(self, url):
|
||||
|
Loading…
x
Reference in New Issue
Block a user