From 3411bac78ad27a0f2b67a010991a288d6de86c5c Mon Sep 17 00:00:00 2001 From: tcely Date: Sat, 1 Mar 2025 02:54:56 -0500 Subject: [PATCH 1/2] Set `Media.download_date` for imported files --- .../management/commands/import-existing-media.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tubesync/sync/management/commands/import-existing-media.py b/tubesync/sync/management/commands/import-existing-media.py index fd6a800d..66f6648c 100644 --- a/tubesync/sync/management/commands/import-existing-media.py +++ b/tubesync/sync/management/commands/import-existing-media.py @@ -1,4 +1,5 @@ import os +from datetime import timedelta from pathlib import Path from django.core.management.base import BaseCommand, CommandError from common.logger import log @@ -54,5 +55,16 @@ class Command(BaseCommand): item.media_file.name = str(Path(filepath).relative_to(item.media_file.storage.location)) item.downloaded = True item.downloaded_filesize = Path(filepath).stat().st_size + # set a reasonable download date + date = item.posix_epoch + timedelta(seconds=Path(filepath).stat().st_mtime) + if item.published and item.published > date: + date = item.published + if item.has_metadata: + metadata_date = item.posix_epoch + timedelta(seconds=item.loaded_metadata.get('epoch', 0)) + if metadata_date and metadata_date > date: + date = metadata_date + if item.download_date and item.download_date > date: + date = item.download_date + item.download_date = date item.save() log.info('Done') From b8503fd9e963fd0d25d1f4a6b8202a6c6c1e24d0 Mon Sep 17 00:00:00 2001 From: tcely Date: Wed, 5 Mar 2025 16:10:47 -0500 Subject: [PATCH 2/2] =?UTF-8?q?Use`Media.metadata=5Fpublished=E2=80=8E`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It does the same operation, but has logging too. --- tubesync/sync/management/commands/import-existing-media.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tubesync/sync/management/commands/import-existing-media.py b/tubesync/sync/management/commands/import-existing-media.py index 66f6648c..00fd5ef1 100644 --- a/tubesync/sync/management/commands/import-existing-media.py +++ b/tubesync/sync/management/commands/import-existing-media.py @@ -1,5 +1,4 @@ import os -from datetime import timedelta from pathlib import Path from django.core.management.base import BaseCommand, CommandError from common.logger import log @@ -56,11 +55,13 @@ class Command(BaseCommand): item.downloaded = True item.downloaded_filesize = Path(filepath).stat().st_size # set a reasonable download date - date = item.posix_epoch + timedelta(seconds=Path(filepath).stat().st_mtime) + date = item.metadata_published‎(Path(filepath).stat().st_mtime) if item.published and item.published > date: date = item.published if item.has_metadata: - metadata_date = item.posix_epoch + timedelta(seconds=item.loaded_metadata.get('epoch', 0)) + # TODO: switch to the newer function when it is merged from PR 807 + # item.get_metadata_first_value('epoch', 0) + metadata_date = item.metadata_published‎(item.loaded_metadata.get('epoch', 0)) if metadata_date and metadata_date > date: date = metadata_date if item.download_date and item.download_date > date: