add isodate requirement for parsing iso8601 durations

This commit is contained in:
jesopo 2020-02-24 10:30:59 +00:00
parent 5a2e4db608
commit eb60e09a23
3 changed files with 7 additions and 11 deletions

View file

@ -6,7 +6,6 @@ import datetime, re, urllib.parse
from src import EventManager, ModuleManager, utils
REGEX_YOUTUBE = re.compile("https?://(?:www\.|m\.)?(?:youtu.be/|youtube.com/)\\S+", re.I)
REGEX_ISO8601 = re.compile("PT(\d+H)?(\d+M)?(\d+S)?", re.I)
URL_YOUTUBESEARCH = "https://www.googleapis.com/youtube/v3/search"
URL_YOUTUBEVIDEO = "https://www.googleapis.com/youtube/v3/videos"
@ -52,7 +51,6 @@ class Module(ModuleManager.BaseModule):
video_views = self._number(statistics.get("viewCount"))
video_likes = self._number(statistics.get("likeCount"))
video_dislikes = self._number(statistics.get("dislikeCount"))
video_duration = content["duration"]
video_opinions = ""
if video_likes and video_dislikes:
@ -66,14 +64,9 @@ class Module(ModuleManager.BaseModule):
if video_views:
video_views_str = ", %s views" % video_views
match = re.match(REGEX_ISO8601, video_duration)
video_duration = ""
video_duration += "%s:" % match.group(1)[:-1].zfill(2
) if match.group(1) else ""
video_duration += "%s:" % match.group(2)[:-1].zfill(2
) if match.group(2) else "00:"
video_duration += "%s" % match.group(3)[:-1].zfill(2
) if match.group(3) else "00"
td = utils.datetime.parse.iso8601_duration(content["duration"])
video_duration = utils.datetime.format.to_pretty_time(
td.total_seconds())
url = URL_YOUTUBESHORT % video_id

View file

@ -4,6 +4,7 @@ dataclasses ==0.6
dnspython ==1.16.0
feedparser ==5.2.1
html5lib ==1.0.1
isodate ==0.6.0
lxml ==4.4.1
netifaces ==0.10.9
PySocks ==1.7.1

View file

@ -1,10 +1,12 @@
import re, typing
import datetime as _datetime
import dateutil.parser
import dateutil.parser, isodate
from .common import *
def iso8601(s: str) -> _datetime.datetime:
return dateutil.parser.parse(s)
def iso8601_duration(s: str) -> _datetime.timedelta:
return isodate.parse_duration(s)
def date_human(s: str) -> typing.Optional[_datetime.datetime]:
try: