mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-29 23:11:09 -05:00
IMDb/Lyrics/YouTube: simplify URL parsing
This commit is contained in:
parent
aaaebe6983
commit
bbfa1c72e9
@ -40,6 +40,7 @@ import json
|
|||||||
import re
|
import re
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
|
from urllib.parse import urljoin, urlparse
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from supybot.i18n import PluginInternationalization
|
from supybot.i18n import PluginInternationalization
|
||||||
@ -62,9 +63,7 @@ class IMDb(callbacks.Plugin):
|
|||||||
soup = BeautifulSoup(data.text)
|
soup = BeautifulSoup(data.text)
|
||||||
elements = soup.select('.r a')
|
elements = soup.select('.r a')
|
||||||
url = elements[0]['href']
|
url = elements[0]['href']
|
||||||
url = re.split('https?://', url)[-1]
|
url = urljoin(url, urlparse(url).path)
|
||||||
url = re.sub("&rct=.*", "", url)
|
|
||||||
url = "https://{0}".format(url)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -77,7 +76,7 @@ class IMDb(callbacks.Plugin):
|
|||||||
apikey = self.registryValue('omdbAPI')
|
apikey = self.registryValue('omdbAPI')
|
||||||
url = self.dosearch(query)
|
url = self.dosearch(query)
|
||||||
if url:
|
if url:
|
||||||
imdb_id = url.split("/title/")[1].rstrip("/")
|
imdb_id = url.split("/title/")[-1].rstrip("/")
|
||||||
omdb_url = "http://www.omdbapi.com/?i=%s&plot=short&r=json&tomatoes=true&apikey=%s" % (imdb_id, apikey)
|
omdb_url = "http://www.omdbapi.com/?i=%s&plot=short&r=json&tomatoes=true&apikey=%s" % (imdb_id, apikey)
|
||||||
else:
|
else:
|
||||||
irc.reply("No results found for {0}".format(query))
|
irc.reply("No results found for {0}".format(query))
|
||||||
|
@ -38,6 +38,7 @@ import requests
|
|||||||
import re
|
import re
|
||||||
import pylyrics3
|
import pylyrics3
|
||||||
from fake_useragent import UserAgent
|
from fake_useragent import UserAgent
|
||||||
|
from urllib.parse import urljoin, urlparse
|
||||||
|
|
||||||
try:
|
try:
|
||||||
from supybot.i18n import PluginInternationalization
|
from supybot.i18n import PluginInternationalization
|
||||||
@ -60,10 +61,8 @@ class Lyrics(callbacks.Plugin):
|
|||||||
soup = BeautifulSoup(data.text)
|
soup = BeautifulSoup(data.text)
|
||||||
elements = soup.select('.r a')
|
elements = soup.select('.r a')
|
||||||
url = elements[0]['href']
|
url = elements[0]['href']
|
||||||
url = re.split('https?://', url)[-1]
|
urljoin(url, urlparse(url).path)
|
||||||
url = re.sub("&rct=.*", "", url)
|
title = soup.find("h3").getText().replace(":", " - ").split('|')[0]
|
||||||
url = "https://{0}".format(url)
|
|
||||||
title = soup.find("h3").getText()
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
@ -90,7 +89,7 @@ class Lyrics(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
lyrics = self.getlyrics(url)
|
lyrics = self.getlyrics(url)
|
||||||
irc.reply(title.replace(":", " - "))
|
irc.reply(title)
|
||||||
irc.reply(lyrics)
|
irc.reply(lyrics)
|
||||||
except Exception:
|
except Exception:
|
||||||
irc.reply("Unable to retrieve lyrics from {0}".format(url))
|
irc.reply("Unable to retrieve lyrics from {0}".format(url))
|
||||||
|
@ -66,9 +66,6 @@ class YouTube(callbacks.Plugin):
|
|||||||
soup = BeautifulSoup(data.text)
|
soup = BeautifulSoup(data.text)
|
||||||
elements = soup.select('.r a')
|
elements = soup.select('.r a')
|
||||||
url = elements[0]['href']
|
url = elements[0]['href']
|
||||||
url = re.split('https?://', url)[-1]
|
|
||||||
url = re.sub("&rct=.*", "", url)
|
|
||||||
url = "https://{0}".format(url)
|
|
||||||
except Exception:
|
except Exception:
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user