This commit is contained in:
Marek Lenczewski
2026-04-07 17:55:30 +02:00
parent 8f15f51bce
commit ca988345e9
19 changed files with 201 additions and 203 deletions

View File

@@ -8,28 +8,28 @@ VIDEOS_DIR = "/videos"
MIN_VALID_SIZE = 1024 * 100 # 100 KB
def download_video(video_id: int, youtube_url: str):
output_path = f"{VIDEOS_DIR}/{video_id}.mp4"
def downloadVideo(videoId: int, youtubeUrl: str):
outputPath = f"{VIDEOS_DIR}/{videoId}.mp4"
subprocess.run(
[
"yt-dlp",
"-f", "bestvideo[ext=mp4][vcodec^=avc]+bestaudio[ext=m4a]/best[ext=mp4]",
"-o", output_path,
"-o", outputPath,
"--merge-output-format", "mp4",
"--force-overwrites",
"--no-continue",
youtube_url,
youtubeUrl,
],
check=True,
)
path = Path(output_path)
path = Path(outputPath)
if not path.exists() or path.stat().st_size < MIN_VALID_SIZE:
return
db = SessionLocal()
try:
Video.update_file_path(db, video_id, output_path)
Video.updateFilePath(db, videoId, outputPath)
finally:
db.close()