mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-22 13:06:34 +00:00
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
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:
commit
d482a3a444
@ -1032,6 +1032,20 @@ class Media(models.Model):
|
||||
field = self.get_metadata_field('title')
|
||||
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
|
||||
def slugtitle(self):
|
||||
replaced = self.title.replace('_', '-').replace('&', 'and').replace('+', 'and')
|
||||
|
@ -217,15 +217,9 @@ def index_source_task(source_id):
|
||||
media.duration = float(video.get(fields('duration', media), None) or 0) or None
|
||||
media.title = str(video.get(fields('title', media), ''))[:200]
|
||||
timestamp = video.get(fields('timestamp', media), 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 set published for: {source} / {media} with "{e}"')
|
||||
else:
|
||||
media.published = published_dt
|
||||
published_dt = media.metadata_published(timestamp)
|
||||
if published_dt is not None:
|
||||
media.published = published_dt
|
||||
try:
|
||||
media.save()
|
||||
log.debug(f'Indexed media: {source} / {media}')
|
||||
@ -386,6 +380,9 @@ def download_media_metadata(media_id):
|
||||
# Media must have a valid upload date
|
||||
if 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
|
||||
if media.metadata_title:
|
||||
|
Loading…
Reference in New Issue
Block a user