def download_url(url, filename): try: logger.debug('download_url : %s', url) save_path = ModelSetting.get('save_path') max_pf_count = ModelSetting.get('max_pf_count') tmp = Wavve.get_prefer_url(url) proxy = None if ModelSetting.get_bool('use_proxy'): proxy = ModelSetting.get('proxy_url') f = ffmpeg.Ffmpeg(tmp, filename, plugin_id=-1, listener=LogicBasic.ffmpeg_listener, max_pf_count=max_pf_count, call_plugin='wavve_basic', save_path=save_path, proxy=proxy) #f.start_and_wait() f.start() #time.sleep(60) return True except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def plugin_load(): try: logger.debug('%s plugin_load', package_name) # DB 초기화 Logic.db_init() # 편의를 위해 json 파일 생성 from plugin import plugin_info Util.save_from_dict_to_json(plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def __init__(self, api_token, account_id, esg_name, adjustment_type, adjustment): """Create an ECSAutoscaler.""" self._api_root = "https://api.spotinst.io" self._account_id = account_id self._api_token = api_token self._esg_name = esg_name self._adjustment_type = adjustment_type self._adjustment = int(adjustment) # Fill in the ESG ID based on the name esg_id_req = self.request( url=self._preprocess(endpoint="/aws/ec2/group", options=dict(name=self._esg_name))) logger.debug(esg_id_req) self._esg_id = esg_id_req['items'][0]['id'] self._esg_capacity = esg_id_req['items'][0]['capacity']
def plugin_load(): try: logger.debug('%s plugin_load', package_name) # DB 초기화 Logic.db_init() LogicBasic.login() if ModelSetting.get('auto_start') == 'True': Logic.scheduler_start() # 편의를 위해 json 파일 생성 from plugin import plugin_info Util.save_from_dict_to_json( plugin_info, os.path.join(os.path.dirname(__file__), 'info.json')) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())
def ffmpeg_listener(**arg): import ffmpeg refresh_type = None if arg['type'] == 'status_change': if arg['status'] == ffmpeg.Status.DOWNLOADING: episode = db.session.query(ModelWavveEpisode).filter_by( id=arg['plugin_id']).with_for_update().first() if episode: episode.ffmpeg_status = int(arg['status']) episode.duration = arg['data']['duration'] db.session.commit() elif arg['status'] == ffmpeg.Status.COMPLETED: pass elif arg['status'] == ffmpeg.Status.READY: pass elif arg['type'] == 'last': episode = db.session.query(ModelWavveEpisode).filter_by( id=arg['plugin_id']).with_for_update().first() if episode: episode.ffmpeg_status = int(arg['status']) if arg['status'] == ffmpeg.Status.WRONG_URL or arg[ 'status'] == ffmpeg.Status.WRONG_DIRECTORY or arg[ 'status'] == ffmpeg.Status.ERROR or arg[ 'status'] == ffmpeg.Status.EXCEPTION: episode.etc_abort = 1 elif arg['status'] == ffmpeg.Status.USER_STOP: episode.user_abort = True logger.debug('Status.USER_STOP received..') elif arg['status'] == ffmpeg.Status.COMPLETED: episode.completed = True episode.end_time = datetime.now() episode.download_time = (episode.end_time - episode.start_time).seconds episode.filesize = arg['data']['filesize'] episode.filesize_str = arg['data']['filesize_str'] episode.download_speed = arg['data']['download_speed'] logger.debug('Status.COMPLETED received..') elif arg['status'] == ffmpeg.Status.TIME_OVER: episode.etc_abort = 2 elif arg['status'] == ffmpeg.Status.PF_STOP: episode.pf = int(arg['data']['current_pf_count']) episode.pf_abort = 1 elif arg['status'] == ffmpeg.Status.FORCE_STOP: episode.etc_abort = 3 elif arg['status'] == ffmpeg.Status.HTTP_FORBIDDEN: episode.etc_abort = 4 db.session.commit() logger.debug('LAST commit %s', arg['status']) from .logic_recent import LogicRecent LogicRecent.current_auto_count_ffmpeg -= 1 elif arg['type'] == 'log': pass elif arg['type'] == 'normal': pass if refresh_type is not None: pass
def setting_save(req): try: flag_login = False for key, value in req.form.items(): logger.debug('Key:%s Value:%s', key, value) entity = db.session.query(ModelSetting).filter_by( key=key).with_for_update().first() if key == 'id' or key == 'pw': if entity.value != value: flag_login = True if entity is not None: entity.value = value db.session.commit() if flag_login: if LogicBasic.login(force=True): return 1 else: return 2 return True except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) logger.error('key:%s value:%s', key, value) return False
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 plugin_unload(): try: logger.debug('%s plugin_unload', package_name) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc())