1
0
mirror of https://github.com/mikf/gallery-dl.git synced 2024-11-26 12:42:29 +01:00

[kemonoparty] fix parsing of non-standard 'dates' (#4676)

This commit is contained in:
Mike Fährmann 2023-10-26 21:50:18 +02:00
parent 75dec71253
commit 3bbaa875f1
No known key found for this signature in database
GPG Key ID: 5680CA389D365A88
2 changed files with 19 additions and 4 deletions

View File

@ -69,8 +69,9 @@ class KemonopartyExtractor(Extractor):
headers["Referer"] = "{}/{}/user/{}/post/{}".format(
self.root, post["service"], post["user"], post["id"])
post["_http_headers"] = headers
post["date"] = text.parse_datetime(
post["published"] or post["added"], "%Y-%m-%dT%H:%M:%S")
post["date"] = self._parse_datetime(
post["published"] or post["added"])
if username:
post["username"] = username
if comments:
@ -205,6 +206,11 @@ class KemonopartyExtractor(Extractor):
})
return dms
def _parse_datetime(self, date_string):
if len(date_string) > 19:
date_string = date_string[:19]
return text.parse_datetime(date_string, "%Y-%m-%dT%H:%M:%S")
@memcache(keyarg=1)
def _discord_channels(self, server):
url = "{}/api/v1/discord/channel/lookup/{}".format(
@ -360,8 +366,7 @@ class KemonopartyDiscordExtractor(KemonopartyExtractor):
"name": path, "type": "inline", "hash": ""})
post["channel_name"] = self.channel_name
post["date"] = text.parse_datetime(
post["published"], "%Y-%m-%dT%H:%M:%S.%f")
post["date"] = self._parse_datetime(post["published"])
post["count"] = len(files)
yield Message.Directory, post

View File

@ -199,6 +199,16 @@ __tests__ = (
"#exception": exception.NotFoundError,
},
{
"#url" : "https://kemono.su/patreon/user/6298789/post/69764693",
"#comment" : "'published' metadata with extra microsecond data",
"#category": ("", "kemonoparty", "patreon"),
"#class" : kemonoparty.KemonopartyPostExtractor,
"date" : "dt:2022-07-29 21:12:11",
"published": "2022-07-29T21:12:11.483000",
},
{
"#url" : "https://kemono.party/discord/server/488668827274444803#608504710906904576",
"#category": ("", "kemonoparty", "discord"),