tidy up and pass a serialised list through to youtube.download_media, may help with #362
This commit is contained in:
parent
6853c1fa76
commit
4fdd172b05
|
@ -107,7 +107,6 @@ class Source(models.Model):
|
|||
EXTENSION_MKV = 'mkv'
|
||||
EXTENSIONS = (EXTENSION_M4A, EXTENSION_OGG, EXTENSION_MKV)
|
||||
|
||||
|
||||
# as stolen from: https://wiki.sponsor.ajay.app/w/Types / https://github.com/yt-dlp/yt-dlp/blob/master/yt_dlp/postprocessor/sponsorblock.py
|
||||
SPONSORBLOCK_CATEGORIES_CHOICES = (
|
||||
('sponsor', 'Sponsor'),
|
||||
|
@ -123,13 +122,12 @@ class Source(models.Model):
|
|||
sponsorblock_categories = CommaSepChoiceField(
|
||||
_(''),
|
||||
possible_choices=SPONSORBLOCK_CATEGORIES_CHOICES,
|
||||
all_choice="all",
|
||||
all_choice='all',
|
||||
allow_all=True,
|
||||
all_label="(all options)",
|
||||
default="all",
|
||||
help_text=_("Select the sponsorblocks you want to enforce")
|
||||
all_label='(all options)',
|
||||
default='all',
|
||||
help_text=_('Select the sponsorblocks you want to enforce')
|
||||
)
|
||||
|
||||
embed_metadata = models.BooleanField(
|
||||
_('embed metadata'),
|
||||
default=False,
|
||||
|
@ -140,14 +138,12 @@ class Source(models.Model):
|
|||
default=False,
|
||||
help_text=_('Embed thumbnail into the file')
|
||||
)
|
||||
|
||||
enable_sponsorblock = models.BooleanField(
|
||||
_('enable sponsorblock'),
|
||||
default=True,
|
||||
help_text=_('Use SponsorBlock?')
|
||||
)
|
||||
|
||||
|
||||
# Fontawesome icons used for the source on the front end
|
||||
ICONS = {
|
||||
SOURCE_TYPE_YOUTUBE_CHANNEL: '<i class="fab fa-youtube"></i>',
|
||||
|
@ -1391,7 +1387,7 @@ class Media(models.Model):
|
|||
# Download the media with youtube-dl
|
||||
download_youtube_media(self.url, format_str, self.source.extension,
|
||||
str(self.filepath), self.source.write_json,
|
||||
self.source.sponsorblock_categories, self.source.embed_thumbnail,
|
||||
self.source.sponsorblock_categories.selected_choices, self.source.embed_thumbnail,
|
||||
self.source.embed_metadata, self.source.enable_sponsorblock,
|
||||
self.source.write_subtitles, self.source.auto_subtitles,self.source.sub_langs )
|
||||
# Return the download paramaters
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
'''
|
||||
Wrapper for the youtube-dl library. Used so if there are any library interface
|
||||
Wrapper for the yt-dlp library. Used so if there are any library interface
|
||||
updates we only need to udpate them in one place.
|
||||
'''
|
||||
|
||||
|
@ -65,7 +65,7 @@ def get_media_info(url):
|
|||
|
||||
|
||||
def download_media(url, media_format, extension, output_file, info_json,
|
||||
sponsor_categories="all",
|
||||
sponsor_categories=None,
|
||||
embed_thumbnail=False, embed_metadata=False, skip_sponsors=True,
|
||||
write_subtitles=False, auto_subtitles=False, sub_langs='en'):
|
||||
'''
|
||||
|
@ -106,8 +106,8 @@ def download_media(url, media_format, extension, output_file, info_json,
|
|||
f'{total_size_str} in {elapsed_str}')
|
||||
else:
|
||||
log.warn(f'[youtube-dl] unknown event: {str(event)}')
|
||||
hook.download_progress = 0
|
||||
|
||||
hook.download_progress = 0
|
||||
ytopts = {
|
||||
'format': media_format,
|
||||
'merge_output_format': extension,
|
||||
|
@ -120,7 +120,8 @@ def download_media(url, media_format, extension, output_file, info_json,
|
|||
'writeautomaticsub': auto_subtitles,
|
||||
'subtitleslangs': sub_langs.split(','),
|
||||
}
|
||||
|
||||
if not sponsor_categories:
|
||||
sponsor_categories = []
|
||||
sbopt = {
|
||||
'key': 'SponsorBlock',
|
||||
'categories': [sponsor_categories]
|
||||
|
@ -130,7 +131,6 @@ def download_media(url, media_format, extension, output_file, info_json,
|
|||
'add_chapters': True,
|
||||
'add_metadata': True
|
||||
}
|
||||
|
||||
opts = get_yt_opts()
|
||||
if embed_thumbnail:
|
||||
ytopts['postprocessors'].append({'key': 'EmbedThumbnail'})
|
||||
|
@ -138,9 +138,7 @@ def download_media(url, media_format, extension, output_file, info_json,
|
|||
ffmdopt["add_metadata"] = True
|
||||
if skip_sponsors:
|
||||
ytopts['postprocessors'].append(sbopt)
|
||||
|
||||
ytopts['postprocessors'].append(ffmdopt)
|
||||
|
||||
opts.update(ytopts)
|
||||
|
||||
with yt_dlp.YoutubeDL(opts) as y:
|
||||
|
|
Loading…
Reference in New Issue