def set_streaming(self, data): self.streaming_json = data self.playurl = data['playurl'] import framework.wavve.api as Wavve self.filename = Wavve.get_filename(self.contents_json, data['quality']) self.quality = data['quality']
def analyze(url, quality=None): try: logger.debug('analyze :%s', url) url_type = None code = None corner_id = None vod_type = None if url.startswith('http'): match = re.compile( r'contentid\=(?P<contentid>.*?)(\&|$|\#)').search(url) match2 = re.compile( r'programid\=(?P<programid>.*?)(\&|$|\#)').search(url) if match: code = match.group('contentid') url_type = 'episode' elif match2: url_type = 'program' code = match2.group('programid') else: match = re.compile( r'movieid\=(?P<movieid>.*?)($|\#)').search(url) if match: url_type = 'movie' code = match.group('movieid') else: if len(url.split('.')) == 2: url_type = 'episode' code = url.strip() elif url.startswith('MV_'): url_type = 'movie' code = url.strip() elif url.find('_') != -1: url_type = 'program' code = url.strip() else: pass logger.debug('Analyze %s %s', url_type, code) if url_type is None: return {'url_type': 'None'} elif url_type == 'episode': if quality is None: quality = ModelSetting.get('quality') data = Wavve.vod_contents_contentid(code) contenttype = 'onairvod' if data['type'] == 'onair' else 'vod' proxy = None data2 = Wavve.streaming(contenttype, code, quality, ModelSetting.get('credential')) try: tmp = data2['playurl'] except: try: LogicBasic.login() data2 = Wavve.streaming(contenttype, code, quality, ModelSetting.get('credential')) except: pass #logger.debug(data2) data3 = {} data3['filename'] = Wavve.get_filename(data, quality) data3['preview'] = (data2['playurl'].find('preview') != -1) data3['current_quality'] = quality ModelSetting.set('recent_code', code) return { 'url_type': url_type, 'code': code, 'episode': data, 'streaming': data2, 'available': data3 } elif url_type == 'program': data = Wavve.vod_program_contents_programid(code) ModelSetting.set('recent_code', code) return { 'url_type': url_type, 'page': '1', 'code': code, 'data': data } elif url_type == 'movie': if quality is None: quality = ModelSetting.get('quality') data = Wavve.movie_contents_movieid(code) data2 = Wavve.streaming('movie', code, quality, ModelSetting.get('credential')) try: tmp = data2['playurl'] except: try: LogicBasic.login() data2 = Wavve.streaming('movie', code, quality, ModelSetting.get('credential')) except: pass data3 = {} data3['filename'] = Wavve.get_filename(data, quality) data3['preview'] = (data2['playurl'].find('preview') != -1) data3['current_quality'] = quality ModelSetting.set('recent_code', code) return { 'url_type': url_type, 'code': code, 'info': data, 'streaming': data2, 'available': data3 } except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
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())