Add metadata_published property

This commit is contained in:
tcely authored and GitHub committed 2025-02-17 08:07:46 -05:00
1 parent 676b2c3ace
commit 695c1f6e59
1 file changed
+14
+14
View File
@@ -1032,6 +1032,20 @@ class Media(models.Model):
field = self.get_metadata_field('title') field = self.get_metadata_field('title')
return self.loaded_metadata.get(field, '').strip() 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 @property
def slugtitle(self): def slugtitle(self):
replaced = self.title.replace('_', '-').replace('&', 'and').replace('+', 'and') replaced = self.title.replace('_', '-').replace('&', 'and').replace('+', 'and')