From 3bbaa875f1749bb06a3a2d47fad07d0dbd48e911 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20F=C3=A4hrmann?= Date: Thu, 26 Oct 2023 21:50:18 +0200 Subject: [PATCH] [kemonoparty] fix parsing of non-standard 'dates' (#4676) --- gallery_dl/extractor/kemonoparty.py | 13 +++++++++---- test/results/kemonoparty.py | 10 ++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/gallery_dl/extractor/kemonoparty.py b/gallery_dl/extractor/kemonoparty.py index 1596cfb1..76e940c7 100644 --- a/gallery_dl/extractor/kemonoparty.py +++ b/gallery_dl/extractor/kemonoparty.py @@ -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 diff --git a/test/results/kemonoparty.py b/test/results/kemonoparty.py index 6594c4b2..06f62c82 100644 --- a/test/results/kemonoparty.py +++ b/test/results/kemonoparty.py @@ -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"),