Skip to content

Commit

Permalink
v0.07.5 - yt-dlp logging w/ interval
Browse files Browse the repository at this point in the history
  • Loading branch information
FlyingFathead committed Apr 1, 2024
1 parent 8b415d5 commit 100bbe8
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 10 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ After launching the bot, you can interact with it via Telegram:

## Changes

- v0.07.4 - fixes for non-youtube url's
- v0.07.5 - 10-second interval update for `yt-dlp` logging
- v0.07.4 - fixes for non-youtube urls
- v0.07.2 - job queues fine-tuned to be more informative
- v0.07.1 - job queues introduced
- v0.07 - transcript queuing, more precise transcript time estimates
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# openai-whisper transcriber-bot for Telegram

# version of this program
version_number = "0.07.4"
version_number = "0.07.5"

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# https://github.com/FlyingFathead/whisper-transcriber-telegram-bot/
Expand Down
37 changes: 29 additions & 8 deletions src/transcription_handler.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# transcription_handler.py
# ~~~
# openai-whisper transcriber-bot for Telegram
# v0.07.4
# v0.07.5
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# https://github.com/FlyingFathead/whisper-transcriber-telegram-bot/
# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -117,25 +117,46 @@ async def download_audio(url, output_path):
command = [
"yt-dlp",
"--extract-audio",
# "--quiet", # Add quiet flags to suppress output
"--audio-format", "mp3",
"--cache-dir", cache_dir, # Specify the custom cache directory
url,
"-o", output_path
]

# Start the subprocess and capture stdout and stderr
# Start the subprocess
process = await asyncio.create_subprocess_exec(*command, stdout=asyncio.subprocess.PIPE, stderr=asyncio.subprocess.PIPE)

# Communicate with the process to retrieve its output and error message
stdout, stderr = await process.communicate()
# Initialize an empty buffer and set the initial time marker
output_buffer = ''
last_log_time = time.time()
log_interval = 10 # seconds

while True:
chunk = await process.stdout.read(1)
if not chunk: # Break if no more output
break

output_buffer += chunk.decode()

# Log at regular time intervals, regardless of the content
current_time = time.time()
if current_time - last_log_time >= log_interval:
if output_buffer.strip():
logger.info(output_buffer.strip())
output_buffer = '' # Reset the buffer
last_log_time = current_time

# After the loop, ensure to log any remaining output
if output_buffer.strip():
logger.info(output_buffer.strip())

# Log the stdout and stderr
if stdout:
logger.info(f"yt-dlp stdout: {stdout.decode().strip()}")
# Check for any error output
stderr = await process.stderr.read()
if stderr:
logger.error(f"yt-dlp stderr: {stderr.decode().strip()}")

# Check if the file was downloaded successfully
# Verify the download success
if os.path.exists(output_path):
logger.info(f"Audio downloaded successfully: {output_path}")
else:
Expand Down

0 comments on commit 100bbe8

Please sign in to comment.