diff --git a/src/auto_archiver/core/metadata.py b/src/auto_archiver/core/metadata.py index 3b73dcd7..cca49a47 100644 --- a/src/auto_archiver/core/metadata.py +++ b/src/auto_archiver/core/metadata.py @@ -7,6 +7,8 @@ import datetime from urllib.parse import urlparse from dateutil.parser import parse as parse_dt +from loguru import logger + from .media import Media from .context import ArchivingContext @@ -106,10 +108,15 @@ def set_timestamp(self, timestamp: datetime.datetime) -> Metadata: def get_timestamp(self, utc=True, iso=True) -> datetime.datetime: ts = self.get("timestamp") if not ts: return - if type(ts) == float: ts = datetime.datetime.fromtimestamp(ts) - if utc: ts = ts.replace(tzinfo=datetime.timezone.utc) - if iso: return ts.isoformat() - return ts + try: + if type(ts) == str: ts = datetime.datetime.fromisoformat(ts) + if type(ts) == float: ts = datetime.datetime.fromtimestamp(ts) + if utc: ts = ts.replace(tzinfo=datetime.timezone.utc) + if iso: return ts.isoformat() + return ts + except Exception as e: + logger.error(f"Unable to parse timestamp {ts}: {e}") + return def add_media(self, media: Media, id: str = None) -> Metadata: # adds a new media, optionally including an id diff --git a/src/auto_archiver/version.py b/src/auto_archiver/version.py index 335414da..30ebc893 100644 --- a/src/auto_archiver/version.py +++ b/src/auto_archiver/version.py @@ -3,7 +3,7 @@ _MINOR = "7" # On main and in a nightly release the patch should be one ahead of the last # released build. -_PATCH = "9" +_PATCH = "10" # This is mainly for nightly builds which have the suffix ".dev$DATE". See # https://semver.org/#is-v123-a-semantic-version for the semantics. _SUFFIX = ""