Skip to content

Commit 6bbfd37

Browse files
committed
v0.1714 - fallbacks
1 parent 79702ae commit 6bbfd37

File tree

4 files changed

+100
-20
lines changed

4 files changed

+100
-20
lines changed

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,12 @@ If you just need to see the options and help, type:
219219
```
220220

221221
## Changes
222+
- v0.1714 - **More fixes**
223+
- Graceful passing of description fetching errors
224+
=> (`yt-dlp` pushes onward w/ warnings if the description fetch yielded errors)
225+
- Default client behavior changed to suit YouTube better when using `yt-dlp` (Android client in custom arguments as default in `config.ini`)
226+
- Added `[Delays]` section to `config.ini`
227+
=> Set up delays between description and video fetching to avoid snags; user configurable
222228
- v0.1713 - Added customizable `yt-dlp` commands to `config.ini` under `custom_yt_dlp_args`
223229
- Leave the entry blank if you don't want any custom commands to be added.
224230
- Adding custom commands might help with some sites that have i.e. chunking problems during download, or if you need to tweak something, etc.

config/config.ini

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,14 +100,21 @@ completionmessage = Transcription complete. Have a nice day! 😊\n\n<i>P.S. If
100100
cooldown_seconds = 10
101101
max_requests_per_minute = 5
102102

103+
[Delays]
104+
# Wait time in seconds between fetching video description and downloading the file
105+
descriptionfetchdelay = 5
106+
103107
[YTDLPSettings]
104108
# (((=== Custom commands for yt-dlp when downloading video/audio ===)))
105109
# If the entry below is blank, no extra flags are appended to the yt-dlp command.
106110
# (leave blank like so if no extra commands aren't needed)
107111
# (Example below); can help with "chunk side exceeded" errors in some cases, i.e.:
108112
# custom_yt_dlp_args = --http-chunk-size 0
113+
# ~~~ android client ~~~
114+
# custom_yt_dlp_args = --extractor-args "youtube:player_client=android"
115+
# ~~~
109116
# Just leave the entry below blank if you have no idea what you're doing. :-)
110-
custom_yt_dlp_args =
117+
custom_yt_dlp_args = --extractor-args "youtube:player_client=android"
111118
# (((=== Cookies ===)))
112119
# Use your own `cookies.txt` file (true/false)
113120
# this is sometimes required for sites that require login
@@ -116,7 +123,7 @@ custom_yt_dlp_args =
116123
use_cookies_file = false
117124
cookies_file = config/cookies.txt
118125
# use cookies from your browser (to bypass yt-dlp woes)
119-
use_browser_cookies = true
126+
use_browser_cookies = false
120127
# your browser type
121128
browser_type = firefox
122129
# your browser cookies profile location, leave blank to use default location

src/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# openai-whisper transcriber-bot for Telegram
44

55
# version of this program
6-
version_number = "0.1713"
6+
version_number = "0.1714"
77

88
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99
# https://github.com/FlyingFathead/whisper-transcriber-telegram-bot/
@@ -911,7 +911,7 @@ async def ping_owners_on_startup(app: Application):
911911
await app.bot.send_message(
912912
chat_id=owner_id,
913913
text=(
914-
"<b>👋🤖 Whisper Transcriber Bot is now online!</b>\n"
914+
f"<b>👋🤖 Whisper Transcriber Bot (v{version_number}) is now online!</b>\n"
915915
f"\nStart time: {start_time_utc} (UTC)"
916916
f"\nLocal time: {start_time_local}"
917917
),

src/transcription_handler.py

Lines changed: 83 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -600,10 +600,24 @@ async def transcribe_audio(bot, update, audio_path, output_dir, youtube_url, vid
600600
logger.error(f"An error occurred during transcription: {e}")
601601
return {}, ""
602602

603+
# debugger for yt-dlp version
604+
async def debug_yt_dlp_version():
605+
proc = await asyncio.create_subprocess_exec(
606+
"yt-dlp", "--version",
607+
stdout=asyncio.subprocess.PIPE,
608+
stderr=asyncio.subprocess.PIPE
609+
)
610+
out, err = await proc.communicate()
611+
logger.info(f"DEBUG: 'yt-dlp --version' -> {out.decode().strip()}")
603612

604613
# Process the message's URL and keep the user informed
605614
# (Added in the new GPU logging function call to the process_url_message function)
606615
async def process_url_message(message_text, bot, update, model, language):
616+
617+
# fetch delays
618+
config = ConfigLoader.get_config()
619+
desc_fetch_delay = config.getfloat('Delays', 'descriptionfetchdelay', fallback=0.0)
620+
607621
try:
608622
# Get transcription settings
609623
transcription_settings = get_transcription_settings()
@@ -613,6 +627,9 @@ async def process_url_message(message_text, bot, update, model, language):
613627
should_send_detailed_info = notification_settings['send_detailed_info']
614628
send_video_info = notification_settings['send_video_info']
615629

630+
# for yt-dlp version debugging
631+
await debug_yt_dlp_version()
632+
616633
logger.info(f"Transcription settings in process_url_message: {transcription_settings}")
617634

618635
user_id = update.effective_user.id
@@ -645,32 +662,82 @@ async def process_url_message(message_text, bot, update, model, language):
645662
audio_path = os.path.join(audio_dir, audio_file_name)
646663
video_info_message = "Transcription initiated."
647664

648-
# Wrap fetch_video_details in try-except
665+
# get the video details first; graceful passthrough if broken
649666
try:
650667
logger.info("Fetching video details...")
651668
details = await fetch_video_details(normalized_url)
652669
details['video_url'] = normalized_url
653-
video_info_message = create_video_info_message(details)
654-
655-
# Only send if config says so
656-
if send_video_info:
657-
for part in split_message(video_info_message):
658-
await bot.send_message(
659-
chat_id=update.effective_chat.id,
660-
text=f"<code>{part}</code>",
661-
parse_mode='HTML'
662-
)
663670

664671
except Exception as e:
665-
error_message = str(e)
666-
logger.error(f"An error occurred while fetching video details: {error_message}")
667-
# await bot.send_message(chat_id=update.effective_chat.id, text=f"❌ Error: {error_message}")
672+
# WARN instead of abort
673+
logger.warning(f"Could not fetch video details for '{normalized_url}'. Continuing anyway.\nError: {e}")
668674
await bot.send_message(
669675
chat_id=update.effective_chat.id,
670-
text=f"❌ Error: {error_message}",
676+
text="⚠️ WARNING: Could not fetch video description. Continuing with audio download...",
671677
disable_web_page_preview=True
672678
)
673-
continue # Skip to the next URL if any
679+
# Provide a fallback for create_video_info_message()
680+
details = {
681+
'title': '???',
682+
'duration': 0,
683+
'channel': '???',
684+
'upload_date': '?',
685+
'views': '?',
686+
'likes': '?',
687+
'average_rating': '?',
688+
'comment_count': '?',
689+
'channel_id': '?',
690+
'video_id': '?',
691+
'video_url': normalized_url,
692+
'tags': [],
693+
'description': 'No description available',
694+
'audio_duration': 0
695+
}
696+
697+
# Now create a (possibly placeholder) message
698+
video_info_message = create_video_info_message(details)
699+
700+
# Only send if config says so
701+
if send_video_info and video_info_message.strip():
702+
for part in split_message(video_info_message):
703+
await bot.send_message(
704+
chat_id=update.effective_chat.id,
705+
text=f"<code>{part}</code>",
706+
parse_mode='HTML'
707+
)
708+
709+
# # // (old method)
710+
# # Wrap fetch_video_details in try-except
711+
# try:
712+
# logger.info("Fetching video details...")
713+
# details = await fetch_video_details(normalized_url)
714+
# details['video_url'] = normalized_url
715+
# video_info_message = create_video_info_message(details)
716+
717+
# # Only send if config says so
718+
# if send_video_info:
719+
# for part in split_message(video_info_message):
720+
# await bot.send_message(
721+
# chat_id=update.effective_chat.id,
722+
# text=f"<code>{part}</code>",
723+
# parse_mode='HTML'
724+
# )
725+
726+
# except Exception as e:
727+
# error_message = str(e)
728+
# logger.error(f"An error occurred while fetching video details: {error_message}")
729+
# # await bot.send_message(chat_id=update.effective_chat.id, text=f"❌ Error: {error_message}")
730+
# await bot.send_message(
731+
# chat_id=update.effective_chat.id,
732+
# text=f"❌ Error: {error_message}",
733+
# disable_web_page_preview=True
734+
# )
735+
# continue # Skip to the next URL if any
736+
737+
# If we do want to wait after any attempt:
738+
if desc_fetch_delay > 0:
739+
logger.info(f"Waiting {desc_fetch_delay} second(s) after fetching description...")
740+
await asyncio.sleep(desc_fetch_delay)
674741

675742
await bot.send_message(chat_id=update.effective_chat.id, text="📥 Fetching the audio track...")
676743

0 commit comments

Comments
 (0)