Save thumb and remove hook

This commit is contained in:
Antonio J. Delgado 2024-12-28 20:09:17 +02:00
parent de762a5533
commit 9fd5352f2d

View file

@ -130,8 +130,11 @@ class GetPeertubeVideos:
selected['url'], selected['url'],
full_file_name full_file_name
) )
result = self.session.get(selected['url'], hooks={'response': self._req_hook}) result = self.session.get(selected['url'])
video_bytes = result.content video_bytes = result.content
self._log.debug(
'Saving video to file...'
)
with open(full_file_name, mode='wb') as video_file: with open(full_file_name, mode='wb') as video_file:
video_file.write(video_bytes) video_file.write(video_bytes)
sel_thumb = '' sel_thumb = ''
@ -142,6 +145,13 @@ class GetPeertubeVideos:
split_url = sel_thumb['url'].split('.') split_url = sel_thumb['url'].split('.')
thumb_file_name = file_name.replace(file_extension, split_url[len(split_url)-1]) 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) 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) self._add_thumbnail_to_video(full_file_name, full_thumb_file_name)
else: else:
self._log.debug( self._log.debug(
@ -186,14 +196,6 @@ class GetPeertubeVideos:
os.remove(video_file) os.remove(video_file)
os.rename(f"{video_file}_with_thumb", 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): def _write_downloaded_items(self):
with open(self.config['downloaded_database'], 'w', encoding='utf-8') as db_file: with open(self.config['downloaded_database'], 'w', encoding='utf-8') as db_file:
for download_item in self.downloaded_items: for download_item in self.downloaded_items: