mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-15 17:46:37 +00:00
Merge pull request #1008 from tcely/patch-3
Some checks failed
CI / info (push) Has been cancelled
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.8) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / containerise (push) Has been cancelled
Some checks failed
CI / info (push) Has been cancelled
CI / test (3.10) (push) Has been cancelled
CI / test (3.11) (push) Has been cancelled
CI / test (3.12) (push) Has been cancelled
CI / test (3.8) (push) Has been cancelled
CI / test (3.9) (push) Has been cancelled
CI / containerise (push) Has been cancelled
Handle `AssertionError` for timestamp
This commit is contained in:
commit
9ae0fecb7d
@ -1312,23 +1312,15 @@ class Media(models.Model):
|
||||
return self.get_metadata_first_value(('fulltitle', 'title',), '')
|
||||
|
||||
def ts_to_dt(self, /, timestamp):
|
||||
assert timestamp is not None
|
||||
try:
|
||||
timestamp_float = float(timestamp)
|
||||
except Exception as e:
|
||||
except (TypeError, ValueError,) as e:
|
||||
log.warn(f'Could not compute published from timestamp for: {self.source} / {self} with "{e}"')
|
||||
pass
|
||||
else:
|
||||
return self.posix_epoch + timedelta(seconds=timestamp_float)
|
||||
return None
|
||||
|
||||
def metadata_published(self, timestamp=None):
|
||||
if timestamp is None:
|
||||
timestamp = self.get_metadata_first_value(
|
||||
('release_timestamp', 'timestamp',)
|
||||
)
|
||||
return self.ts_to_dt(timestamp)
|
||||
|
||||
@property
|
||||
def slugtitle(self):
|
||||
replaced = self.title.replace('_', '-').replace('&', 'and').replace('+', 'and')
|
||||
|
@ -330,9 +330,13 @@ 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)
|
||||
published_dt = media.metadata_published(timestamp)
|
||||
if published_dt is not None:
|
||||
media.published = published_dt
|
||||
try:
|
||||
published_dt = media.ts_to_dt(timestamp)
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
if published_dt:
|
||||
media.published = published_dt
|
||||
try:
|
||||
media.save()
|
||||
except IntegrityError as e:
|
||||
@ -500,9 +504,17 @@ 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
|
||||
timestamp = media.get_metadata_first_value(
|
||||
('release_timestamp', 'timestamp',),
|
||||
arg_dict=response,
|
||||
)
|
||||
try:
|
||||
published_dt = media.ts_to_dt(timestamp)
|
||||
except AssertionError:
|
||||
pass
|
||||
else:
|
||||
if published_dt:
|
||||
media.published = published_dt
|
||||
|
||||
# Store title in DB so it's fast to access
|
||||
if media.metadata_title:
|
||||
|
Loading…
Reference in New Issue
Block a user