1111from pygifsicle import optimize
1212from requests import Response
1313
14- from nc_py_api import NextcloudApp
14+ from nc_py_api import FsNode , NextcloudApp
1515from nc_py_api .ex_app import (
1616 LogLvl ,
17- UiActionFileInfo ,
1817 UiFileActionHandlerInfo ,
1918 nc_app ,
2019 run_app ,
2423APP = FastAPI ()
2524
2625
27- def convert_video_to_gif (input_params : UiActionFileInfo , nc : NextcloudApp ):
28- source_path = path .join (input_params .directory , input_params .name )
29- save_path = path .splitext (source_path )[0 ] + ".gif"
30- nc .log (LogLvl .WARNING , f"Processing:{ source_path } -> { save_path } " )
26+ def convert_video_to_gif (input_file : FsNode , nc : NextcloudApp ):
27+ save_path = path .splitext (input_file .user_path )[0 ] + ".gif"
28+ nc .log (LogLvl .WARNING , f"Processing:{ input_file .user_path } -> { save_path } " )
3129 try :
3230 with tempfile .NamedTemporaryFile (mode = "w+b" ) as tmp_in :
33- nc .files .download2stream (source_path , tmp_in )
31+ nc .files .download2stream (input_file , tmp_in )
3432 nc .log (LogLvl .WARNING , "File downloaded" )
3533 tmp_in .flush ()
3634 cap = cv2 .VideoCapture (tmp_in .name )
@@ -61,7 +59,7 @@ def convert_video_to_gif(input_params: UiActionFileInfo, nc: NextcloudApp):
6159 nc .log (LogLvl .WARNING , "GIF is ready" )
6260 nc .files .upload_stream (save_path , tmp_out )
6361 nc .log (LogLvl .WARNING , "Result uploaded" )
64- nc .users .notifications .create (f"{ input_params .name } finished!" , f"{ save_path } is waiting for you!" )
62+ nc .users .notifications .create (f"{ input_file .name } finished!" , f"{ save_path } is waiting for you!" )
6563 except Exception as e :
6664 nc .log (LogLvl .ERROR , str (e ))
6765 nc .users .notifications .create ("Error occurred" , "Error information was written to log file" )
@@ -73,7 +71,7 @@ async def video_to_gif(
7371 nc : Annotated [NextcloudApp , Depends (nc_app )],
7472 background_tasks : BackgroundTasks ,
7573):
76- background_tasks .add_task (convert_video_to_gif , file .actionFile , nc )
74+ background_tasks .add_task (convert_video_to_gif , file .actionFile . to_fs_node () , nc )
7775 return Response ()
7876
7977
0 commit comments