mirror of
https://github.com/meeb/tubesync.git
synced 2025-06-24 22:16:37 +00:00
Use yt_dlp.get_postprocessors()
This commit is contained in:
parent
3130ff2816
commit
d160a043e5
@ -5,10 +5,13 @@
|
|||||||
|
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
|
||||||
from django.conf import settings
|
from collections import namedtuple
|
||||||
from copy import copy
|
|
||||||
from common.logger import log
|
from common.logger import log
|
||||||
|
from copy import copy, deepcopy
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
import yt_dlp
|
import yt_dlp
|
||||||
|
|
||||||
|
|
||||||
@ -207,6 +210,21 @@ def download_media(url, media_format, extension, output_file, info_json,
|
|||||||
log.warn(f'[youtube-dl] unknown event: {str(event)}')
|
log.warn(f'[youtube-dl] unknown event: {str(event)}')
|
||||||
|
|
||||||
hook.download_progress = 0
|
hook.download_progress = 0
|
||||||
|
|
||||||
|
default_opts = yt_dlp.parse_options([]).options
|
||||||
|
pp_opts = deepcopy(default_opts.__dict__)
|
||||||
|
pp_opts.update({
|
||||||
|
'embedthumbnail': embed_thumbnail,
|
||||||
|
'addmetadata': embed_metadata,
|
||||||
|
'addchapters': True,
|
||||||
|
'embed_infojson': False,
|
||||||
|
'force_keyframes_at_cuts': True,
|
||||||
|
})
|
||||||
|
|
||||||
|
if skip_sponsors:
|
||||||
|
pp_opts['sponsorblock_mark'].update('all,-chapter'.split(','))
|
||||||
|
pp_opts['sponsorblock_remove'].update(sponsor_categories or {})
|
||||||
|
|
||||||
ytopts = {
|
ytopts = {
|
||||||
'format': media_format,
|
'format': media_format,
|
||||||
'merge_output_format': extension,
|
'merge_output_format': extension,
|
||||||
@ -221,27 +239,22 @@ def download_media(url, media_format, extension, output_file, info_json,
|
|||||||
'writeautomaticsub': auto_subtitles,
|
'writeautomaticsub': auto_subtitles,
|
||||||
'subtitleslangs': sub_langs.split(','),
|
'subtitleslangs': sub_langs.split(','),
|
||||||
}
|
}
|
||||||
if not sponsor_categories:
|
|
||||||
sponsor_categories = []
|
|
||||||
sbopt = {
|
|
||||||
'key': 'SponsorBlock',
|
|
||||||
'categories': sponsor_categories
|
|
||||||
}
|
|
||||||
ffmdopt = {
|
|
||||||
'key': 'FFmpegMetadata',
|
|
||||||
'add_chapters': embed_metadata,
|
|
||||||
'add_metadata': embed_metadata
|
|
||||||
}
|
|
||||||
opts = get_yt_opts()
|
opts = get_yt_opts()
|
||||||
ytopts['paths'] = opts.get('paths', {})
|
ytopts['paths'] = opts.get('paths', {})
|
||||||
ytopts['paths'].update({
|
ytopts['paths'].update({
|
||||||
'home': os.path.dirname(output_file),
|
'home': os.path.dirname(output_file),
|
||||||
})
|
})
|
||||||
if embed_thumbnail:
|
|
||||||
ytopts['postprocessors'].append({'key': 'EmbedThumbnail'})
|
# clean-up incompatible keys
|
||||||
if skip_sponsors:
|
pp_opts = {k: v for k, v in pp_opts.items() if not k.startswith('_')}
|
||||||
ytopts['postprocessors'].append(sbopt)
|
|
||||||
ytopts['postprocessors'].append(ffmdopt)
|
# convert dict to namedtuple
|
||||||
|
yt_dlp_opts = namedtuple('yt_dlp_opts', pp_opts)
|
||||||
|
pp_opts = yt_dlp_opts(**pp_opts)
|
||||||
|
|
||||||
|
# create the post processors list
|
||||||
|
ytopts['postprocessors'] = list(yt_dlp.get_postprocessors(pp_opts))
|
||||||
|
|
||||||
opts.update(ytopts)
|
opts.update(ytopts)
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL(opts) as y:
|
with yt_dlp.YoutubeDL(opts) as y:
|
||||||
|
Loading…
Reference in New Issue
Block a user