diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index d8a43649..8ae84a4e 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -1032,6 +1032,20 @@ class Media(models.Model): field = self.get_metadata_field('title') return self.loaded_metadata.get(field, '').strip() + @property + def metadata_published(self): + published_dt = None + field = self.get_metadata_field('timestamp') + timestamp = self.loaded_metadata.get(field, None) + if timestamp is not None: + try: + timestamp_float = float(timestamp) + posix_epoch = datetime(1970, 1, 1, tzinfo=tz.utc) + published_dt = posix_epoch + timedelta(seconds=timestamp_float) + except Exception as e: + log.warn(f'Could not compute published from timestamp for: {self.source} / {self} with "{e}"') + return published_dt + @property def slugtitle(self): replaced = self.title.replace('_', '-').replace('&', 'and').replace('+', 'and')