types and flexible naming
Browse files- App/Editor/Schema.py +6 -1
- App/Worker.py +9 -21
App/Editor/Schema.py
CHANGED
@@ -2,8 +2,13 @@ from typing import List, Optional
|
|
2 |
from pydantic import BaseModel, HttpUrl
|
3 |
|
4 |
|
|
|
|
|
|
|
|
|
|
|
5 |
class EditorRequest(BaseModel):
|
6 |
-
links: Optional[List[
|
7 |
script: str
|
8 |
|
9 |
|
|
|
2 |
from pydantic import BaseModel, HttpUrl
|
3 |
|
4 |
|
5 |
+
class LinkInfo(BaseModel):
|
6 |
+
file_name: str
|
7 |
+
link: HttpUrl
|
8 |
+
|
9 |
+
|
10 |
class EditorRequest(BaseModel):
|
11 |
+
links: Optional[List[LinkInfo]] # List of LinkInfo objects
|
12 |
script: str
|
13 |
|
14 |
|
App/Worker.py
CHANGED
@@ -6,7 +6,7 @@ import time
|
|
6 |
import requests
|
7 |
from App import celery_config, bot
|
8 |
from typing import List
|
9 |
-
from App.Editor.Schema import EditorRequest
|
10 |
from celery.signals import worker_process_init
|
11 |
|
12 |
|
@@ -54,24 +54,12 @@ def install_dependencies(directory: str):
|
|
54 |
|
55 |
|
56 |
@celery.task
|
57 |
-
def download_assets(links: List[
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
content_disposition = response.headers.get("Content-Disposition")
|
64 |
-
if content_disposition and "filename" in content_disposition:
|
65 |
-
_, params = cgi.parse_header(content_disposition)
|
66 |
-
filename = params["filename"]
|
67 |
-
else:
|
68 |
-
# If Content-Disposition is not available, use the last part of the URL as the filename
|
69 |
-
filename = os.path.basename(urlparse(link).path)
|
70 |
-
public_dir = f"{temp_dir}/public"
|
71 |
-
print(public_dir)
|
72 |
-
# Use the extracted filename to save the file
|
73 |
-
|
74 |
-
download_with_wget(link, public_dir, filename)
|
75 |
|
76 |
|
77 |
@celery.task
|
@@ -92,7 +80,7 @@ def cleanup_temp_directory(
|
|
92 |
|
93 |
|
94 |
@celery.task
|
95 |
-
def celery_task(
|
96 |
remotion_app_dir = os.path.join("/srv", "Remotion-app")
|
97 |
project_id = str(uuid.uuid4())
|
98 |
temp_dir = f"/tmp/{project_id}"
|
@@ -101,7 +89,7 @@ def celery_task(links, script=""):
|
|
101 |
chain(
|
102 |
copy_remotion_app.si(remotion_app_dir, temp_dir),
|
103 |
# install_dependencies.si(temp_dir),
|
104 |
-
download_assets.si(links, temp_dir) if links else None,
|
105 |
render_video.si(temp_dir, output_dir),
|
106 |
cleanup_temp_directory.si(temp_dir, output_dir),
|
107 |
).apply_async(
|
|
|
6 |
import requests
|
7 |
from App import celery_config, bot
|
8 |
from typing import List
|
9 |
+
from App.Editor.Schema import EditorRequest, LinkInfo
|
10 |
from celery.signals import worker_process_init
|
11 |
|
12 |
|
|
|
54 |
|
55 |
|
56 |
@celery.task
|
57 |
+
def download_assets(links: List[LinkInfo], temp_dir: str):
|
58 |
+
public_dir = f"{temp_dir}/public"
|
59 |
+
for link in links:
|
60 |
+
file_link = link.link
|
61 |
+
file_name = link.file_name
|
62 |
+
download_with_wget(file_link, public_dir, file_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
63 |
|
64 |
|
65 |
@celery.task
|
|
|
80 |
|
81 |
|
82 |
@celery.task
|
83 |
+
def celery_task(video_task: EditorRequest):
|
84 |
remotion_app_dir = os.path.join("/srv", "Remotion-app")
|
85 |
project_id = str(uuid.uuid4())
|
86 |
temp_dir = f"/tmp/{project_id}"
|
|
|
89 |
chain(
|
90 |
copy_remotion_app.si(remotion_app_dir, temp_dir),
|
91 |
# install_dependencies.si(temp_dir),
|
92 |
+
download_assets.si(video_task.links, temp_dir) if video_task.links else None,
|
93 |
render_video.si(temp_dir, output_dir),
|
94 |
cleanup_temp_directory.si(temp_dir, output_dir),
|
95 |
).apply_async(
|