diff options
author | Alex Merkel <mail@alexmerkel.com> | 2020-12-29 16:03:07 +0100 |
---|---|---|
committer | pukkandan <pukkandan@gmail.com> | 2021-01-09 16:00:49 +0530 |
commit | ab8e5e516f38c3eab8947614e2347a2473e5dbbc (patch) | |
tree | 48040b0af24439d51ea923efcaf9f48f4bfca477 /youtube_dlc/YoutubeDL.py | |
parent | 62d80ba17c5d4f06c324991b076597ec8c5a8c33 (diff) | |
download | hypervideo-pre-ab8e5e516f38c3eab8947614e2347a2473e5dbbc.tar.lz hypervideo-pre-ab8e5e516f38c3eab8947614e2347a2473e5dbbc.tar.xz hypervideo-pre-ab8e5e516f38c3eab8947614e2347a2473e5dbbc.zip |
Add post_hooks option to YoutubeDL.py (https://github.com/ytdl-org/youtube-dl/pull/27573)
Authored by: alexmerkel
Diffstat (limited to 'youtube_dlc/YoutubeDL.py')
-rw-r--r-- | youtube_dlc/YoutubeDL.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/youtube_dlc/YoutubeDL.py b/youtube_dlc/YoutubeDL.py index fbd40cf73..3bae07764 100644 --- a/youtube_dlc/YoutubeDL.py +++ b/youtube_dlc/YoutubeDL.py @@ -252,6 +252,9 @@ class YoutubeDL(object): youtube_dlc/postprocessor/__init__.py for a list. as well as any further keyword arguments for the postprocessor. + post_hooks: A list of functions that get called as the final step + for each video file, after all postprocessors have been + called. The filename will be passed as the only argument. progress_hooks: A list of functions that get called on download progress, with a dictionary with the entries * status: One of "downloading", "error", or "finished". @@ -369,6 +372,7 @@ class YoutubeDL(object): self._ies = [] self._ies_instances = {} self._pps = [] + self._post_hooks = [] self._progress_hooks = [] self._download_retcode = 0 self._num_downloads = 0 @@ -472,6 +476,9 @@ class YoutubeDL(object): pp = pp_class(self, **compat_kwargs(pp_def)) self.add_post_processor(pp) + for ph in self.params.get('post_hooks', []): + self.add_post_hook(ph) + for ph in self.params.get('progress_hooks', []): self.add_progress_hook(ph) @@ -524,6 +531,10 @@ class YoutubeDL(object): self._pps.append(pp) pp.set_downloader(self) + def add_post_hook(self, ph): + """Add the post hook""" + self._post_hooks.append(ph) + def add_progress_hook(self, ph): """Add the progress hook (currently only for the file downloader)""" self._progress_hooks.append(ph) @@ -2199,6 +2210,12 @@ class YoutubeDL(object): except (PostProcessingError) as err: self.report_error('postprocessing: %s' % str(err)) return + try: + for ph in self._post_hooks: + ph(filename) + except Exception as err: + self.report_error('post hooks: %s' % str(err)) + return must_record_download_archive = True if must_record_download_archive or self.params.get('force_write_download_archive', False): |