From 4d7e9133e0973fa190f71a997226971c9634963c Mon Sep 17 00:00:00 2001 From: Thibault Nocchi <1619359+ThibaultNocchi@users.noreply.github.com> Date: Tue, 1 Feb 2022 20:26:57 +0100 Subject: [PATCH] add possibilty to use yt dlp write_info_json flag --- .../migrations/0011_auto_20220201_1654.py | 21 +++++++++++++++++++ tubesync/sync/models.py | 17 ++++++++++++++- tubesync/sync/templates/sync/source.html | 4 ++++ tubesync/sync/views.py | 6 ++++-- tubesync/sync/youtube.py | 3 ++- 5 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 tubesync/sync/migrations/0011_auto_20220201_1654.py diff --git a/tubesync/sync/migrations/0011_auto_20220201_1654.py b/tubesync/sync/migrations/0011_auto_20220201_1654.py new file mode 100644 index 0000000..96d9f4a --- /dev/null +++ b/tubesync/sync/migrations/0011_auto_20220201_1654.py @@ -0,0 +1,21 @@ +# Generated by Django 3.2.11 on 2022-02-01 16:54 + +import django.core.files.storage +from django.db import migrations, models +import sync.models + + +class Migration(migrations.Migration): + + dependencies = [ + ('sync', '0010_auto_20210924_0554'), + ] + + operations = [ + migrations.AddField( + model_name='source', + name='write_json', + field=models.BooleanField( + default=False, help_text='Write a JSON file with the media info, these may be detected and used by some media servers', verbose_name='write json'), + ), + ] diff --git a/tubesync/sync/models.py b/tubesync/sync/models.py index 4c99f71..3ac58a4 100644 --- a/tubesync/sync/models.py +++ b/tubesync/sync/models.py @@ -298,6 +298,11 @@ class Source(models.Model): default=False, help_text=_('Write an NFO file in XML with the media info, these may be detected and used by some media servers') ) + write_json = models.BooleanField( + _('write json'), + default=False, + help_text=_('Write a JSON file with the media info, these may be detected and used by some media servers') + ) has_failed = models.BooleanField( _('has failed'), default=False, @@ -1072,6 +1077,16 @@ class Media(models.Model): def nfopath(self): return self.source.directory_path / self.nfoname + @property + def jsonname(self): + filename = os.path.basename(self.media_file.path) + prefix, ext = os.path.splitext(filename) + return f'{prefix}.info.json' + + @property + def jsonpath(self): + return self.source.directory_path / self.jsonname + @property def directory_path(self): # Otherwise, create a suitable filename from the source media_format @@ -1220,7 +1235,7 @@ class Media(models.Model): f'no valid format available') # Download the media with youtube-dl download_youtube_media(self.url, format_str, self.source.extension, - str(self.filepath)) + str(self.filepath), self.source.write_json) # Return the download paramaters return format_str, self.source.extension diff --git a/tubesync/sync/templates/sync/source.html b/tubesync/sync/templates/sync/source.html index f8b1e39..1668e3b 100644 --- a/tubesync/sync/templates/sync/source.html +++ b/tubesync/sync/templates/sync/source.html @@ -111,6 +111,10 @@