From 9fd5352f2df541df806103effda764bcec080b15 Mon Sep 17 00:00:00 2001 From: "Antonio J. Delgado" Date: Sat, 28 Dec 2024 20:09:17 +0200 Subject: [PATCH] Save thumb and remove hook --- get_peertube_videos/get_peertube_videos.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/get_peertube_videos/get_peertube_videos.py b/get_peertube_videos/get_peertube_videos.py index 8990b37..1d3391e 100644 --- a/get_peertube_videos/get_peertube_videos.py +++ b/get_peertube_videos/get_peertube_videos.py @@ -130,8 +130,11 @@ class GetPeertubeVideos: selected['url'], full_file_name ) - result = self.session.get(selected['url'], hooks={'response': self._req_hook}) + result = self.session.get(selected['url']) video_bytes = result.content + self._log.debug( + 'Saving video to file...' + ) with open(full_file_name, mode='wb') as video_file: video_file.write(video_bytes) sel_thumb = '' @@ -142,6 +145,13 @@ class GetPeertubeVideos: split_url = sel_thumb['url'].split('.') thumb_file_name = file_name.replace(file_extension, split_url[len(split_url)-1]) full_thumb_file_name = os.path.join(self.config['download_dir'], thumb_file_name) + result = self.session.get(sel_thumb['url']) + thumb_bytes = result.content + self._log.debug( + 'Saving thumbnail to file...' + ) + with open(full_thumb_file_name, mode='wb') as thumb_file: + thumb_file.write(thumb_bytes) self._add_thumbnail_to_video(full_file_name, full_thumb_file_name) else: self._log.debug( @@ -186,14 +196,6 @@ class GetPeertubeVideos: 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: