testing
Browse files- App/Transcription/TranscriptionRoutes.py +25 -2
- App/Worker.py +2 -5
App/Transcription/TranscriptionRoutes.py
CHANGED
|
@@ -2,7 +2,7 @@ from fastapi import APIRouter, status, Form, UploadFile, File, Query, Background
|
|
| 2 |
from typing_extensions import Annotated
|
| 3 |
from .Schemas import UserDetails
|
| 4 |
from App import bot
|
| 5 |
-
import aiofiles, os
|
| 6 |
import tempfile
|
| 7 |
from celery.result import AsyncResult
|
| 8 |
from App.Worker import transcription_task, downloadfile
|
|
@@ -30,10 +30,33 @@ async def download_audio(
|
|
| 30 |
user = await User.objects.filter(id=userId).first()
|
| 31 |
if user == None:
|
| 32 |
return {"code": 400, "message": "doesn't exist", "payload": None}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
ydl_opts = {
|
| 34 |
"format": "bestaudio/best",
|
| 35 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
}
|
|
|
|
| 37 |
task = downloadfile.delay(url, ydl_opts, model)
|
| 38 |
transcription_enrty = await Transcriptions.objects.create(
|
| 39 |
task_id=task.id, user=user
|
|
|
|
| 2 |
from typing_extensions import Annotated
|
| 3 |
from .Schemas import UserDetails
|
| 4 |
from App import bot
|
| 5 |
+
import aiofiles, os, re
|
| 6 |
import tempfile
|
| 7 |
from celery.result import AsyncResult
|
| 8 |
from App.Worker import transcription_task, downloadfile
|
|
|
|
| 30 |
user = await User.objects.filter(id=userId).first()
|
| 31 |
if user == None:
|
| 32 |
return {"code": 400, "message": "doesn't exist", "payload": None}
|
| 33 |
+
|
| 34 |
+
ydl_opts_info = {
|
| 35 |
+
"quiet": True,
|
| 36 |
+
}
|
| 37 |
+
|
| 38 |
+
with youtube_dl.YoutubeDL(ydl_opts_info) as ydl:
|
| 39 |
+
info_dict = ydl.extract_info(url, download=False)
|
| 40 |
+
video_title = info_dict.get("title", None)
|
| 41 |
+
|
| 42 |
+
sanitized_title = re.sub(
|
| 43 |
+
r"(?u)[^-\w.]", "", video_title
|
| 44 |
+
) # Ensure the title is file-friendly
|
| 45 |
+
filename = f"{sanitized_title}.mp3"
|
| 46 |
+
file_path = os.path.join(os.path.expanduser("~"), "Downloads", filename)
|
| 47 |
+
|
| 48 |
ydl_opts = {
|
| 49 |
"format": "bestaudio/best",
|
| 50 |
+
"postprocessors": [
|
| 51 |
+
{
|
| 52 |
+
"key": "FFmpegExtractAudio",
|
| 53 |
+
"preferredcodec": "mp3",
|
| 54 |
+
"preferredquality": "192",
|
| 55 |
+
}
|
| 56 |
+
],
|
| 57 |
+
"outtmpl": file_path,
|
| 58 |
}
|
| 59 |
+
|
| 60 |
task = downloadfile.delay(url, ydl_opts, model)
|
| 61 |
transcription_enrty = await Transcriptions.objects.create(
|
| 62 |
task_id=task.id, user=user
|
App/Worker.py
CHANGED
|
@@ -21,11 +21,8 @@ def downloadfile(self, url, ydl_opts, model_size="tiny"):
|
|
| 21 |
self.update_state(state="Downloading File..", meta={})
|
| 22 |
|
| 23 |
####
|
| 24 |
-
with
|
| 25 |
-
|
| 26 |
-
audio_file = ydl.prepare_filename(info)
|
| 27 |
-
# final_audio_file = f"{audio_file}.mp3"
|
| 28 |
-
# os.rename(final_audio_file, audio_file)
|
| 29 |
|
| 30 |
# updated
|
| 31 |
self.update_state(state="Downloading complete", meta={})
|
|
|
|
| 21 |
self.update_state(state="Downloading File..", meta={})
|
| 22 |
|
| 23 |
####
|
| 24 |
+
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
|
| 25 |
+
ydl.download([url])
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
# updated
|
| 28 |
self.update_state(state="Downloading complete", meta={})
|