Use Media.get_metadata_field

This commit is contained in:
tcely 2025-02-10 08:27:10 -05:00 committed by GitHub
parent b6334ce41c
commit b8f8d9d7fa
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -202,7 +202,7 @@ def index_source_task(source_id):
source.last_crawl = timezone.now()
source.save()
log.info(f'Found {len(videos)} media items for source: {source}')
fields = lambda x, t=source.source_type: Media.METADATA_FIELDS.get(x, dict()).get(t, x)
fields = lambda f, m: m.get_metadata_field(f)
for video in videos:
# Create or update each video as a Media object
key = video.get(source.key_field, None)
@ -214,9 +214,9 @@ def index_source_task(source_id):
except Media.DoesNotExist:
media = Media(key=key)
media.source = source
media.duration = float(video.get(fields('duration'), 0)) or None
media.title = str(video.get(fields('title'), ''))
timestamp = video.get(fields('timestamp'), None)
media.duration = float(video.get(fields('duration', media), 0)) or None
media.title = str(video.get(fields('title', media), ''))
timestamp = video.get(fields('timestamp', media), None)
if timestamp is not None:
try:
timestamp_float = float(timestamp)