def streaming(cls, req): try: c_id = req.args.get('contentid') quality = Tving.get_quality_to_tving( ModelSetting.get('tving_quality')) data, url = Tving.get_episode_json(c_id, quality) return redirect(url, code=302) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def analyze(url): try: logger.debug('analyze :%s', url) url_type = None code = None if url.startswith('http'): match = re.compile(r'player\/(?P<code>E\d+)').search(url) if match: url_type = 'episode' code = match.group('code') else: if url.startswith('E'): url_type = 'episode' code = url elif url.startswith('P'): url_type = 'program' code = url.strip() elif url.startswith('M'): url_type = 'movie' code = url.strip() else: pass logger.debug('Analyze %s %s', url_type, code) ModelSetting.set('recent_code', code) if url_type is None: return {'url_type':'None'} elif url_type == 'episode': quality = ModelSetting.get('quality') quality = Tving.get_quality_to_tving(quality) data, vod_url = TvingBasic.get_episode_json(code, quality) logger.debug(vod_url) if data is not None: episode = Episode('basic') episode = TvingBasic.make_episode_by_json(episode, data, vod_url) TvingBasic.current_episode = episode return {'url_type': url_type, 'ret' : True, 'data' : episode.as_dict()} else: return {'url_type': url_type, 'ret' : False, 'data' : data} elif url_type == 'program': data = Tving.get_vod_list(Tving.config['program_param'] % code, page=1) return {'url_type': url_type, 'page':'1', 'code':code, 'data' : data} elif url_type == 'movie': proxy_url = ModelSetting.get('proxy_url') if ModelSetting.get_bool('use_proxy') else None data = Tving.get_movie_json(code, ModelSetting.get('device_id'), proxy_url, ModelSetting.get('token')) return {'url_type': url_type, 'page':'1', 'code':code, 'data' : data} except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def streaming(cls, req): try: c_id = req.args.get('contentid') quality = Tving.get_quality_to_tving(ModelSetting.get('tving_quality')) proxy = None if ModelSetting.get_bool('tving_use_proxy'): proxy = ModelSetting.get('tving_proxy_url') #data, url = Tving.get_episode_json(c_id, quality, cls.login_data, proxy=proxy, is_live=True) # 이건 vod data, url = Tving.get_episode_json(c_id, quality, cls.login_data, proxy=proxy) return redirect(url, code=302) except Exception, e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def get_url(cls, source_id, quality, mode): try: quality = Tving.get_quality_to_tving(quality) c_id = source_id if source_id.startswith('V'): c_id = source_id[1:] if Tving.is_drm_channel(source_id): return Tving.get_stream_info_by_web('live', c_id, quality) else: data, url = Tving.get_episode_json(c_id, quality, is_live=True) if source_id.startswith('V'): return 'redirect', url else: return 'return_after_read', url except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def get_url(cls, source_id, quality, mode): #logger.debug('tving get_url:%s %s %s', source_id, quality, cls.login_data) try: quality = Tving.get_quality_to_tving(quality) c_id = source_id if source_id.startswith('V'): c_id = source_id[1:] proxy = None if ModelSetting.get_bool('tving_use_proxy'): proxy = ModelSetting.get('tving_proxy_url') data, url = Tving.get_episode_json(c_id, quality, cls.login_data, proxy=proxy, is_live=True) if source_id.startswith('V'): return 'redirect', url else: return 'return_after_read', url except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def scheduler_function(): try: #logger.debug('start scheduler_function') import ffmpeg page = ModelSetting.get_int('auto_page') max_pf_count = ModelSetting.get('max_pf_count') save_path = ModelSetting.get('auto_save_path') default_quality = Tving.get_quality_to_tving(ModelSetting.get('auto_quality')) retry_user_abort = ModelSetting.get_bool('retry_user_abort') except_channel = ModelSetting.get('except_channel') except_program = ModelSetting.get(key='except_program') download_qvod = ModelSetting.get_bool('download_qvod') download_program_in_qvod = ModelSetting.get('download_program_in_qvod') download_mode = ModelSetting.get(key='download_mode') whitelist_program = ModelSetting.get('whitelist_program') whitelist_first_episode_download = ModelSetting.get_bool('whitelist_first_episode_download') except_channels = [x.strip() for x in except_channel.replace('\n', ',').split(',')] except_programs = [x.strip().replace(' ', '') for x in except_program.replace('\n', ',').split(',')] download_program_in_qvods = [x.strip().replace(' ', '') for x in download_program_in_qvod.replace('\n', ',').split(',')] whitelist_programs = [x.strip().replace(' ', '') for x in whitelist_program.replace('\n', ',').split(',')] except_channels = Util.get_list_except_empty(except_channels) except_programs = Util.get_list_except_empty(except_programs) download_program_in_qvods = Util.get_list_except_empty(download_program_in_qvods) whitelist_programs = Util.get_list_except_empty(whitelist_programs) logger.debug('except_channels:%s', except_channels) logger.debug('except_programs:%s', except_programs) logger.debug('download_qvod :%s %s', download_qvod, type(download_qvod)) logger.debug('download_program_in_qvods:%s', download_program_in_qvods) for i in range(1, page+1): vod_list = Tving.get_vod_list(page=i)["body"]["result"] for vod in vod_list: try: if not scheduler.is_include('tving_recent'): logger.debug('not in scheduler') return code = vod["episode"]["code"] with db.session.no_autoflush: # 2019-01-11 720권한만 있을 때 1080p를 받으려고 하면 계속 episode를 생성 #episode = db.session.query(Episode).filter_by(episode_code=code, quality=default_quality).with_for_update().first() #episode = db.session.query(Episode).filter_by(episode_code=code).with_for_update().first() # 2020-02-14 qvod episode_code 고정 episode = db.session.query(Episode).filter_by(episode_code=code, broadcast_date=str(vod["episode"]["broadcast_date"])[2:]).with_for_update().first() if episode is not None: logger.debug('program_name:%s frequency:%s %s %s', episode.program_name, episode.frequency, episode.user_abort, episode.retry) if episode.completed: logger.debug('COMPLETED') continue elif episode.user_abort: if retry_user_abort: episode.user_abort = False else: continue elif episode.etc_abort > 10: # 1:알수없는이유 시작실패, 2 타임오버, 3, 강제스톱.킬 # 12:제외채널, 13:제외프로그램 # 14:화이트리스트 # 9 : retry # 8 : qvod logger.debug('ETC ABORT:%s', episode.etc_abort) continue elif episode.retry > 20: logger.debug('retry 20') episode.etc_abort = 15 continue # URL때문에 DB에 있어도 다시 JSON을 받아야함. json_data, url = TvingBasic.get_episode_json(code, default_quality) if episode is None: logger.debug('EPISODE is none') episode = Episode('auto') episode = TvingBasic.make_episode_by_json(episode, json_data, url) db.session.add(episode) else: episode = TvingBasic.make_episode_by_json(episode, json_data, url) # qvod 체크 is_qvod = False if url.find('quickvod') != -1: is_qvod = True # 채널, 프로그램 체크 flag_download = True if is_qvod: if not download_qvod: flag_download = False for program_name in download_program_in_qvods: if episode.program_name.replace(' ', '').find(program_name) != -1: episode.etc_abort = 0 flag_download = True logger.debug('is qvod.. %s %s', program_name, flag_download) break if not flag_download: episode.etc_abort = 8 db.session.commit() logger.debug('is qvod.. pass') continue if download_mode == '0': for program_name in except_programs: if episode.program_name.replace(' ', '').find(program_name) != -1: episode.etc_abort = 13 flag_download = False break if episode.channel_name in except_channels: episode.etc_abort = 12 flag_download = False else: if flag_download: #무조건 탐 find_in_whitelist = False for program_name in whitelist_programs: if episode.program_name.replace(' ', '').find(program_name) != -1: find_in_whitelist = True break if not find_in_whitelist: episode.etc_abort = 14 flag_download = False if not flag_download and whitelist_first_episode_download and episode.frequency == 1: flag_download = True if flag_download: episode.etc_abort = 0 episode.retry += 1 episode.pf = 0 # 재시도 episode.save_path = save_path episode.start_time = datetime.now() db.session.commit() else: db.session.commit() time.sleep(2) continue logger.debug('FFMPEG Start.. id:%s', episode.id) if episode.id is None: logger.debug('PROGRAM:%s', episode.program_name) f = ffmpeg.Ffmpeg(url, episode.filename, plugin_id=episode.id, listener=TvingBasic.ffmpeg_listener, max_pf_count=max_pf_count, call_plugin='%s_recent' % package_name, save_path=save_path) f.start_and_wait() except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) #break #logger.debug('end scheduler_function') except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def analyze(url): try: logger.debug('analyze :%s', url) url_type = None code = None match = re.compile(r'(?P<code>[EMP]\d+)').search(url) if match: code = match.group('code') if code.startswith('E'): url_type = 'episode' elif code.startswith('P'): url_type = 'program' elif code.startswith('M'): url_type = 'movie' logger.debug('Analyze %s %s', url_type, code) if url_type is None: return {'url_type': 'None'} elif url_type == 'episode': quality = ModelSetting.get('quality') quality = Tving.get_quality_to_tving(quality) try: data, vod_url = TvingBasic.get_episode_json(code, quality) except TypeError as e: data, vod_url = None, None logger.debug(vod_url) if data is not None: episode = Episode('basic') episode = TvingBasic.make_episode_by_json( episode, data, vod_url) TvingBasic.current_episode = episode return { 'url_type': url_type, 'ret': True, 'code': code, 'data': episode.as_dict() } else: return { 'url_type': url_type, 'ret': False, 'data': { 'message': '에피소드 정보를 얻지 못함' } } elif url_type == 'program': data = Tving.get_vod_list(Tving.config['program_param'] % code, page=1) return { 'url_type': url_type, 'page': '1', 'code': code, 'data': data } elif url_type == 'movie': data = Tving.get_movie_json(code) return { 'url_type': url_type, 'page': '1', 'code': code, 'data': data } except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())