def edit_uploadvideo(): """编辑审核状态""" form = VerificationForm().validate_for_api() verification = form.verification try: verification.status = form.status.data verification.admin_id = current_user.id db.session.add(verification) db.session.commit() except Exception as e: print(e) db.session.rollback() uploadvideo = form.uploadvideo if verification.status == 1: # 审核通过 try: # 审核通过,添加到视频表 video = Video() video.user_id = uploadvideo.user_id video.tag_id = uploadvideo.tag_id video.name = uploadvideo.name video.info = uploadvideo.info # 更换视频封面文件位置 file_name = uploadvideo.logo.rsplit("/", 1)[1] src = os.path.join(current_app.config["TMP_DIR"], file_name) if os.path.isfile(src): des = os.path.join(current_app.config["LOGO_DIR"], file_name) shutil.move(src, des) else: return ReturnObj.get_response( ReturnEnum.UPLOAD_VIDEO_LOGO.value, "上传视频封面不存在") video.logo = uploadvideo.logo.replace("tmp", "logo") # 更换视频文件位置 file_name = uploadvideo.url.rsplit("/", 1)[1] src = os.path.join(current_app.config["TMP_DIR"], file_name) if os.path.isfile(src): des = os.path.join(current_app.config["VIDEO_DIR"], file_name) shutil.move(src, des) else: return ReturnObj.get_response( ReturnEnum.UPLOADVIDE0_NOT_EXIST.value, "上传视频不存在") video.url = uploadvideo.url.replace("tmp", "video") video.release_time = datetime.now() db.session.add(video) except Exception as e: print(e) db.session.rollback() write_oplog() return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")
def add_video(): form = VideoAddForm() # 每次刷新列表,动态加载最新的标签 # form.tag_id.choices = [(v.id, v.name) for v in Tag.query.all()] form.validate_for_api() with db.auto_commit(): video = Video() video.name = form.name.data try: file = request.files[form.url.name] if not allowed_video_file(file.filename): return ReturnObj.get_response( ReturnEnum.VIDEO_TYPE_ERROR.value, "只允许上传mp4 avi flv wmv格式") file_url = secure_filename(file.filename) url = change_filename(file_url) file.save(os.path.join(current_app.config["VIDEO_DIR"], url)) try: video_clip = VideoFileClip( os.path.join(current_app.config["VIDEO_DIR"], url)) video.length = video_clip.duration video_clip.reader.close() video_clip.audio.reader.close_proc() except Exception as e: print(e) video.length = None video.url = urljoin(current_app.config["VIDEO_PATH"], url) except Exception as e: return ReturnObj.get_response(ReturnEnum.UPLOAD_VIDEO.value, "请上传视频") try: file = request.files[form.logo.name] if not allowed_image_file(file.filename): return ReturnObj.get_response( ReturnEnum.IMAGE_TYPE_ERROR.value, "只允许上传png jpg jpeg gif格式") file_logo = secure_filename(file.filename) logo = change_filename(file_logo) file.save(os.path.join(current_app.config["LOGO_DIR"], logo)) video.logo = urljoin(current_app.config["LOGO_PATH"], logo) except Exception as e: return ReturnObj.get_response(ReturnEnum.UPLOAD_VIDEO_LOGO.value, "请上传视频封面") # 默认所属用户为pilipili番剧 video.user_id = 6666 video.info = form.info.data # 默认所属标签为连载动画 video.tag_id = 18 db.session.add(video) write_oplog() return ReturnObj.get_response(ReturnEnum.SUCCESS.value, "success")