|
@@ -6,6 +6,7 @@ import requests
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
from urllib.parse import urlparse, urljoin
|
|
from urllib.parse import urlparse, urljoin
|
|
from .aianchor import make_video_from_zip
|
|
from .aianchor import make_video_from_zip
|
|
|
|
+import gc
|
|
#client_sentry = Client(settings.SENTRY_DSN)
|
|
#client_sentry = Client(settings.SENTRY_DSN)
|
|
import dataset
|
|
import dataset
|
|
from app.db.session import SessionLocal
|
|
from app.db.session import SessionLocal
|
|
@@ -20,11 +21,18 @@ CELERY_VIDEO_STORAGE = Path("/").joinpath(settings.LOCAL_VIDEO_STORAGE)
|
|
LOCAL_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')
|
|
STORAGE_IP = '192.168.192.252'#os.getenv('STORAGE_IP')
|
|
|
|
+BACKEND_IP = '172.'
|
|
if not STORAGE_IP:
|
|
if not STORAGE_IP:
|
|
raise Exception
|
|
raise Exception
|
|
|
|
|
|
-@celery_app.task(acks_late=True)
|
|
|
|
-def make_video(video_id, filename, user_id) -> str:
|
|
|
|
|
|
+@celery_app.task(acks_late=True, bind=True, track_started=True)
|
|
|
|
+def make_video_test(self, title=None, anchor_id=None, lang_id=None)->int:
|
|
|
|
+ print(title, anchor_id, lang_id)
|
|
|
|
+ return 0
|
|
|
|
+
|
|
|
|
+@celery_app.task(acks_late=True, bind=True, track_started=True)
|
|
|
|
+def make_video(self, *, video_id, stored_filename=None, user_id=None, anchor_id=None, membership=None, available_time=None, **others) -> int:
|
|
|
|
+
|
|
#video_id, zip_filename, user_id = args
|
|
#video_id, zip_filename, user_id = args
|
|
# download
|
|
# download
|
|
'''
|
|
'''
|
|
@@ -34,40 +42,55 @@ def make_video(video_id, filename, user_id) -> str:
|
|
for chunk in r.iter_content(chunk_size=1024):
|
|
for chunk in r.iter_content(chunk_size=1024):
|
|
f.write(chunk)
|
|
f.write(chunk)
|
|
'''
|
|
'''
|
|
- db = SessionLocal()
|
|
|
|
- db.execute("SELECT 1")
|
|
|
|
- zip_filename = filename + ".zip"
|
|
|
|
|
|
+ # db = SessionLocal()
|
|
|
|
+ # db.execute("SELECT 1")
|
|
|
|
+ zip_filename = stored_filename + ".zip"
|
|
r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
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)}"])
|
|
"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'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()
|
|
|
|
|
|
+ print(f"video_id: {video_id}, file name: {stored_filename}")
|
|
|
|
+
|
|
|
|
+ # db.execute(f"UPDATE video SET progress_state='processing' where id={video_id}")
|
|
|
|
+ # db.commit()
|
|
# make video
|
|
# make video
|
|
|
|
+ watermark_path='medias/logo_watermark.jpg'
|
|
|
|
+ content_time = 0
|
|
try:
|
|
try:
|
|
- make_video_from_zip(working_dir=CELERY_ZIP_STORAGE,style=Path("app/style/choozmo"), inputfile=zip_filename,opening=False, ending=False)
|
|
|
|
|
|
+ if membership=="infinite":
|
|
|
|
+ watermark_path=None
|
|
|
|
+ content_time = make_video_from_zip(working_dir=CELERY_ZIP_STORAGE,style=Path("app/style/choozmo"),
|
|
|
|
+ inputfile=zip_filename,
|
|
|
|
+ opening=False,
|
|
|
|
+ ending=False,
|
|
|
|
+ watermark_path=watermark_path,
|
|
|
|
+ available_time=available_time)
|
|
except Exception as e:
|
|
except Exception as e:
|
|
print(f"error:{e}")
|
|
print(f"error:{e}")
|
|
- db.execute(f"UPDATE video SET progress_state='failed' where id={video_id}")
|
|
|
|
- db.commit()
|
|
|
|
|
|
+ # db.execute(f"UPDATE video SET progress_state='failed' where id={video_id}")
|
|
|
|
+ # db.commit()
|
|
else:
|
|
else:
|
|
#
|
|
#
|
|
- video_filename = filename + ".mp4"
|
|
|
|
|
|
+ video_filename = stored_filename + ".mp4"
|
|
r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
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}"])
|
|
"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"return to local storage: {r.returncode}")
|
|
- print(f"video_id: {video_id}, file name: {filename}")
|
|
|
|
|
|
+ print(f"video_id: {video_id}, file name: {stored_filename}")
|
|
|
|
|
|
- db.execute(f"UPDATE video SET progress_state='completed' where id={video_id}")
|
|
|
|
- db.commit()
|
|
|
|
|
|
+ # db.execute(f"UPDATE video SET progress_state='completed', length={int(content_time)} where id={video_id}")
|
|
|
|
+ # db.commit()
|
|
|
|
|
|
|
|
|
|
- return "complete"
|
|
|
|
|
|
+ gc_num = gc.collect()
|
|
|
|
+ print(f"gc_num: {gc_num}")
|
|
|
|
+ return int(content_time)
|
|
|
|
|
|
-@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)}"])
|
|
|
|
|
|
+@celery_app.task(acks_late=True, bind=True, track_started=True)
|
|
|
|
+def super_resolution(self, dirname, filenames):
|
|
|
|
|
|
-
|
|
|
|
|
|
+ r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
|
|
+ "scp", "-o", "StrictHostKeyChecking=no", "-r", f"root@{STORAGE_IP}:{str(LOCAL_ZIP_STORAGE/dirname)}", f"{str(CELERY_ZIP_STORAGE)}"])
|
|
|
|
+
|
|
|
|
+ r = subprocess.run(["python", "/root/github/GFPGAN/inference_gfpgan.py", "-i", f"{str(CELERY_ZIP_STORAGE/dirname)}", "-o", f"{str(CELERY_ZIP_STORAGE/dirname)}", "-v", "1.4", "-s", "2"])
|
|
|
|
+
|
|
|
|
+ r = subprocess.run(["sshpass", "-p", "choozmo9",
|
|
|
|
+ "scp", "-o", "StrictHostKeyChecking=no", "-r", f"{str(CELERY_ZIP_STORAGE/dirname)}", f"root@{STORAGE_IP}:{str(LOCAL_ZIP_STORAGE)}"])
|