From de762a55331f0559597ee9a8c8b94f48a71fcc0c Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 28 Dec 2024 20:04:31 +0200 Subject: [PATCH] add hook --- get_peertube_videos/get_peertube_videos.py | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/get_peertube_videos/get_peertube_videos.py b/get_peertube_videos/get_peertube_videos.py index ef63975..8990b37 100644 --- a/get_peertube_videos/get_peertube_videos.py +++ b/get_peertube_videos/get_peertube_videos.py @@ -130,7 +130,7 @@ class GetPeertubeVideos: selected['url'], full_file_name ) - result = self.session.get(selected['url']) + result = self.session.get(selected['url'], hooks={'response': self._req_hook}) video_bytes = result.content with open(full_file_name, mode='wb') as video_file: video_file.write(video_bytes) @@ -174,11 +174,26 @@ class GetPeertubeVideos: '-disposition:0', 'attached_pic', f"{video_file}_with_thumb" ], capture_output=True, - check=True + check=False + ) + if result.returncode != 0: + self._log.error( + "Error %s adding thumnail. Output: %s. Errors: %s", + result.returncode, + result.stdout, + result.stderr ) os.remove(video_file) os.rename(f"{video_file}_with_thumb", video_file) + def _req_hook(self, request, *args, **kwargs): + self._log.debug( + "Request hook: %s. Other args: %s. Dictionary args: %s", + request, + args, + kwargs + ) + def _write_downloaded_items(self): with open(self.config['downloaded_database'], 'w', encoding='utf-8') as db_file: for download_item in self.downloaded_items: