|
@@ -1,23 +1,30 @@
|
|
|
from raven import Client
|
|
|
-import os
|
|
|
+import os, subprocess
|
|
|
from app.core.celery_app import celery_app
|
|
|
from app.core.config import settings
|
|
|
import requests
|
|
|
from pathlib import Path
|
|
|
from urllib.parse import urlparse, urljoin
|
|
|
-import os
|
|
|
+from .aianchor import make_video_from_zip
|
|
|
#client_sentry = Client(settings.SENTRY_DSN)
|
|
|
-
|
|
|
+import dataset
|
|
|
+from app.db.session import SessionLocal
|
|
|
+from app.models import video
|
|
|
+from app import crud
|
|
|
download_to_local_url = urljoin(settings.SERVER_HOST, settings.API_V1_STR+"/videos/worker")
|
|
|
upload_to_server_url = urljoin(settings.SERVER_HOST, settings.API_V1_STR+"/videos/worker")
|
|
|
|
|
|
-ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE)
|
|
|
-VIDEO_STORAGE = Path("/").joinpath(settings.CELERY_VIDEO_STORAGE)
|
|
|
-
|
|
|
+LOCAL_ZIP_STORAGE = Path("/").joinpath(settings.LOCAL_ZIP_STORAGE)
|
|
|
+CELERY_ZIP_STORAGE = Path("/").joinpath(settings.CELERY_ZIP_STORAGE)
|
|
|
+CELERY_VIDEO_STORAGE = Path("/").joinpath(settings.LOCAL_VIDEO_STORAGE)
|
|
|
+LOCAL_VIDEO_STORAGE = Path("/").joinpath(settings.LOCAL_VIDEO_STORAGE)
|
|
|
|
|
|
+STORAGE_IP = '192.168.192.252'#os.getenv('STORAGE_IP')
|
|
|
+if not STORAGE_IP:
|
|
|
+ raise Exception
|
|
|
|
|
|
@celery_app.task(acks_late=True)
|
|
|
-def make_video(video_id, zip_filename, user_id) -> str:
|
|
|
+def make_video(video_id, filename, user_id) -> str:
|
|
|
#video_id, zip_filename, user_id = args
|
|
|
# download
|
|
|
'''
|
|
@@ -27,13 +34,40 @@ def make_video(video_id, zip_filename, user_id) -> str:
|
|
|
for chunk in r.iter_content(chunk_size=1024):
|
|
|
f.write(chunk)
|
|
|
'''
|
|
|
- zip_filename = zip_filename + ".zip"
|
|
|
- print(str(ZIP_STORAGE/zip_filename))
|
|
|
- print((ZIP_STORAGE/zip_filename).exists())
|
|
|
+ db = SessionLocal()
|
|
|
+ db.execute("SELECT 1")
|
|
|
+ zip_filename = filename + ".zip"
|
|
|
+ r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
|
+ "scp", "-o", "StrictHostKeyChecking=no", f"root@{STORAGE_IP}:{str(LOCAL_ZIP_STORAGE/zip_filename)}", f"{str(CELERY_ZIP_STORAGE/zip_filename)}"])
|
|
|
+ print(f'get from local storage: {r.returncode}')
|
|
|
+ print(f"video_id: {video_id}, file name: {filename}")
|
|
|
+ db.execute(f"UPDATE video SET progress_state='processing' where id={video_id}")
|
|
|
+ db.commit()
|
|
|
# make video
|
|
|
+ try:
|
|
|
+ make_video_from_zip(working_dir=CELERY_ZIP_STORAGE,style=Path("app/style/choozmo"), inputfile=zip_filename,opening=False, ending=False)
|
|
|
+ except Exception as e:
|
|
|
+ print(f"error:{e}")
|
|
|
+ db.execute(f"UPDATE video SET progress_state='failed' where id={video_id}")
|
|
|
+ db.commit()
|
|
|
+ else:
|
|
|
+ #
|
|
|
+ video_filename = filename + ".mp4"
|
|
|
+ r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
|
+ "scp", "-o", "StrictHostKeyChecking=no", f"{str(CELERY_ZIP_STORAGE/'output.mp4')}", f"root@{STORAGE_IP}:{'/var/www/videos/'+video_filename}"])
|
|
|
+ print(f"return to local storage: {r.returncode}")
|
|
|
+ print(f"video_id: {video_id}, file name: {filename}")
|
|
|
|
|
|
+ db.execute(f"UPDATE video SET progress_state='completed' where id={video_id}")
|
|
|
+ db.commit()
|
|
|
|
|
|
-
|
|
|
- return "complete"
|
|
|
+
|
|
|
+ return "complete"
|
|
|
|
|
|
+@celery_app.task(acks_late=True)
|
|
|
+def super_resolution(filenames):
|
|
|
+ source = [f"root@{STORAGE_IP}:{str(LOCAL_ZIP_STORAGE/filename)}" for filename in filenames]
|
|
|
+ r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
|
+ "scp", "-o", "StrictHostKeyChecking=no", f"root@{STORAGE_IP}:{str(LOCAL_ZIP_STORAGE/zip_filename)}", f"{str(CELERY_ZIP_STORAGE/zip_filename)}"])
|
|
|
+
|
|
|
|