import time from subprocess import Popen,PIPE from rq import get_current_job import os.path def long_job(arg): for i in range(20): time.sleep(1) job = get_current_job() job.meta['progress'] = i job.save() #push to db, return id if ok. return error if not ok return "37" def upload_video(title,thumb_path,video_path): import youtube_upload.main j=get_current_job() return youtube_upload.main.main(title,thumb_path,video_path,job=j) def cut_video(in_fname,start_time,end_time,out_fname): if not os.path.isfile(in_fname): return { "status":"error", "error": "El archivo %s no existe" % in_fname } if os.path.isfile(out_fname): return { "status":"error", "error": "El archivo %s existe" % out_fname } process = [ 'ffmpeg', '-loglevel', 'error', '-stats', '-i', in_fname, '-ss', start_time, '-t', end_time, '-c', 'copy', '-movflags', '+faststart', out_fname ] out = run_process(process) if out == "": out = { "status": "Proceso finalizado" } return out def run_process(process = None): if process is None or type(process) is not list: return { "status": "error", "error": "Argumento process invalido" } proc=Popen(process, stderr=PIPE, universal_newlines=True) while True: line = proc.stderr.readline() if line != '' and line !=b'': job = get_current_job() job.meta['progress'] = line.rstrip() job.save() else: break