def make_rss(package_name, rss_list): #from system.model import ModelSetting as SystemModelSetting #ddns = SystemModelSetting.get('ddns') xml = '<rss xmlns:showrss=\"http://showrss.info/\" version=\"2.0\">\n' xml += '\t<channel>\n' xml += '\t\t<title>' + '%s</title>\n' % package_name xml += '\t\t<link></link>\n' xml += '\t\t<description></description>\n' for bbs in rss_list: try: item_str = '\t\t<item>\n' tmp = '\t\t\t<title>%s</title>\n' % RssUtil.replace_xml( bbs['title']) item_str += tmp #item_str += '\t\t\t<link>%s</link>\n' % bbs['link'] item_str += '\t\t\t<link>%s</link>\n' % RssUtil.replace_xml( bbs['link']) date_str = bbs['created_time'].strftime( "%a, %d %b %Y %H:%M:%S") + ' +0900' item_str += '\t\t\t<pubDate>%s</pubDate>\n' % date_str item_str += '\t\t</item>\n' xml += item_str except Exception as exception: logger.debug('Exception:%s', exception) logger.debug(traceback.format_exc()) xml += '\t</channel>\n' xml += '</rss>' return xml
def run(self): logger.debug('WatchThread.. Start %s', self.package) if self.package is not None: logfile = os.path.join(path_data, 'log', '%s.log' % self.package) key = 'package' value = self.package else: logfile = os.path.join(path_data, 'log', self.filename) key = 'filename' value = self.filename if os.path.exists(logfile): with open(logfile, 'r') as f: f.seek(0, os.SEEK_END) while not self.stop_flag: line = f.readline() if not line: time.sleep(0.1) # Sleep briefly continue socketio.emit("add", { key: value, 'data': line }, namespace='/log', broadcast=True) logger.debug('WatchThread.. End %s', value) else: socketio.emit("add", { key: value, 'data': 'not exist logfile' }, namespace='/log', broadcast=True)
def disconnect(): try: LogViewer.instance().disconnect(request.sid) logger.debug('disconnect sid:%s', request.sid) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def check_filename(filename): logger.debug('check_filename filename : %s', filename) try: ret = None match1 = re.compile(_REGEX_FILENAME).match(filename) match2 = re.compile(_REGEX_FILENAME_NO_EPISODE_NUMBER).match( filename) for regex in [_REGEX_FILENAME, _REGEX_FILENAME_NO_EPISODE_NUMBER]: match = re.compile(regex).match(filename) if match: logger.debug('QQQQQQQQQQQ') ret = {} ret['title'] = match1.group('name') ret['no'] = match1.group('no') ret['date'] = match1.group('date') ret['etc'] = match1.group('etc').replace('.', '') ret['quality'] = match1.group('quality') ret['release'] = None if 'release' in match1.groupdict(): ret['release'] = match1.group('release') else: ret['release'] = None if ret['no'] is not None and ret['no'] != '': ret['no'] = int(ret['no']) else: ret['no'] = -1 return DaumTV.change_filename_continous_episode(ret) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def rc(): try: logger.debug('XXXXXXXXXXXXXXXXXXXXXXXXXXXXX') logger.debug(path) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return jsonify('fail')
def download(url, file_name): try: import requests with open(file_name, "wb") as file_is: # open in binary mode response = requests.get(url) # get request file_is.write(response.content) # write to file except Exception as exception: logger.debug('Exception:%s', exception) logger.debug(traceback.format_exc())
def write_file(data, filename): try: import codecs ofp = codecs.open(filename, 'w', encoding='utf8') ofp.write(data) ofp.close() except Exception as exception: logger.debug('Exception:%s', exception) logger.debug(traceback.format_exc())
def _move_task(source_path, target_path): try: logger.debug('_move_task:%s %s', source_path, target_path) shutil.move(source_path, target_path) logger.debug('_move_task end') return True except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return False
def func(mod, key): try: logger.debug( f'[!] plugin_load threading start : [{key}]') mod.plugin_load() logger.debug( f'[!] plugin_load threading end : [{key}]') except Exception as exception: logger.error('### plugin_load exception : %s', key) logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def copy_server_side(cls, source, target, rclone_path='rclone', config_path=os.path.join(path_data, 'db', 'rclone.conf'), option=None): try: command = [rclone_path, '--config', config_path, 'copy', source, target, '--drive-server-side-across-configs=true', '--drive-stop-on-upload-limit', '-vv'] if option is not None: command += option logger.debug(' '.join(command)) ret = ToolSubprocess.execute_command_return(command) return ret except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def socket_file(data): try: package = filename = None if 'package' in data: package = data['package'] else: filename = data['filename'] LogViewer.instance().start(package, filename, request.sid) logger.debug('start package:%s filename:%s sid:%s', package, filename, request.sid) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def thread_function(): if package is not None: logfile = os.path.join(path_data, 'log', '%s.log' % package) else: logfile = os.path.join(path_data, 'log', filename) if os.path.exists(logfile): ins_file = open(logfile, 'r', encoding='utf8') ## 3) line = ins_file.read() socketio.emit("on_start", {'data': line}, namespace='/log') logger.debug('on_start end') else: socketio.emit("on_start", {'data': 'not exist logfile'}, namespace='/log')
def remove(remove_path): try: logger.debug('CELERY os.remove start : %s', remove_path) if app.config['config']['use_celery']: result = _remove_task.apply_async((remove_path, )) return result.get() else: return _remove_task(remove_path) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return _remove_task(remove_path) finally: logger.debug('CELERY os.remove end : %s', remove_path)
def _move_exist_remove_task(source_path, target_path): try: target_file_path = os.path.join(target_path, os.path.basename(source_path)) if os.path.exists(target_file_path): os.remove(source_path) return True logger.debug('_move_exist_remove:%s %s', source_path, target_path) shutil.move(source_path, target_path) logger.debug('_move_exist_remove end') return True except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return False
def change_filename_continous_episode(ret): try: if ret['title'].find(u'합') == -1: return ret match = re.compile(_REGEX_FILENAME_RENAME).match(ret['title']) if match: logger.debug(u'합본 : %s', ret['filename']) ret['title'] = match.group('title').strip() # 기존 규칙으로 매칭되어있다면 굳이 바꿀 필요는 없다. if ret['no'] == -1: ret['no'] = int(match.group('no')) return ret except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def upload(): # curl -F file=@downloader_video.tar https://dev.soju6jan.com/up # try: if request.method == 'POST': f = request.files['file'] from werkzeug import secure_filename tmp = secure_filename(f.filename) logger.debug('upload : %s', tmp) f.save(os.path.join(path_data, 'upload', tmp)) return jsonify('success') except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return jsonify('fail')
def disconnect(cls, sid): find = False find_key = None for key, value in cls.watch_list.items(): logger.debug('key:%s value:%s', key, value) for s in value['sid']: if sid == s: find = True find_key = key value['sid'].remove(s) break if find: break if not find: return if not cls.watch_list[find_key]['sid']: logger.debug('thread kill') cls.watch_list[find_key]['thread'].stop() del cls.watch_list[find_key]
def wrapper_function(*args, **kwargs): #1 from framework import logger #logger.debug('CHECK API... {} '.format(original_function.__module__)) #logger.warning(request.url) #logger.warning(request.form) try: from system import ModelSetting as SystemModelSetting if SystemModelSetting.get_bool('auth_use_apikey'): if request.method == 'POST': apikey = request.form['apikey'] else: apikey = request.args.get('apikey') #apikey = request.args.get('apikey') if apikey is None or apikey != SystemModelSetting.get('auth_apikey'): logger.debug('CHECK API : ABORT no match ({})'.format(apikey)) logger.debug(request.environ.get('HTTP_X_REAL_IP', request.remote_addr)) abort(403) return except Exception as exception: print('Exception:%s', exception) print(traceback.format_exc()) logger.debug('CHECK API : ABORT exception') abort(403) return return original_function(*args, **kwargs) #2
def get_paging_info(count, current_page, page_size): try: paging = {} paging['prev_page'] = True paging['next_page'] = True if current_page <= 10: paging['prev_page'] = False paging['total_page'] = int(count / page_size) + 1 if count % page_size == 0: paging['total_page'] -= 1 paging['start_page'] = int((current_page - 1) / 10) * 10 + 1 paging['last_page'] = paging[ 'total_page'] if paging['start_page'] + 9 > paging[ 'total_page'] else paging['start_page'] + 9 if paging['last_page'] == paging['total_page']: paging['next_page'] = False paging['current_page'] = current_page paging['count'] = count logger.debug('paging : c:%s %s %s %s %s %s', count, paging['total_page'], paging['prev_page'], paging['next_page'], paging['start_page'], paging['last_page']) return paging except Exception as exception: logger.debug('Exception:%s', exception) logger.debug(traceback.format_exc())
def socket_connect(): logger.debug('log connect')
def open_file(path): logger.debug('open_file :%s', path) return send_from_directory('/', path)
def file2(path): logger.debug('file2 :%s', path) return send_from_directory('/', path)
def plugin_init(): try: if not app.config['config']['auth_status']: return import inspect plugin_path = os.path.join( os.path.dirname( os.path.dirname(os.path.dirname(os.path.abspath(__file__)))), 'plugin') sys.path.insert(0, plugin_path) from . import SystemModelSetting """ try: from . import SystemModelSetting plugins = ['command', 'mod'] for plugin in os.listdir(plugin_path): plugins.append(plugin) except: plugins = os.listdir(plugin_path) """ plugins = os.listdir(plugin_path) pass_include = [] except_plugin_list = [] #2019-07-17 try: plugin_path = os.path.join( os.path.dirname( os.path.dirname(os.path.dirname( os.path.abspath(__file__)))), 'data', 'custom') sys.path.insert(1, plugin_path) tmps = os.listdir(plugin_path) add_plugin_list = [] for t in tmps: if not t.startswith('_') and os.path.isdir( os.path.join(plugin_path, t)): add_plugin_list.append(t) plugins = plugins + add_plugin_list pass_include = pass_include + add_plugin_list except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) # 2018-09-04 try: plugin_path = SystemModelSetting.get('plugin_dev_path') if plugin_path != '': if os.path.exists(plugin_path): sys.path.insert(0, plugin_path) tmps = os.listdir(plugin_path) add_plugin_list = [] for t in tmps: if not t.startswith('_') and os.path.isdir( os.path.join(plugin_path, t)): add_plugin_list.append(t) if app.config['config']['level'] < 4: break plugins = plugins + add_plugin_list pass_include = pass_include + add_plugin_list except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) plugins = sorted(plugins) logger.debug(plugins) for plugin_name in plugins: #logger.debug(len(system.LogicPlugin.current_loading_plugin_list)) if plugin_name.startswith('_'): continue if plugin_name == 'terminal' and platform.system() == 'Windows': continue if plugin_name in except_plugin_list: logger.debug('Except plugin : %s' % plugin_menu) continue logger.debug(f'[+] PLUGIN LOADING Start.. [{plugin_name}]') try: mod = __import__('%s' % (plugin_name), fromlist=[]) mod_plugin_info = None # 2021-12-31 if plugin_name not in system.LogicPlugin.current_loading_plugin_list: system.LogicPlugin.current_loading_plugin_list[ plugin_name] = { 'status': 'loading' } try: mod_plugin_info = getattr(mod, 'plugin_info') if 'category' not in mod_plugin_info and 'category_name' in mod_plugin_info: mod_plugin_info['category'] = mod_plugin_info[ 'category_name'] if 'policy_point' in mod_plugin_info: if mod_plugin_info['policy_point'] > app.config[ 'config']['point']: system.LogicPlugin.current_loading_plugin_list[ plugin_name][ 'status'] = 'violation_policy_point' continue if 'policy_level' in mod_plugin_info: if mod_plugin_info['policy_level'] > app.config[ 'config']['level']: system.LogicPlugin.current_loading_plugin_list[ plugin_name][ 'status'] = 'violation_policy_level' continue if 'category' in mod_plugin_info and mod_plugin_info[ 'category'] == 'beta': if SystemModelSetting.get_bool('use_beta') == False: system.LogicPlugin.current_loading_plugin_list[ plugin_name]['status'] = 'violation_beta' continue except Exception as exception: #logger.error('Exception:%s', exception) #logger.error(traceback.format_exc()) logger.debug( f'[!] PLUGIN_INFO not exist : [{plugin_name}]') try: mod_blue_print = getattr(mod, 'blueprint') if mod_blue_print: if plugin_name in pass_include or is_include_menu( plugin_name): app.register_blueprint(mod_blue_print) except Exception as exception: #logger.error('Exception:%s', exception) #logger.error(traceback.format_exc()) logger.debug(f'[!] BLUEPRINT not exist : [{plugin_name}]') plugin_instance_list[plugin_name] = mod system.LogicPlugin.current_loading_plugin_list[plugin_name][ 'status'] = 'success' system.LogicPlugin.current_loading_plugin_list[plugin_name][ 'info'] = mod_plugin_info except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) logger.debug('no blueprint') #from tool_base import d #logger.error(d(system.LogicPlugin.current_loading_plugin_list)) # 2021-07-01 모듈에 있는 DB 테이블 생성이 안되는 문제 # 기존 구조 : db.create_all() => 모듈 plugin_load => celery task 등록 후 리턴 # 변경 구조 : 모듈 plugin_load => db.create_all() => celery인 경우 리턴 # plugin_load 를 해야 하위 로직에 있는 DB가 로딩된다. # plugin_load 에 db는 사용하는 코드가 있으면 안된다. (테이블도 없을 때 에러발생) try: #logger.warning('module plugin_load in celery ') plugin_instance_list['mod'].plugin_load() except Exception as exception: logger.debug(f'mod plugin_load error!!') #logger.error('Exception:%s', exception) #logger.error(traceback.format_exc()) # import가 끝나면 DB를 만든다. # 플러그인 로드시 DB 초기화를 할 수 있다. if not app.config['config']['run_by_worker']: try: db.create_all() except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) logger.debug('db.create_all error') if not app.config['config']['run_by_real']: # 2021-06-03 # 모듈의 로직에 있는 celery 함수는 등록해주어야한다. #try: # logger.warning('module plugin_load in celery ') # plugin_instance_list['mod'].plugin_load() #except Exception as exception: # logger.error('module plugin_load error') # logger.error('Exception:%s', exception) # logger.error(traceback.format_exc()) # 2021-07-01 # db때문에 위에서 로딩함. return for key, mod in plugin_instance_list.items(): try: mod_plugin_load = getattr(mod, 'plugin_load') if mod_plugin_load and (key in pass_include or is_include_menu(key)): def func(mod, key): try: logger.debug( f'[!] plugin_load threading start : [{key}]') mod.plugin_load() logger.debug( f'[!] plugin_load threading end : [{key}]') except Exception as exception: logger.error('### plugin_load exception : %s', key) logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) # mod는 위에서 로딩 if key != 'mod': t = threading.Thread(target=func, args=(mod, key)) t.setDaemon(True) t.start() #if key == 'mod': # t.join() except Exception as exception: logger.debug(f'[!] PLUGIN_LOAD function not exist : [{key}]') #logger.error('Exception:%s', exception) #logger.error(traceback.format_exc()) #logger.debug('no init_scheduler') try: mod_menu = getattr(mod, 'menu') if mod_menu and (key in pass_include or is_include_menu(key)): plugin_menu.append(mod_menu) except Exception as exception: logger.debug('no menu') logger.debug('### plugin_load threading all start.. : %s ', len(plugin_instance_list)) # 모든 모듈을 로드한 이후에 app 등록, table 생성, start except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc())
def download_file(path): logger.debug('download_file :%s', path) return send_from_directory('/', path, as_attachment=True)
def execute_command_return(cls, command, format=None, force_log=False, shell=False, env=None): try: #logger.debug('execute_command_return : %s', ' '.join(command)) if app.config['config']['running_type'] == 'windows': tmp = [] if type(command) == type([]): for x in command: if x.find(' ') == -1: tmp.append(x) else: tmp.append(f'"{x}"') command = ' '.join(tmp) iter_arg = b'' if app.config['config']['is_py2'] else '' if app.config['config']['is_py2']: process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, bufsize=1, shell=shell, env=env) else: process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=shell, env=env, encoding='utf8') #process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=shell, env=env, encoding='utf8') ret = [] with process.stdout: for line in iter(process.stdout.readline, iter_arg): ret.append(line.strip()) if force_log: logger.debug(ret[-1]) process.wait() # wait for the subprocess to exit if format is None: ret2 = '\n'.join(ret) elif format == 'json': try: index = 0 for idx, tmp in enumerate(ret): #logger.debug(tmp) if tmp.startswith('{') or tmp.startswith('['): index = idx break ret2 = json.loads(''.join(ret[index:])) except: ret2 = None return ret2 except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) logger.error('command : %s', command)
def execute_command_return2(cls, command, format=None, force_log=False, shell=False, env=None, timeout=None, uid=0, gid=0, pid_dict=None): def demote(user_uid, user_gid): def result(): os.setgid(user_gid) os.setuid(user_uid) return result try: if app.config['config']['running_type'] == 'windows': tmp = [] if type(command) == type([]): for x in command: if x.find(' ') == -1: tmp.append(x) else: tmp.append(f'"{x}"') command = ' '.join(tmp) iter_arg = b'' if app.config['config']['is_py2'] else '' if app.config['config']['running_type'] == 'windows': process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=shell, env=env, encoding='utf8') else: process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, universal_newlines=True, shell=shell, env=env, preexec_fn=demote(uid, gid), encoding='utf8') new_ret = {'status': 'finish', 'log': None} try: process_ret = process.wait( timeout=timeout) # wait for the subprocess to exit except: import psutil process = psutil.Process(process.pid) for proc in process.children(recursive=True): proc.kill() process.kill() new_ret['status'] = "timeout" ret = [] with process.stdout: for line in iter(process.stdout.readline, iter_arg): ret.append(line.strip()) if force_log: logger.debug(ret[-1]) if format is None: ret2 = '\n'.join(ret) elif format == 'json': try: index = 0 for idx, tmp in enumerate(ret): #logger.debug(tmp) if tmp.startswith('{') or tmp.startswith('['): index = idx break ret2 = json.loads(''.join(ret[index:])) except: ret2 = None new_ret['log'] = ret2 return new_ret except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) logger.error('command : %s', command)
def hls_play(): url = request.args.get('url') logger.debug('hls url : %s', url) return render_template('hls_player3.html', url=url)
def get_rss(url): try: logger.debug('get_rss : %s', url) """ req = py_urllib2.Request(url) req.add_header('user-agent', 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36') resp = py_urllib2.urlopen(req) tree = ET.ElementTree(file=resp) """ text = requests.get( url, headers={ 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.92 Safari/537.36' }).text #logger.warning(text) root = ET.fromstring(text) #logger.warning(tree) #root = tree.getroot() item_list = root.find('channel').findall('item') logger.debug('xml item count:%s', len(item_list)) ret = [] for item in item_list: try: link = item.find('link').text.strip() if link.startswith('magnet'): try: link = link[0:60] except: logger.error(e) logger.error(traceback.format_exc()) link = item.find('link').text.strip() rss = Feed(item.find('title').text.strip(), link) ret.append(rss) except Exception as exception: #logger.debug(item.find('title').text) #logger.debug(item.find('link').text) logger.debug(exception) logger.debug(traceback.format_exc()) return ret except Exception as exception: logger.debug(exception) logger.debug(traceback.format_exc()) logger.debug('url:%s', url) return None
def search_movie(movie_name, movie_year): try: movie_year = '%s' % movie_year movie_list = [] #8년 전쟁 이란 vs 이라크 split_index = -1 is_include_kor = False for index, c in enumerate(movie_name): if app.config['config']['is_py2']: if ord(u'가') <= ord(c) <= ord(u'힣'): is_include_kor = True split_index = -1 elif ord('a') <= ord(c.lower()) <= ord('z'): is_include_eng = True if split_index == -1: split_index = index elif ord('0') <= ord(c.lower()) <= ord('9') or ord(' '): pass else: split_index = -1 else: if (u'가') <= (c) <= (u'힣'): is_include_kor = True split_index = -1 elif ('a') <= (c.lower()) <= ('z'): is_include_eng = True if split_index == -1: split_index = index elif ('0') <= (c.lower()) <= ('9') or (' '): pass else: split_index = -1 if is_include_kor and split_index != -1: kor = movie_name[:split_index].strip() eng = movie_name[split_index:].strip() else: kor = None eng = None logger.debug('SEARCH_MOVIE : [%s] [%s] [%s] [%s]' % (movie_name, is_include_kor, kor, eng)) movie_list = MovieSearch.search_movie_web(movie_list, movie_name, movie_year) if movie_list and movie_list[0]['score'] == 100: logger.debug('SEARCH_MOVIE STEP 1 : %s' % movie_list) return is_include_kor, movie_list if kor is not None: movie_list = MovieSearch.search_movie_web(movie_list, kor, movie_year) if movie_list and movie_list[0]['score'] == 100: logger.debug('SEARCH_MOVIE STEP 2 : %s' % movie_list) return is_include_kor, movie_list if eng is not None: movie_list = MovieSearch.search_movie_web(movie_list, eng, movie_year) if movie_list and movie_list[0]['score'] == 100: logger.debug('SEARCH_MOVIE STEP 3 : %s' % movie_list) return is_include_kor, movie_list #검찰측의 죄인 検察側の罪人. Kensatsu gawa no zainin. 2018.1080p.KOR.FHDRip.H264.AAC-RTM # 영어로 끝나지전은 한글 # 그 한글중 한글로 시작하지 않는곳까지 if kor is not None: tmps = kor.split(' ') index = -1 for i in range(len(tmps)): if app.config['config']['is_py2']: if ord(u'가') <= ord(tmps[i][0]) <= ord(u'힣') or ord('0') <= ord(tmps[i][0]) <= ord('9'): pass else: index = i break else: if (u'가') <= (tmps[i][0]) <= (u'힣') or ('0') <= (tmps[i][0]) <= ('9'): pass else: index = i break if index != -1: movie_list = MovieSearch.search_movie_web(movie_list, ' '.join(tmps[:index]), movie_year) if movie_list and movie_list[0]['score'] == 100: logger.debug('SEARCH_MOVIE STEP 4 : %s' % movie_list) return is_include_kor, movie_list #if is_plex == False: if True: # 95점이면 맞다고 하자. 한글로 보내야하기때문에 검색된 이름을.. if movie_list and movie_list[0]['score'] == 95: movie_list = MovieSearch.search_movie_web(movie_list, movie_list[0]['title'], movie_year) if movie_list and movie_list[0]['score'] == 100: logger.debug('SEARCH_MOVIE STEP 5 : %s' % movie_list) return is_include_kor, movie_list # IMDB if is_include_kor == False: movie = MovieSearch.search_imdb(movie_name.lower(), movie_year) if movie is not None: movie_list = MovieSearch.search_movie_web(movie_list, movie['title'], movie_year) if movie_list and movie_list[0]['score'] == 100: logger.debug('SEARCH_MOVIE STEP IMDB : %s' % movie_list) return is_include_kor, movie_list logger.debug('SEARCH_MOVIE STEP LAST : %s' % movie_list) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) return is_include_kor, movie_list
def search_movie_web(movie_list, movie_name, movie_year): """ try: #movie_list = [] url = 'https://suggest-bar.daum.net/suggest?id=movie&cate=movie&multiple=1&mod=json&code=utf_in_out&q=%s' % (py_urllib.quote(movie_name.encode('utf8'))) from system import SystemLogicSite data = SystemLogicSite.get_response_daum(url).json() #data = requests.get(url).json() for index, item in enumerate(data['items']['movie']): tmps = item.split('|') score = 85 - (index*5) if tmps[0].find(movie_name) != -1 and tmps[3] == movie_year: score = 95 elif tmps[3] == movie_year: score = score + 5 if score < 10: score = 10 MovieSearch.movie_append(movie_list, {'id':tmps[1], 'title':tmps[0], 'year':tmps[3], 'score':score}) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) """ try: url = 'https://search.daum.net/search?nil_suggest=btn&w=tot&DA=SBC&q=%s%s' % ('%EC%98%81%ED%99%94+', py_urllib.quote(movie_name.encode('utf8'))) ret = MovieSearch.get_movie_info_from_home(url) if ret is not None: # 부제목때문에 제목은 체크 하지 않는다. # 홈에 검색한게 년도도 같다면 score : 100을 주고 다른것은 검색하지 않는다. if ret['year'] == movie_year: score = 100 need_another_search = False else: score = 90 need_another_search = True MovieSearch.movie_append(movie_list, {'id':ret['daum_id'], 'title':ret['title'], 'year':ret['year'], 'score':score, 'country':ret['country'], 'more':ret['more']}) logger.debug('need_another_search : %s' % need_another_search) movie = ret['movie'] if need_another_search: tmp = movie.find('div[@class="coll_etc"]') if tmp is not None: tag_list = tmp.findall('.//a') first_url = None for tag in tag_list: match = re.compile(r'(.*?)\((.*?)\)').search(tag.text_content()) if match: daum_id = tag.attrib['href'].split('||')[1] score = 80 if match.group(1) == movie_name and match.group(2) == movie_year: first_url = 'https://search.daum.net/search?%s' % tag.attrib['href'] elif match.group(2) == movie_year and first_url is not None: first_url = 'https://search.daum.net/search?%s' % tag.attrib['href'] MovieSearch.movie_append(movie_list, {'id':daum_id, 'title':match.group(1), 'year':match.group(2), 'score':score}) #results.Append(MetadataSearchResult(id=daum_id, name=match.group(1), year=match.group(2), score=score, lang=lang)) logger.debug('first_url : %s' % first_url) if need_another_search and first_url is not None: new_ret = MovieSearch.get_movie_info_from_home(first_url) MovieSearch.movie_append(movie_list, {'id':new_ret['daum_id'], 'title':new_ret['title'], 'year':new_ret['year'], 'score':100, 'country':new_ret['country'], 'more':new_ret['more']}) #시리즈 tmp = movie.find('.//ul[@class="list_thumb list_few"]') logger.debug('SERIES:%s' % tmp) if tmp is not None: tag_list = tmp.findall('.//div[@class="wrap_cont"]') first_url = None score = 80 for tag in tag_list: a_tag = tag.find('a') daum_id = a_tag.attrib['href'].split('||')[1] daum_name = a_tag.text_content() span_tag = tag.find('span') year = span_tag.text_content() logger.debug('daum_id:%s %s %s' % (daum_id, year, daum_name)) if daum_name == movie_name and year == movie_year: first_url = 'https://search.daum.net/search?%s' % a_tag.attrib['href'] elif year == movie_year and first_url is not None: first_url = 'https://search.daum.net/search?%s' % tag.attrib['href'] MovieSearch.movie_append(movie_list, {'id':daum_id, 'title':daum_name, 'year':year, 'score':score}) logger.debug('first_url : %s' % first_url) if need_another_search and first_url is not None: new_ret = MovieSearch.get_movie_info_from_home(first_url) MovieSearch.movie_append(movie_list, {'id':new_ret['daum_id'], 'title':new_ret['title'], 'year':new_ret['year'], 'score':100, 'country':new_ret['country'], 'more':new_ret['more']}) except Exception as exception: logger.error('Exception:%s', exception) logger.error(traceback.format_exc()) movie_list = list(reversed(sorted(movie_list, key=lambda k:k['score']))) return movie_list