mirror of
https://github.com/oddluck/limnoria-plugins.git
synced 2025-04-29 06:51:12 -05:00
Lyrics: match break, debug url, add retries
This commit is contained in:
parent
d2118e773f
commit
454fac3ca9
@ -54,7 +54,10 @@ class Lyrics(callbacks.Plugin):
|
|||||||
threaded = True
|
threaded = True
|
||||||
|
|
||||||
def dosearch(self, irc, channel, text):
|
def dosearch(self, irc, channel, text):
|
||||||
google = ddg = title = None
|
google = None
|
||||||
|
ddg = None
|
||||||
|
title = None
|
||||||
|
match = None
|
||||||
if self.registryValue("google", channel) > 0:
|
if self.registryValue("google", channel) > 0:
|
||||||
google = irc.getCallback("google")
|
google = irc.getCallback("google")
|
||||||
if not google:
|
if not google:
|
||||||
@ -69,6 +72,8 @@ class Lyrics(callbacks.Plugin):
|
|||||||
query = "site:lyrics.fandom.com/wiki/ %s" % text
|
query = "site:lyrics.fandom.com/wiki/ %s" % text
|
||||||
pattern = re.compile(r"https?://lyrics.fandom.com/wiki/.*")
|
pattern = re.compile(r"https?://lyrics.fandom.com/wiki/.*")
|
||||||
for i in range(1, 3):
|
for i in range(1, 3):
|
||||||
|
if match:
|
||||||
|
break
|
||||||
if google and self.registryValue("google", channel) == i:
|
if google and self.registryValue("google", channel) == i:
|
||||||
try:
|
try:
|
||||||
results = google.decode(google.search(query, irc.network, channel))
|
results = google.decode(google.search(query, irc.network, channel))
|
||||||
@ -82,7 +87,10 @@ class Lyrics(callbacks.Plugin):
|
|||||||
title = r["title"].replace(":", " - ").split("|")[0]
|
title = r["title"].replace(":", " - ").split("|")[0]
|
||||||
except TypeError:
|
except TypeError:
|
||||||
title = r.title.replace(":", " - ").split("|")[0]
|
title = r.title.replace(":", " - ").split("|")[0]
|
||||||
log.debug("Lyrics: found link using Google search")
|
log.debug(
|
||||||
|
"Lyrics: found link using Google search: %s"
|
||||||
|
% match.group(0)
|
||||||
|
)
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -98,7 +106,9 @@ class Lyrics(callbacks.Plugin):
|
|||||||
match = re.search(pattern, r[2])
|
match = re.search(pattern, r[2])
|
||||||
if match:
|
if match:
|
||||||
title = r[0].replace(":", " - ").split("|")[0]
|
title = r[0].replace(":", " - ").split("|")[0]
|
||||||
log.debug("Lyrics: found link using DDG")
|
log.debug(
|
||||||
|
"Lyrics: found link using DDG: %s" % match.group(0)
|
||||||
|
)
|
||||||
break
|
break
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@ -107,28 +117,33 @@ class Lyrics(callbacks.Plugin):
|
|||||||
else:
|
else:
|
||||||
return None, None
|
return None, None
|
||||||
|
|
||||||
def getlyrics(self, query):
|
def getlyrics(self, query, retries=0):
|
||||||
lyrics = None
|
lyrics = None
|
||||||
if "lyrics.fandom.com/wiki/" in query:
|
if retries < 3:
|
||||||
try:
|
if "lyrics.fandom.com/wiki/" in query:
|
||||||
log.debug("Lyrics: requesting {0}".format(query))
|
try:
|
||||||
lyrics = pylyrics3.get_lyrics_from_url(query)
|
log.debug("Lyrics: requesting {0}".format(query))
|
||||||
except Exception:
|
lyrics = pylyrics3.get_lyrics_from_url(query)
|
||||||
pass
|
except Exception:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
log.debug("Lyrics: requesting {0}".format(query))
|
||||||
|
query = query.split(",", 1)
|
||||||
|
lyrics = pylyrics3.get_song_lyrics(
|
||||||
|
query[0].strip(), query[1].strip()
|
||||||
|
)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
if lyrics:
|
||||||
|
lyrics = re.sub(r"(?<!\.|\!|\?)\s+\n", ".", lyrics)
|
||||||
|
lyrics = re.sub(r"\s+\n", "", lyrics)
|
||||||
|
return lyrics
|
||||||
|
else:
|
||||||
|
self.getLyrics(query, retries + 1)
|
||||||
else:
|
else:
|
||||||
try:
|
log.info("Lyrics: maximum number of retries (3) reached.")
|
||||||
log.debug("Lyrics: requesting {0}".format(query))
|
return
|
||||||
query = query.split(",", 1)
|
|
||||||
lyrics = pylyrics3.get_song_lyrics(query[0].strip(), query[1].strip())
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
if lyrics:
|
|
||||||
lyrics = re.sub(r"(?<!\.|\!|\?)\s+\n", ".", lyrics)
|
|
||||||
lyrics = re.sub(r"\s+\n", "", lyrics)
|
|
||||||
|
|
||||||
return lyrics
|
|
||||||
else:
|
|
||||||
return
|
|
||||||
|
|
||||||
def lyric(self, irc, msg, args, lyric):
|
def lyric(self, irc, msg, args, lyric):
|
||||||
"""<query>
|
"""<query>
|
||||||
@ -165,6 +180,7 @@ class Lyrics(callbacks.Plugin):
|
|||||||
return
|
return
|
||||||
|
|
||||||
lyric = wrap(lyric, ["text"])
|
lyric = wrap(lyric, ["text"])
|
||||||
|
lyrics = lyric
|
||||||
|
|
||||||
|
|
||||||
Class = Lyrics
|
Class = Lyrics
|
||||||
|
Loading…
x
Reference in New Issue
Block a user