update
This commit is contained in:
27
backend/services/download_service.py
Normal file
27
backend/services/download_service.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import subprocess
|
||||
|
||||
from database import SessionLocal
|
||||
from services.video_service import get_video, update_file_path
|
||||
|
||||
VIDEOS_DIR = "/videos"
|
||||
|
||||
|
||||
def download_video(video_id: int, youtube_url: str):
|
||||
output_path = f"{VIDEOS_DIR}/{video_id}.mp4"
|
||||
|
||||
subprocess.run(
|
||||
[
|
||||
"yt-dlp",
|
||||
"-f", "bestvideo[ext=mp4]+bestaudio[ext=m4a]/best[ext=mp4]",
|
||||
"-o", output_path,
|
||||
"--merge-output-format", "mp4",
|
||||
youtube_url,
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
update_file_path(db, video_id, output_path)
|
||||
finally:
|
||||
db.close()
|
||||
Reference in New Issue
Block a user