File size: 1,524 Bytes
aff0a09
 
 
 
5ac7dcf
aff0a09
 
155198f
aff0a09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5f04dc5
 
 
 
 
aff0a09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
155198f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
from fastapi import UploadFile, File, Form, BackgroundTasks
from fastapi.responses import FileResponse
from fastapi import APIRouter
from generate_minecraft_subtitles import generate_minecraft_subtitles
from endpoints.utils import remove_content_from_dir
import os
import shutil
from endpoints.utils import get_file_name

router = APIRouter()

@router.post("/minecraft")
async def create_minecraft_video(
	video: UploadFile = File(...),
	subtitles: str = Form(...),
	color: str = Form(...),
	size: int = Form(...),
	font: str = Form(...),
	credit: str = Form(...),
	credit_size: int = Form(...),
	background_tasks: BackgroundTasks = BackgroundTasks()
):
	
	background_video_path = "./data/minecraft/videos/background_video.mp4"

	# Create the directory if it doesn't exist
	if not os.path.exists("./data/minecraft/videos"):
		os.makedirs("./data/minecraft/videos")

	# Save the videos
	with open(background_video_path, "wb") as buffer:
		shutil.copyfileobj(video.file, buffer)

	options = {
		"background_video": background_video_path,
		"font_color": color,
		"font_size": size,
		"font_family": font,
		"border_size": 1,
		"credit": credit,
		"credit_size": credit_size,
	}

	result_video_path = generate_minecraft_subtitles(options, subtitles)

	if not os.path.exists(result_video_path):
		return {"message": "Error generating subtitles!"}

	background_tasks.add_task(remove_content_from_dir, "./data/minecraft/videos")

	return FileResponse(result_video_path, media_type="video/mp4", filename=get_file_name("minecraft"))