From 24ae70ea708e1ccb4ca62932f93197a2b74a0cd9 Mon Sep 17 00:00:00 2001 From: meeb Date: Wed, 5 Apr 2023 11:02:21 +1000 Subject: [PATCH] add reset-metadata command, related to #287 --- README.md | 1 + docs/reset-metadata.md | 30 +++++++++++++++++++ .../management/commands/reset-metadata.py | 19 ++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 docs/reset-metadata.md create mode 100644 tubesync/sync/management/commands/reset-metadata.py diff --git a/README.md b/README.md index 30f2107..7965444 100644 --- a/README.md +++ b/README.md @@ -241,6 +241,7 @@ and less common features: * [Reset tasks from the command line](https://github.com/meeb/tubesync/blob/main/docs/reset-tasks.md) * [Using PostgreSQL, MySQL or MariaDB as database backends](https://github.com/meeb/tubesync/blob/main/docs/other-database-backends.md) * [Using cookies](https://github.com/meeb/tubesync/blob/main/docs/using-cookies.md) + * [Reset metadata](https://github.com/meeb/tubesync/blob/main/docs/reset-metadata.md) # Warnings diff --git a/docs/reset-metadata.md b/docs/reset-metadata.md new file mode 100644 index 0000000..0311d37 --- /dev/null +++ b/docs/reset-metadata.md @@ -0,0 +1,30 @@ +# TubeSync + +## Advanced usage guide - reset media metadata from the command line + +This command allows you to reset all media item metadata. You might want to use +this if you have a lot of media items with invalid metadata and you want to +wipe it which triggers the metadata to be redownloaded. + + +## Requirements + +You have added some sources and media + +## Steps + +### 1. Run the reset tasks command + +Execute the following Django command: + +`./manage.py reset-metadata` + +When deploying TubeSync inside a container, you can execute this with: + +`docker exec -ti tubesync python3 /app/manage.py reset-metadata` + +This command will log what its doing to the terminal when you run it. + +When this is run, new tasks will be immediately created so all your media +items will start downloading updated metadata straight away, any missing information +such as thumbnails will be redownloaded, etc. diff --git a/tubesync/sync/management/commands/reset-metadata.py b/tubesync/sync/management/commands/reset-metadata.py new file mode 100644 index 0000000..be344e1 --- /dev/null +++ b/tubesync/sync/management/commands/reset-metadata.py @@ -0,0 +1,19 @@ +from django.core.management.base import BaseCommand +from sync.models import Media + + +from common.logger import log + + +class Command(BaseCommand): + + help = 'Resets all media item metadata' + + def handle(self, *args, **options): + log.info('Resettings all media metadata...') + # Delete all metadata + Media.objects.update(metadata=None) + # Trigger the save signal on each media item + for item in Media.objects.all(): + item.save() + log.info('Done')