From 7918261c48dd1db2f0ef004ea01b35a39b5b6c68 Mon Sep 17 00:00:00 2001 From: tcely Date: Wed, 11 Jun 2025 12:39:17 -0400 Subject: [PATCH] Create create-tvshow-nfo.py --- .../management/commands/create-tvshow-nfo.py | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 tubesync/sync/management/commands/create-tvshow-nfo.py diff --git a/tubesync/sync/management/commands/create-tvshow-nfo.py b/tubesync/sync/management/commands/create-tvshow-nfo.py new file mode 100644 index 00000000..987f206a --- /dev/null +++ b/tubesync/sync/management/commands/create-tvshow-nfo.py @@ -0,0 +1,48 @@ +from common.logger import log +from django.utils.translation import gettext_lazy as _ +from sync.models import Source +from sync.utils import write_text_file +from django.core.management.base import BaseCommand, CommandError + + +class Command(BaseCommand): + + filename = 'tvshow.nfo' + help = 'Creates a "tvshow.nfo" file for a source during the indexing process' + + def add_arguments(self, parser): + parser.add_argument('id', type=str) + + def handle(self, *args, **options): + key = options['id'] + try: + source = Source.objects.get(key=key) + except Source.DoesNotExist as e: + raise CommandError(_(f'no such source for: {key=}')) from e + else: + if not source.write_nfo: + log.warning( + 'The matching source is not configured to write ".nfo" files.' + f' ({source=})' + ) + return + nfo_path = source.directory_path / self.filename + if nfo_path.exists(): + log.debug( + f'not overwriting the existing path: {nfo_path}' + ) + return + content = f'''\ + + {source.name} + {source.key} + +''' + log.debug( + f'Writing new content to: {nfo_path}', + ) + write_text_file(nfo_path, content) + log.info( + f'Wrote a new "{self.filename}" file for: {source}', + ) +