Skip to content

Commit

Permalink
Merge pull request #371 from jhj0517/fix/tests
Browse files Browse the repository at this point in the history
Update pytube bot detection exception
  • Loading branch information
jhj0517 authored Nov 1, 2024
2 parents 1a63918 + 85f37ae commit 71e7964
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 9 deletions.
19 changes: 19 additions & 0 deletions tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
import functools

from modules.utils.paths import *
from modules.utils.youtube_manager import *

import os
import torch
Expand All @@ -13,5 +16,21 @@
TEST_SUBTITLE_VTT_PATH = os.path.join(WEBUI_DIR, "tests", "test_vtt.vtt")


@functools.lru_cache
def is_cuda_available():
return torch.cuda.is_available()


@functools.lru_cache
def is_pytube_detected_bot(url: str = TEST_YOUTUBE_URL):
try:
yt_temp_path = os.path.join("modules", "yt_tmp.wav")
if os.path.exists(yt_temp_path):
return False
yt = get_ytdata(url)
audio = get_ytaudio(yt)
return False
except Exception as e:
print(f"Pytube has detected as a bot: {e}")
return True

19 changes: 10 additions & 9 deletions tests/test_transcription.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ def test_transcribe(
assert isinstance(subtitle_str, str) and subtitle_str
assert isinstance(file_path[0], str) and file_path

whisper_inferencer.transcribe_youtube(
TEST_YOUTUBE_URL,
"SRT",
False,
gr.Progress(),
*hparams,
)
assert isinstance(subtitle_str, str) and subtitle_str
assert isinstance(file_path[0], str) and file_path
if not is_pytube_detected_bot():
whisper_inferencer.transcribe_youtube(
TEST_YOUTUBE_URL,
"SRT",
False,
gr.Progress(),
*hparams,
)
assert isinstance(subtitle_str, str) and subtitle_str
assert isinstance(file_path[0], str) and file_path

whisper_inferencer.transcribe_mic(
audio_path,
Expand Down

0 comments on commit 71e7964

Please sign in to comment.