Write metadata to .info.json when requested

This commit is contained in:
tcely committed 2025-07-21 02:45:23 -04:00
1 parent 18d3077adf
commit 0dc01a8ea1
1 file changed
+8 -3
@@ -12,13 +12,13 @@ class Command(BaseCommand):
def handle(self, *args, **options):
log.info('Syncing missing metadata...')
sources = Source.objects.filter(Q(copy_thumbnails=True) | Q(write_nfo=True))
sources = Source.objects.filter(Q(copy_thumbnails=True) | Q(write_json=True) | Q(write_nfo=True))
for source in sources.order_by('name'):
log.info(f'Finding media for source: {source}')
for item in Media.objects.filter(source=source, downloaded=True):
log.info(f'Checking media for missing metadata: {source} / {item}')
thumbpath = item.thumbpath
if not thumbpath.is_file():
if source.copy_thumbnails and not thumbpath.is_file():
if item.thumb:
log.info(f'Copying missing thumbnail from: {item.thumb.path} '
f'to: {thumbpath}')
@@ -27,7 +27,12 @@ class Command(BaseCommand):
log.error(f'Tried to copy missing thumbnail for {item} but '
f'the thumbnail has not been downloaded')
nfopath = item.nfopath
if not nfopath.is_file():
if source.write_nfo and not nfopath.is_file():
log.info(f'Writing missing NFO file: {nfopath}')
write_text_file(nfopath, item.nfoxml)
jsonpath = item.jsonpath
if source.write_json and item.has_metadata and not jsonpath.is_file():
log.info(f'Writing missing JSON file: {jsonpath}')
write_text_file(jsonpath, item.metadata_dumps())
log.info('Done')