File size: 1,478 Bytes
aff0a09
 
 
 
5ac7dcf
aff0a09
 
155198f
aff0a09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6fa32c7
 
 
 
 
 
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
52
53
from fastapi import UploadFile, File, Form, BackgroundTasks
from fastapi.responses import FileResponse
from fastapi import APIRouter
from generate_basic_subtitles import generate_basic_subtitles
from endpoints.utils import remove_content_from_dir
import os
import shutil
from endpoints.utils import get_file_name

router = APIRouter()

@router.post("/basic")
async def create_basic_video(
	video: UploadFile = File(...),
	color: str = Form(...),
	size: int = Form(...),
	font: str = Form(...),
	credit: str = Form(...),
	credit_size: int = Form(...),
	background_tasks: BackgroundTasks = BackgroundTasks()
):
	# Save the videos
	basic_video_path = "./data/basic/videos/video.mp4"

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

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

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

	result_video_path = generate_basic_subtitles(options)


	if not os.path.exists(result_video_path):
		return {"message": "Error generating subtitles!"}
	
	background_tasks.add_task(remove_content_from_dir, "./data/basic/videos")

	# return the video with the current date and time
	return FileResponse(result_video_path, media_type="video/mp4", filename=get_file_name("basic"))