add isodate requirement for parsing iso8601 durations
This commit is contained in:
parent
5a2e4db608
commit
eb60e09a23
3 changed files with 7 additions and 11 deletions
|
@ -6,7 +6,6 @@ import datetime, re, urllib.parse
|
||||||
from src import EventManager, ModuleManager, utils
|
from src import EventManager, ModuleManager, utils
|
||||||
|
|
||||||
REGEX_YOUTUBE = re.compile("https?://(?:www\.|m\.)?(?:youtu.be/|youtube.com/)\\S+", re.I)
|
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_YOUTUBESEARCH = "https://www.googleapis.com/youtube/v3/search"
|
||||||
URL_YOUTUBEVIDEO = "https://www.googleapis.com/youtube/v3/videos"
|
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_views = self._number(statistics.get("viewCount"))
|
||||||
video_likes = self._number(statistics.get("likeCount"))
|
video_likes = self._number(statistics.get("likeCount"))
|
||||||
video_dislikes = self._number(statistics.get("dislikeCount"))
|
video_dislikes = self._number(statistics.get("dislikeCount"))
|
||||||
video_duration = content["duration"]
|
|
||||||
|
|
||||||
video_opinions = ""
|
video_opinions = ""
|
||||||
if video_likes and video_dislikes:
|
if video_likes and video_dislikes:
|
||||||
|
@ -66,14 +64,9 @@ class Module(ModuleManager.BaseModule):
|
||||||
if video_views:
|
if video_views:
|
||||||
video_views_str = ", %s views" % video_views
|
video_views_str = ", %s views" % video_views
|
||||||
|
|
||||||
match = re.match(REGEX_ISO8601, video_duration)
|
td = utils.datetime.parse.iso8601_duration(content["duration"])
|
||||||
video_duration = ""
|
video_duration = utils.datetime.format.to_pretty_time(
|
||||||
video_duration += "%s:" % match.group(1)[:-1].zfill(2
|
td.total_seconds())
|
||||||
) 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"
|
|
||||||
|
|
||||||
url = URL_YOUTUBESHORT % video_id
|
url = URL_YOUTUBESHORT % video_id
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,7 @@ dataclasses ==0.6
|
||||||
dnspython ==1.16.0
|
dnspython ==1.16.0
|
||||||
feedparser ==5.2.1
|
feedparser ==5.2.1
|
||||||
html5lib ==1.0.1
|
html5lib ==1.0.1
|
||||||
|
isodate ==0.6.0
|
||||||
lxml ==4.4.1
|
lxml ==4.4.1
|
||||||
netifaces ==0.10.9
|
netifaces ==0.10.9
|
||||||
PySocks ==1.7.1
|
PySocks ==1.7.1
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import re, typing
|
import re, typing
|
||||||
import datetime as _datetime
|
import datetime as _datetime
|
||||||
import dateutil.parser
|
import dateutil.parser, isodate
|
||||||
from .common import *
|
from .common import *
|
||||||
|
|
||||||
def iso8601(s: str) -> _datetime.datetime:
|
def iso8601(s: str) -> _datetime.datetime:
|
||||||
return dateutil.parser.parse(s)
|
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]:
|
def date_human(s: str) -> typing.Optional[_datetime.datetime]:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in a new issue