Fix rare yt-dlp glitch

This commit is contained in:
Taras Terletsky 2024-05-09 00:06:47 +03:00
parent 14b668cf6d
commit b6cdf76219
4 changed files with 13 additions and 3 deletions

View file

@ -14,3 +14,5 @@
LICENSE LICENSE
README.md README.md
pyproject.toml pyproject.toml
rsync_exclude.txt
rsync.sh

2
.gitignore vendored
View file

@ -1,5 +1,7 @@
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files
rsync.sh
rsync_exclude.txt
*tmp* *tmp*
*.session *.session
*.session-journal *.session-journal

View file

@ -210,7 +210,7 @@ class AudioUploadTask(AbstractUploadTask):
) )
def _cache_data(self, message: Message) -> None: def _cache_data(self, message: Message) -> None:
self._log.info('Saving telegram file cache') self._log.info('Saving Telegram file cache')
audio = message.audio audio = message.audio
if not audio: if not audio:
err_msg = 'Telegram message response does not contain audio' err_msg = 'Telegram message response does not contain audio'
@ -291,7 +291,7 @@ class VideoUploadTask(AbstractUploadTask):
return self._bot.send_video(**kwargs) return self._bot.send_video(**kwargs)
def _cache_data(self, message: Message) -> None: def _cache_data(self, message: Message) -> None:
self._log.info('Saving telegram file cache') self._log.info('Saving Telegram file cache')
video = message.video or message.animation video = message.video or message.animation
if not video: if not video:
err_msg = 'Telegram message response does not contain video or animation' err_msg = 'Telegram message response does not contain video or animation'

View file

@ -247,6 +247,10 @@ class MediaDownloader:
def _get_requested_video(self, requested_downloads: list[dict]) -> dict | None: def _get_requested_video(self, requested_downloads: list[dict]) -> dict | None:
for download_obj in requested_downloads: for download_obj in requested_downloads:
if download_obj['ext'] != FINAL_AUDIO_FORMAT: if download_obj['ext'] != FINAL_AUDIO_FORMAT:
# Attempt to handle yt-dlp glitch.
download_obj['filepath'] = download_obj.get(
'filepath', download_obj.get('filename', download_obj['_filename'])
)
return download_obj return download_obj
# When video was converted to audio but video kept. # When video was converted to audio but video kept.
@ -258,7 +262,9 @@ class MediaDownloader:
download_obj['filepath'], download_obj['filepath'],
download_obj['_filename'], download_obj['_filename'],
) )
download_obj['filepath'] = download_obj['_filename'] download_obj['filepath'] = download_obj.get(
'filename', download_obj['_filename']
)
return download_obj return download_obj
return None return None