def merge_video(self, video, *args): tmp_list = video.split('/') tmp_list[-1] = 'merge-' + tmp_list[-1] output = '/'.join(tmp_list) if PathUtil.check_path(output): print(f'{output}已存在') return output print('正在尝试合并视频,请参考控制台输出') FFmpegUtil(CONFIG['FFMPEG_PATH']).merge(video, *args, output=output) return output
def download_video(self, url, filename): final_filename = PathUtil.join_path(CONFIG['DOWNLOAD_PATH'], filename) if PathUtil.check_path(final_filename): print(f'{final_filename} exists, stop downloading') return final_filename print(f'{filename} download start') request = BilibiliApi.build_video_download_request(url) response = RequestUtil.do_request(request, load_json=False) self.before_response(response) self.save_video(response.raw_response, final_filename) return final_filename
def download_video(self, url, filename): if PathUtil.check_path(filename): PathUtil.remove(filename) retry_times = 2 while retry_times > 0: try: request = BilibiliApi.build_video_download_request(url) response = RequestUtil.do_request(request, load_json=False, stream=True) self.before_response(response) self.save_video(response.raw_response, filename) break except: print( f'{filename} download fail, retry times = {retry_times}, restart...' ) retry_times -= 1 if retry_times == 0: raise Exception('retry times exceed, stop downloading...') continue
def merge_video(self, output, *files): if PathUtil.check_path(output): PathUtil.remove(output) return print('正在尝试合并视频,请参考控制台输出') FFmpegUtil(CONFIG['FFMPEG_PATH']).merge(*files, output=output)