mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-16 10:06:35 +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',), '')
|
return self.get_metadata_first_value(('fulltitle', 'title',), '')
|
||||||
|
|
||||||
def ts_to_dt(self, /, timestamp):
|
def ts_to_dt(self, /, timestamp):
|
||||||
assert timestamp is not None
|
|
||||||
try:
|
try:
|
||||||
timestamp_float = float(timestamp)
|
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}"')
|
log.warn(f'Could not compute published from timestamp for: {self.source} / {self} with "{e}"')
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
return self.posix_epoch + timedelta(seconds=timestamp_float)
|
return self.posix_epoch + timedelta(seconds=timestamp_float)
|
||||||
return None
|
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
|
@property
|
||||||
def slugtitle(self):
|
def slugtitle(self):
|
||||||
replaced = self.title.replace('_', '-').replace('&', 'and').replace('+', 'and')
|
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.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)
|
||||||
published_dt = media.metadata_published(timestamp)
|
try:
|
||||||
if published_dt is not None:
|
published_dt = media.ts_to_dt(timestamp)
|
||||||
media.published = published_dt
|
except AssertionError:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if published_dt:
|
||||||
|
media.published = published_dt
|
||||||
try:
|
try:
|
||||||
media.save()
|
media.save()
|
||||||
except IntegrityError as e:
|
except IntegrityError as e:
|
||||||
@ -500,9 +504,17 @@ 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()
|
timestamp = media.get_metadata_first_value(
|
||||||
if published:
|
('release_timestamp', 'timestamp',),
|
||||||
media.published = published
|
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
|
# Store title in DB so it's fast to access
|
||||||
if media.metadata_title:
|
if media.metadata_title:
|
||||||
|
Loading…
Reference in New Issue
Block a user