From e86c8ebebb3c3b3ed7e05d93c72780666a3b6aa6 Mon Sep 17 00:00:00 2001 From: oddluck <39967334+oddluck@users.noreply.github.com> Date: Tue, 25 Feb 2020 09:41:27 +0000 Subject: [PATCH] SpiffyTitles/Youtube: replace duration regex --- SpiffyTitles/plugin.py | 26 +++++--------------------- YouTube/plugin.py | 28 ++-------------------------- 2 files changed, 7 insertions(+), 47 deletions(-) diff --git a/SpiffyTitles/plugin.py b/SpiffyTitles/plugin.py index d501ded..e451857 100644 --- a/SpiffyTitles/plugin.py +++ b/SpiffyTitles/plugin.py @@ -791,16 +791,16 @@ class SpiffyTitles(callbacks.Plugin): twitch_logo = "{0}\x0F\x02".format(self.registryValue("twitch.logo", dynamic.channel)) else: twitch_logo = "{0}\x0F".format(self.registryValue("twitch.logo", dynamic.channel)) - + return twitch_logo - + def get_imdb_logo(self): use_bold = self.registryValue("useBold", dynamic.channel) if use_bold: imdb_logo = "{0}\x0F\x02".format(self.registryValue("imdb.logo", dynamic.channel)) else: imdb_logo = "{0}\x0F".format(self.registryValue("imdb.logo", dynamic.channel)) - + return imdb_logo def get_total_seconds_from_duration(self, input): @@ -809,24 +809,8 @@ class SpiffyTitles(callbacks.Plugin): 4 minutes and 41 seconds. This method returns the total seconds so that the duration can be parsed as usual. """ - regex = re.compile(""" - (?P -?) P - (?:(?P \d+) Y)? - (?:(?P \d+) M)? - (?:(?P \d+) D)? - (?: T - (?:(?P \d+) H)? - (?:(?P\d+) M)? - (?:(?P\d+) S)? - )? - """, re.VERBOSE) - duration = regex.match(input).groupdict(0) - - delta = pendulum.duration(hours=int(duration['hours']), - minutes=int(duration['minutes']), - seconds=int(duration['seconds'])) - - return delta.total_seconds() + duration = pendulum.parse(input) + return duration.total_seconds() def get_timestamp_from_youtube_url(self, url): """ diff --git a/YouTube/plugin.py b/YouTube/plugin.py index dbabe1a..ba184ea 100644 --- a/YouTube/plugin.py +++ b/YouTube/plugin.py @@ -44,14 +44,6 @@ from fake_useragent import UserAgent from bs4 import BeautifulSoup from urllib.parse import urlencode, urlparse, parse_qsl -try: - from supybot.i18n import PluginInternationalization - _ = PluginInternationalization('YouTube') -except ImportError: - # Placeholder that allows to run the plugin on a bot - # without the i18n module - _ = lambda x: x - class YouTube(callbacks.Plugin): """Queries OMDB database for information about YouTube titles""" threaded = True @@ -122,24 +114,8 @@ class YouTube(callbacks.Plugin): 4 minutes and 41 seconds. This method returns the total seconds so that the duration can be parsed as usual. """ - regex = re.compile(""" - (?P -?) P - (?:(?P \d+) Y)? - (?:(?P \d+) M)? - (?:(?P \d+) D)? - (?: T - (?:(?P \d+) H)? - (?:(?P\d+) M)? - (?:(?P\d+) S)? - )? - """, re.VERBOSE) - duration = regex.match(input).groupdict(0) - - delta = pendulum.duration(hours=int(duration['hours']), - minutes=int(duration['minutes']), - seconds=int(duration['seconds'])) - - return delta.total_seconds() + duration = pendulum.parse(input) + return duration.total_seconds() def get_published_date(self, date): date = pendulum.parse(date, strict=False)