MCPcopy
hub / github.com/chidiwilliams/buzz / run

Method run

buzz/transcriber/file_transcriber.py:39–167  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

37
38 @pyqtSlot()
39 def run(self):
40 if self.transcription_task.source == FileTranscriptionTask.Source.URL_IMPORT:
41 cookiefile = os.getenv("BUZZ_DOWNLOAD_COOKIEFILE")
42
43 # First extract info to get the video title
44 extract_options = {
45 "logger": logging.getLogger(),
46 }
47 if cookiefile:
48 extract_options["cookiefile"] = cookiefile
49
50 try:
51 with YoutubeDL(extract_options) as ydl_info:
52 info = ydl_info.extract_info(self.transcription_task.url, download=False)
53 video_title = info.get("title", "audio")
54 except Exception as exc:
55 logging.debug(f"Error extracting video info: {exc}")
56 video_title = "audio"
57
58 # Sanitize title for use as filename
59 video_title = YoutubeDL.sanitize_info({"title": video_title})["title"]
60 # Remove characters that are problematic in filenames
61 for char in ['/', '\\', ':', '*', '?', '"', '<', '>', '|']:
62 video_title = video_title.replace(char, '_')
63
64 # Create temp directory and use video title as filename
65 temp_dir = tempfile.mkdtemp()
66 temp_output_path = os.path.join(temp_dir, video_title)
67 wav_file = temp_output_path + ".wav"
68 wav_file = str(Path(wav_file).resolve())
69
70 options = {
71 "format": "bestaudio/best",
72 "progress_hooks": [self.on_download_progress],
73 "outtmpl": temp_output_path,
74 "logger": logging.getLogger(),
75 }
76
77 if cookiefile:
78 options["cookiefile"] = cookiefile
79
80 ydl = YoutubeDL(options)
81
82 try:
83 logging.debug(f"Downloading audio file from URL: {self.transcription_task.url}")
84 ydl.download([self.transcription_task.url])
85 except Exception as exc:
86 logging.debug(f"Error downloading audio: {exc.msg}")
87 self.error.emit(exc.msg)
88 return
89
90 cmd = [
91 "ffmpeg",
92 "-nostdin",
93 "-threads", "0",
94 "-i", temp_output_path,
95 "-ac", "1",
96 "-ar", str(whisper_audio.SAMPLE_RATE),

Callers 2

transcribeMethod · 0.45
transcribeMethod · 0.45

Calls 4

transcribeMethod · 0.95
get_output_file_pathFunction · 0.90
write_outputFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected