fix
Browse files- App/Transcription/TranscriptionRoutes.py +3 -10
- App/Worker.py +6 -3
App/Transcription/TranscriptionRoutes.py
CHANGED
@@ -9,7 +9,7 @@ from App.Worker import transcription_task, downloadfile
|
|
9 |
from App.Users.Model import User
|
10 |
from .Model import Transcriptions
|
11 |
from .Utils.fastapi_tasks import perform_background_task
|
12 |
-
import
|
13 |
|
14 |
# from .Model import User
|
15 |
# from sqlalchemy import and_
|
@@ -36,7 +36,7 @@ async def download_audio(
|
|
36 |
"quiet": True,
|
37 |
}
|
38 |
|
39 |
-
with
|
40 |
info_dict = ydl.extract_info(url, download=False)
|
41 |
video_title = info_dict.get("title", None)
|
42 |
|
@@ -44,17 +44,10 @@ async def download_audio(
|
|
44 |
r"(?u)[^-\w.]", "", video_title
|
45 |
) # Ensure the title is file-friendly
|
46 |
filename = f"{sanitized_title}.mp3"
|
47 |
-
file_path = os.path.join(
|
48 |
|
49 |
ydl_opts = {
|
50 |
"format": "bestaudio/best",
|
51 |
-
"postprocessors": [
|
52 |
-
{
|
53 |
-
"key": "FFmpegExtractAudio",
|
54 |
-
"preferredcodec": "mp3",
|
55 |
-
"preferredquality": "192",
|
56 |
-
}
|
57 |
-
],
|
58 |
"outtmpl": file_path,
|
59 |
}
|
60 |
|
|
|
9 |
from App.Users.Model import User
|
10 |
from .Model import Transcriptions
|
11 |
from .Utils.fastapi_tasks import perform_background_task
|
12 |
+
import yt_dlp
|
13 |
|
14 |
# from .Model import User
|
15 |
# from sqlalchemy import and_
|
|
|
36 |
"quiet": True,
|
37 |
}
|
38 |
|
39 |
+
with yt_dlp.YoutubeDL(ydl_opts_info) as ydl:
|
40 |
info_dict = ydl.extract_info(url, download=False)
|
41 |
video_title = info_dict.get("title", None)
|
42 |
|
|
|
44 |
r"(?u)[^-\w.]", "", video_title
|
45 |
) # Ensure the title is file-friendly
|
46 |
filename = f"{sanitized_title}.mp3"
|
47 |
+
file_path = os.path.join("./", "Downloads", filename)
|
48 |
|
49 |
ydl_opts = {
|
50 |
"format": "bestaudio/best",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
51 |
"outtmpl": file_path,
|
52 |
}
|
53 |
|
App/Worker.py
CHANGED
@@ -21,10 +21,13 @@ def downloadfile(self, url, ydl_opts, model_size="tiny"):
|
|
21 |
self.update_state(state="Downloading File..", meta={})
|
22 |
|
23 |
####
|
24 |
-
with
|
25 |
ydl.download([url])
|
26 |
|
27 |
# updated
|
28 |
self.update_state(state="Downloading complete", meta={})
|
29 |
-
|
30 |
-
|
|
|
|
|
|
|
|
21 |
self.update_state(state="Downloading File..", meta={})
|
22 |
|
23 |
####
|
24 |
+
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
25 |
ydl.download([url])
|
26 |
|
27 |
# updated
|
28 |
self.update_state(state="Downloading complete", meta={})
|
29 |
+
audio_file = ydl_opts["outtmpl"]
|
30 |
+
print(audio_file["default"])
|
31 |
+
return transcribe_file(
|
32 |
+
state=self, file_path=audio_file["default"], model_size=model_size
|
33 |
+
)
|