Merge pull request #737 from tcely/patch-3
Some checks are pending
Run Django tests for TubeSync / test (3.10) (push) Waiting to run
Run Django tests for TubeSync / test (3.11) (push) Waiting to run
Run Django tests for TubeSync / test (3.12) (push) Waiting to run
Run Django tests for TubeSync / test (3.7) (push) Waiting to run
Run Django tests for TubeSync / test (3.8) (push) Waiting to run
Run Django tests for TubeSync / test (3.9) (push) Waiting to run
Run Django tests for TubeSync / containerise (push) Waiting to run

Add `metadata_published` function
This commit is contained in:
meeb 2025-02-18 07:21:53 +11:00 committed by GitHub
commit d482a3a444
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 9 deletions

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()
def metadata_published(self, timestamp=None):
published_dt = None
if timestamp is 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')

View File

@ -217,14 +217,8 @@ def index_source_task(source_id):
media.duration = float(video.get(fields('duration', media), None) or 0) or None media.duration = float(video.get(fields('duration', media), None) or 0) or None
media.title = str(video.get(fields('title', media), ''))[:200] media.title = str(video.get(fields('title', media), ''))[:200]
timestamp = video.get(fields('timestamp', media), None) timestamp = video.get(fields('timestamp', media), None)
if timestamp is not None: published_dt = media.metadata_published(timestamp)
try: if published_dt is not None:
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 set published for: {source} / {media} with "{e}"')
else:
media.published = published_dt media.published = published_dt
try: try:
media.save() media.save()
@ -386,6 +380,9 @@ def download_media_metadata(media_id):
# Media must have a valid upload date # Media must have a valid upload date
if upload_date: if upload_date:
media.published = timezone.make_aware(upload_date) media.published = timezone.make_aware(upload_date)
published = media.metadata_published()
if published:
media.published = published
# Store title in DB so it's fast to access # Store title in DB so it's fast to access
if media.metadata_title: if media.metadata_title: