Skip to content

Commit 82524d4

Browse files
authored
Merge pull request #973 from tcely/patch-2
Use `Media.has_metadata` in `Media.save` function
2 parents 98c031e + 1c9ef93 commit 82524d4

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

tubesync/sync/models.py

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,20 @@ def save(self, force_insert=False, force_update=False, using=None, update_fields
830830
update_fields = {'media_file', 'skip'}.union(update_fields)
831831

832832
# Trigger an update of derived fields from metadata
833-
if update_fields is None or 'metadata' in update_fields:
833+
update_md = (
834+
self.has_metadata and
835+
(
836+
update_fields is None or
837+
'metadata' in update_fields
838+
)
839+
)
840+
if update_md:
834841
setattr(self, '_cached_metadata_dict', None)
835-
if self.metadata:
836842
self.title = self.metadata_title[:200]
837843
self.duration = self.metadata_duration
838-
if update_fields is not None and "metadata" in update_fields:
839-
# If only some fields are being updated, make sure we update title and duration if metadata changes
840-
update_fields = {"title", "duration"}.union(update_fields)
844+
if update_fields is not None:
845+
# If only some fields are being updated, make sure we update title and duration if metadata changes
846+
update_fields = {"title", "duration"}.union(update_fields)
841847

842848
super().save(
843849
force_insert=force_insert,

0 commit comments

Comments
 (0)