]>
jfr.im git - yt-dlp.git/blob - yt_dlp/postprocessor/sponskrub.py
5 from .common
import PostProcessor
19 # Deprecated in favor of the native implementation
20 class SponSkrubPP(PostProcessor
):
22 _exe_name
= 'sponskrub'
24 def __init__(self
, downloader
, path
='', args
=None, ignoreerror
=False, cut
=False, force
=False, _from_cli
=False):
25 PostProcessor
.__init
__(self
, downloader
)
28 self
.args
= str_or_none(args
) or '' # For backward compatibility
29 self
.path
= self
.get_exe(path
)
32 self
.deprecation_warning(
33 'yt_dlp.postprocessor.SponSkrubPP support is deprecated and may be removed in a future version. '
34 'Use yt_dlp.postprocessor.SponsorBlock and yt_dlp.postprocessor.ModifyChaptersPP instead')
36 if not ignoreerror
and self
.path
is None:
38 raise PostProcessingError('sponskrub not found in "%s"' % path
)
40 raise PostProcessingError('sponskrub not found. Please install or provide the path using --sponskrub-path')
42 def get_exe(self
, path
=''):
43 if not path
or not check_executable(path
, ['-h']):
44 path
= os
.path
.join(path
, self
._exe
_name
)
45 if not check_executable(path
, ['-h']):
49 @PostProcessor._restrict_to(images
=False)
50 def run(self
, information
):
52 return [], information
54 filename
= information
['filepath']
55 if not os
.path
.exists(encodeFilename(filename
)): # no download
56 return [], information
58 if information
['extractor_key'].lower() != 'youtube':
59 self
.to_screen('Skipping sponskrub since it is not a YouTube video')
60 return [], information
61 if self
.cutout
and not self
.force
and not information
.get('__real_download', False):
63 'Skipping sponskrub since the video was already downloaded. '
64 'Use --sponskrub-force to run sponskrub anyway')
65 return [], information
67 self
.to_screen('Trying to %s sponsor sections' % ('remove' if self
.cutout
else 'mark'))
69 self
.report_warning('Cutting out sponsor segments will cause the subtitles to go out of sync.')
70 if not information
.get('__real_download', False):
71 self
.report_warning('If sponskrub is run multiple times, unintended parts of the video could be cut out.')
73 temp_filename
= prepend_extension(filename
, self
._temp
_ext
)
74 if os
.path
.exists(encodeFilename(temp_filename
)):
75 os
.remove(encodeFilename(temp_filename
))
80 cmd
+= cli_option(self
._downloader
.params
, '-proxy', 'proxy')
81 cmd
+= shlex
.split(self
.args
) # For backward compatibility
82 cmd
+= self
._configuration
_args
(self
._exe
_name
, use_compat
=False)
83 cmd
+= ['--', information
['id'], filename
, temp_filename
]
84 cmd
= [encodeArgument(i
) for i
in cmd
]
86 self
.write_debug('sponskrub command line: %s' % shell_quote(cmd
))
87 pipe
= None if self
.get_param('verbose') else subprocess
.PIPE
88 p
= Popen(cmd
, stdout
=pipe
)
89 stdout
= p
.communicate_or_kill()[0]
92 os
.replace(temp_filename
, filename
)
93 self
.to_screen('Sponsor sections have been %s' % ('removed' if self
.cutout
else 'marked'))
94 elif p
.returncode
== 3:
95 self
.to_screen('No segments in the SponsorBlock database')
97 msg
= stdout
.decode('utf-8', 'replace').strip() if stdout
else ''
98 msg
= msg
.split('\n')[0 if msg
.lower().startswith('unrecognised') else -1]
99 raise PostProcessingError(msg
if msg
else 'sponskrub failed with error code %s' % p
.returncode
)
100 return [], information