def download_thread_function(): import plugin while True: try: while True: if LogicQueue.current_ffmpeg_count < int( ModelSetting.get('max_ffmpeg_process_count')): break #logger.debug(LogicQueue.current_ffmpeg_count) time.sleep(5) entity = LogicQueue.download_queue.get() if entity.cancel: continue episode = ModelLinkkf('auto', info=entity.info) db.session.add(episode) db.session.commit() from .logic_linkkf import LogicLinkkf entity.url = LogicLinkkf.get_video_url(entity.info['code']) if entity.url is None: entity.ffmpeg_status_kor = 'URL실패' plugin.socketio_list_refresh() continue import ffmpeg max_pf_count = 0 save_path = ModelSetting.get('download_path') if ModelSetting.get('auto_make_folder') == 'True': program_path = os.path.join(save_path, entity.info['save_folder']) save_path = program_path try: if not os.path.exists(save_path): os.makedirs(save_path) except: logger.debug('program path make fail!!') # 파일 존재여부 체크 if os.path.exists( os.path.join(save_path, entity.info['filename'])): entity.ffmpeg_status_kor = '파일 있음' entity.ffmpeg_percent = 100 plugin.socketio_list_refresh() continue f = ffmpeg.Ffmpeg(entity.url, entity.info['filename'], plugin_id=entity.entity_id, listener=LogicQueue.ffmpeg_listener, max_pf_count=max_pf_count, call_plugin=package_name, save_path=save_path) f.start() LogicQueue.current_ffmpeg_count += 1 LogicQueue.download_queue.task_done() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def program_auto_command(req): try: command = req.form['command'] entity_id = int(req.form['entity_id']) logger.debug('command :%s %s', command, entity_id) entity = WavveProgramEntity.get_entity(entity_id) ret = {} if command == 'cancel': if entity.ffmpeg_status == -1: entity.cancel = True entity.ffmpeg_status_kor = "취소" plugin.socketio_list_refresh() ret['ret'] = 'refresh' elif entity.ffmpeg_status != 5: ret['ret'] = 'notify' ret['log'] = '다운로드중 상태가 아닙니다.' else: idx = entity.ffmpeg_arg['data']['idx'] import ffmpeg ffmpeg.Ffmpeg.stop_by_idx(idx) #plugin.socketio_list_refresh() ret['ret'] = 'refresh' ### edit by lapis ModelWavveProgram.delete(entity.episode_code, entity.quality) ### elif command == 'reset': if LogicProgram.download_queue is not None: with LogicProgram.download_queue.mutex: LogicProgram.download_queue.queue.clear() for _ in WavveProgramEntity.entity_list: if _.ffmpeg_status == 5: import ffmpeg idx = _.ffmpeg_arg['data']['idx'] ffmpeg.Ffmpeg.stop_by_idx(idx) WavveProgramEntity.entity_list = [] plugin.socketio_list_refresh() ret['ret'] = 'refresh' elif command == 'delete_completed': new_list = [] for _ in WavveProgramEntity.entity_list: if _.ffmpeg_status_kor in ['파일 있음', '취소', 'URL실패']: continue if _.ffmpeg_status != 7: new_list.append(_) WavveProgramEntity.entity_list = new_list plugin.socketio_list_refresh() ret['ret'] = 'refresh' except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) ret['ret'] = 'notify' ret['log'] = str(e) return ret
def download_thread_function(): while True: try: while True: if LogicProgram.current_ffmpeg_count < int( ModelSetting.get('program_auto_count_ffmpeg')): break time.sleep(5) entity = LogicProgram.download_queue.get() if entity.cancel: continue # 초기화 if entity is None: return contenttype = 'onairvod' if entity.json_data[ 'type'] == 'onair' else 'vod' count = 0 while True: count += 1 streaming_data = Wavve.streaming( contenttype, entity.episode_code, entity.quality, ModelSetting.get('credential')) try: tmp = data2['playurl'] except: try: from .logic_basic import LogicBasic LogicBasic.login() streaming_data = Wavve.streaming( contenttype, entity.episode_code, entity.quality, ModelSetting.get('credential')) except: pass entity.json_data['filename'] = Wavve.get_filename( entity.json_data, streaming_data['quality']) if streaming_data is not None: break else: time.sleep(20) if count > 10: entity.ffmpeg_status_kor = u'URL실패' break if streaming_data is None: continue import ffmpeg max_pf_count = ModelSetting.get('max_pf_count') save_path = ModelSetting.get('program_auto_path') if ModelSetting.get('program_auto_make_folder') == 'True': program_path = os.path.join( save_path, entity.json_data['programtitle']) save_path = program_path try: if not os.path.exists(save_path): os.makedirs(save_path) except: logger.debug('program path make fail!!') ### edit by lapis ModelWavveProgram.update(entity) ### # 파일 존재여부 체크 if os.path.exists( os.path.join(save_path, entity.json_data['filename'])): entity.ffmpeg_status_kor = '파일 있음' entity.ffmpeg_percent = 100 ### edit by lapis ModelWavveProgram.delete(entity.episode_code, entity.quality) ### plugin.socketio_list_refresh() continue tmp = Wavve.get_prefer_url(streaming_data['playurl']) f = ffmpeg.Ffmpeg(tmp, entity.json_data['filename'], plugin_id=entity.entity_id, listener=LogicProgram.ffmpeg_listener, max_pf_count=max_pf_count, call_plugin='wavve_program', save_path=save_path) f.start() LogicProgram.current_ffmpeg_count += 1 LogicProgram.download_queue.task_done() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def download_thread_function(): while True: #while self.flag_stop == False: try: while True: if TvingProgram.current_ffmpeg_count < ModelSetting.get_int('program_auto_count_ffmpeg'): break time.sleep(5) entity = TvingProgram.download_queue.get() if entity.cancel: continue # 초기화 if entity is None: return #Log('* 스캔 큐 AWAKE : %s', self.current_scan_entity.filename) #self.current_scan_entity.status = 'SCAN_START' #self.current_scan_entity.scan_start_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') #Log('* 스캔 큐 scan_start_time : %s', self.current_scan_entity.scan_start_time) Tving._token = ModelSetting.get('token') data, vod_url = TvingBasic.get_episode_json(entity.episode_code, entity.quality) #logger.debug(data) episode = Episode('basic') episode = TvingBasic.make_episode_by_json(episode, data, vod_url) #TvingBasic.current_episode = episode entity.json_data['filename'] = episode.filename #if TvingProgram.current_ffmpeg_count < TvingProgram.max_ffmpeg_count: import ffmpeg max_pf_count = ModelSetting.get('max_pf_count') save_path = ModelSetting.get('program_auto_path') if ModelSetting.get('program_auto_make_folder') == 'True': program_path = os.path.join(save_path, data['body']['content']['program_name']) save_path = program_path try: if not os.path.exists(save_path): os.makedirs(save_path) except: logger.debug('program path make fail!!') # 파일 존재여부 체크 if os.path.exists(os.path.join(save_path, episode.filename)): entity.ffmpeg_status_kor = '파일 있음' entity.ffmpeg_percent = 100 plugin.socketio_list_refresh() continue f = ffmpeg.Ffmpeg(vod_url, episode.filename, plugin_id=entity.entity_id, listener=TvingProgram.ffmpeg_listener, max_pf_count=max_pf_count, call_plugin='%s_program' % package_name, save_path=save_path) f.start() TvingProgram.current_ffmpeg_count += 1 TvingProgram.download_queue.task_done() """ self.current_scan_t = ScanThread() self.current_scan_t.set(self.current_scan_entity, self.wait_event) self.current_scan_t.start() Log('* 스캔 큐 thread 종료 대기') self.current_scan_t.join(60*10) if self.current_scan_t.is_alive(): Log('* 스캔 큐 still Alive') self.current_scan_t.process.terminate() self.current_scan_t.join() Log('process returncode %s', self.current_scan_t.process.returncode) self.current_scan_t = None # 초기화 한번 체크 if self.flag_stop: return self.current_scan_entity.status = 'SCAN_COMPLETED' self.current_scan_entity.scan_end_time = datetime.datetime.now().strftime('%Y-%m-%d %H:%M:%S') self.scan_queue.task_done() Log('* 남은 큐 사이즈 : %s', self.scan_queue.qsize()) self.current_scan_entity = None """ #time.sleep(100) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())