Add thumbnail
This commit is contained in:
parent
dce5c15604
commit
45c6c5287e
2 changed files with 42 additions and 0 deletions
|
@ -10,6 +10,7 @@ import os
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
from logging.handlers import SysLogHandler
|
from logging.handlers import SysLogHandler
|
||||||
|
import subprocess
|
||||||
import click
|
import click
|
||||||
import click_config_file
|
import click_config_file
|
||||||
import requests
|
import requests
|
||||||
|
@ -133,11 +134,51 @@ class GetPeertubeVideos:
|
||||||
video_bytes = result.content
|
video_bytes = result.content
|
||||||
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 = ''
|
||||||
|
for thumb in item['media_thumbnail']:
|
||||||
|
if 'preview' in thumb['url']:
|
||||||
|
sel_thumb = thumb
|
||||||
|
if 'url' in sel_thumb:
|
||||||
|
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)
|
||||||
|
self._add_thumbnail_to_video(full_file_name, full_thumb_file_name)
|
||||||
else:
|
else:
|
||||||
self._log.debug(
|
self._log.debug(
|
||||||
"Item already downloaded, skipping."
|
"Item already downloaded, skipping."
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def _add_thumbnail_to_video(self, video_file, thumb_file):
|
||||||
|
self._log.debug(
|
||||||
|
'Looking for ffmpeg tool...'
|
||||||
|
)
|
||||||
|
result = subprocess.run(["which", "ffmpeg"], capture_output=True, check=False)
|
||||||
|
if result.stdout == b'':
|
||||||
|
self._log.error(
|
||||||
|
"Error finding ffmpeg, thumbnail won't be added to video."
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
self._log.debug(
|
||||||
|
"Adding thumbnail '%s' to file '%s'...",
|
||||||
|
thumb_file,
|
||||||
|
video_file
|
||||||
|
)
|
||||||
|
result = subprocess.run(
|
||||||
|
[
|
||||||
|
'ffmpeg',
|
||||||
|
'-i', video_file,
|
||||||
|
'-i', thumb_file,
|
||||||
|
'-map', '1',
|
||||||
|
'-map', '0',
|
||||||
|
'-c', 'copy',
|
||||||
|
'-disposition:0', 'attached_pic', f"{video_file}_with_thumb"
|
||||||
|
],
|
||||||
|
capture_output=True,
|
||||||
|
check=True
|
||||||
|
)
|
||||||
|
os.remove(video_file)
|
||||||
|
os.rename(f"{video_file}_with_thumb", video_file)
|
||||||
|
|
||||||
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:
|
||||||
|
|
|
@ -3,3 +3,4 @@ click_config_file
|
||||||
requests
|
requests
|
||||||
transmission_rpc
|
transmission_rpc
|
||||||
feedparser
|
feedparser
|
||||||
|
ffmpeg
|
||||||
|
|
Loading…
Reference in a new issue