Add metadata_published property
This commit is contained in:
1 parent
676b2c3ace
commit
695c1f6e59
1 file changed
+14
@@ -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')
|
||||
|
||||
Reference in new issue
Block a user