mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-17 10:36:35 +00:00
Create create-tvshow-nfo.py
This commit is contained in:
parent
8a89956727
commit
7918261c48
48
tubesync/sync/management/commands/create-tvshow-nfo.py
Normal file
48
tubesync/sync/management/commands/create-tvshow-nfo.py
Normal file
@ -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'''\
|
||||
<tvshow>
|
||||
<title>{source.name}</title>
|
||||
<uniqueid type="Youtube" default="true">{source.key}</uniqueid>
|
||||
</tvshow>
|
||||
'''
|
||||
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}',
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user