def process_ajax(self, sub, req): if sub == 'reset_last_index': ModelSetting.set('last_id', '-1') return jsonify(True) elif sub == 'web_list': ret = ModelBotDownloaderKtvItem.filelist(request) ret['plex_server_hash'] = None try: import plex ret['plex_server_hash'] = plex.Logic.get_server_hash() except Exception as e: logger.debug('not import plex') return jsonify(ret) elif sub == 'add_program': ret = self.add_program(request) return jsonify(ret) elif sub == 'add_download': ret = self.add_download(request) return jsonify(ret) elif sub == 'plex_refresh': ret = self.plex_refresh(request.form['id']) return jsonify(ret) elif sub == 'remove': ret = ModelBotDownloaderKtvItem.remove(request.form['id']) return jsonify(ret) # 봇 검색 elif sub == 'torrent_info': try: from torrent_info import Logic as TorrentInfoLogic data = request.form['hash'] logger.debug(data) if data.startswith('magnet'): ret = TorrentInfoLogic.parse_magnet_uri(data) else: ret = TorrentInfoLogic.parse_torrent_url(data) return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'share_copy': ret = self.share_copy(request) return jsonify(ret)
ret = self.plex_refresh(request.form['id']) return jsonify(ret) elif sub == 'remove': ret = ModelBotDownloaderKtvItem.remove(request.form['id']) return jsonify(ret) # 봇 검색 elif sub == 'torrent_info': try: from torrent_info import Logic as TorrentInfoLogic data = request.form['hash'] logger.debug(data) if data.startswith('magnet'): ret = TorrentInfoLogic.parse_magnet_uri(data) else: ret = TorrentInfoLogic.parse_torrent_url(data) return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'share_copy': ret = self.share_copy(request) return jsonify(ret) def process_api(self, sub, req): if sub == 'add_download': ret = self.add_download_api(request) return jsonify(ret) elif sub == 'rss': ret = ModelBotDownloaderKtvItem.itemlist_by_api(request)
def ajax(sub): try: ret = {} # self - setting if sub == 'setting_save': ret = ModelSetting.setting_save(request) return jsonify(ret) elif sub == 'scheduler': go = request.form['scheduler'] logger.debug('scheduler :%s', go) if go == 'true': Logic.scheduler_start() else: Logic.scheduler_stop() return jsonify(go) elif sub == 'one_execute': ret = Logic.one_execute() return jsonify(ret) elif sub == 'reset_db': ret = Logic.reset_db() return jsonify(ret) # self - site elif sub == 'load_site': ret['site'] = ModelSite2.get_list(by_dict=True) return jsonify(ret) elif sub == 'test': ret = LogicSelf.action_test(request) return jsonify(ret) elif sub == 'site_delete': ret['ret'] = ModelSite2.delete(request.form['site_id']) ret['site'] = ModelSite2.get_list(by_dict=True) return jsonify(ret) elif sub == 'site_edit': ret['ret'] = LogicSelf.site_edit(request) ret['site'] = ModelSite2.get_list(by_dict=True) return jsonify(ret) # self - scheduler elif sub == 'load_scheduler': ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) elif sub == 'add_scheduler': ret['ret'] = LogicSelf.add_scheduler(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) elif sub == 'remove_scheduler_db': ret['ret'] = LogicSelf.remove_scheduler_db_from_id(request.form['db_id']) ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) elif sub == 'remove_scheduler': ret['ret'] = LogicSelf.remove_scheduler(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) # self - group elif sub == 'load_group': ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'add_group': ret['ret'] = LogicSelf.add_group(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'remove_group': ret['ret'] = LogicSelf.remove_group(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'add_group_child': ret['ret'] = LogicSelf.add_group_child(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'remove_group_child': ret['ret'] = LogicSelf.remove_group_child(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) # self - search elif sub == 'list': ret = LogicSearchSelf.get_list_by_web(request) return jsonify(ret) # 토렌트 인포 elif sub == 'torrent_info': try: from torrent_info import Logic as TorrentInfoLogic data = request.form['hash'] logger.debug(data) if data.startswith('magnet'): ret = TorrentInfoLogic.parse_magnet_uri(data) else: ret = TorrentInfoLogic.parse_torrent_url(data) return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'server_test': logger.debug('server_test') """ from sqlalchemy import desc from bot_downloader_movie.model import ModelMovieItem import json datas = db.session.query(ModelMovieItem).order_by(ModelMovieItem.id).limit(7000).all() for data in datas: response = requests.post("https://sjva.me/sjva/torrent_%s.php" % 'movie', data={'data':json.dumps(data.as_dict())}) """ group_name = 'AV' save_list = LogicSearchSelf.get_list(call='api', group=group_name) logger.debug(len(save_list)) save_list = save_list[:10] if app.config['config']['is_server'] or app.config['config']['is_debug']: from tool_expand import TorrentProcess TorrentProcess.server_process(save_list, category=group_name) return "" #return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return jsonify('fail')
def process_ajax(self, sub, req): if sub == "install": return jsonify(self.install()) if sub == "is_installed": try: is_installed = self.is_installed() if is_installed: ret = {"installed": True, "version": is_installed} else: ret = {"installed": False} return jsonify(ret) except Exception as e: logger.error("Exception:%s", e) logger.error(traceback.format_exc()) if sub == "uninstall": return jsonify(self.uninstall()) if sub == "cache": try: p = request.form.to_dict() if request.method == "POST" else request.args.to_dict() action = p.get("action", "") infohash = p.get("infohash", "") name = p.get("name", "") if action == "clear": self.torrent_cache.clear() elif action == "delete" and infohash: for h in infohash.split(","): if h and h in self.torrent_cache: del self.torrent_cache[h] # filtering if name: info = (val["info"] for val in self.torrent_cache.values() if name.strip() in val["info"]["name"]) elif infohash: info = (self.torrent_cache[h]["info"] for h in infohash.split(",") if h and h in self.torrent_cache) else: info = (val["info"] for val in self.torrent_cache.values()) info = sorted(info, key=lambda x: x["creation_date"], reverse=True) total = len(info) if p.get("c", ""): counter = int(p.get("c")) pagesize = ModelSetting.get_int("list_pagesize") if counter == 0: info = info[:pagesize] elif counter == len(info): info = [] else: info = info[counter : counter + pagesize] # return if action == "list": return jsonify({"success": True, "info": info, "total": total}) return jsonify({"success": True, "count": len(info)}) except Exception as e: logger.error("Exception:%s", e) logger.error(traceback.format_exc()) return jsonify({"success": False, "log": str(e)}) if sub == "tracker_update": try: self.update_tracker() return jsonify({"success": True}) except Exception as e: logger.error("Exception:%s", e) logger.error(traceback.format_exc()) return jsonify({"success": False, "log": str(e)}) if sub == "tracker_save": try: self.tracker_save(request) return jsonify({"success": True}) except Exception as e: logger.error("Exception:%s", e) logger.error(traceback.format_exc()) return jsonify({"success": False, "log": str(e)}) if sub == "torrent_info": # for global use - default arguments by function itself try: from torrent_info import Logic as TorrentInfoLogic data = request.form["hash"] logger.debug(data) if data.startswith("magnet"): ret = TorrentInfoLogic.parse_magnet_uri(data) else: ret = TorrentInfoLogic.parse_torrent_url(data) return jsonify(ret) except Exception as e: logger.error("Exception:%s", e) logger.error(traceback.format_exc()) if sub == "get_torrent_info": # for local use - default arguments from user db try: if request.form["uri_url"].startswith("magnet"): torrent_info = self.parse_magnet_uri(request.form["uri_url"]) else: torrent_info = self.parse_torrent_url(request.form["uri_url"]) return jsonify({"success": True, "info": torrent_info}) except Exception as e: logger.error("Exception:%s", e) logger.error(traceback.format_exc()) return jsonify({"success": False, "log": str(e)}) if sub == "get_file_info": try: fs = request.files["file"] fs.seek(0) torrent_file = fs.read() torrent_info = self.parse_torrent_file(torrent_file) return jsonify({"success": True, "info": torrent_info}) except Exception as e: logger.error("Exception:%s", str(e)) logger.error(traceback.format_exc()) return jsonify({"success": False, "log": str(e)}) if sub == "get_torrent_file" and request.method == "GET": try: data = request.args.to_dict() magnet_uri = data.get("uri", "") if not magnet_uri.startswith("magnet"): magnet_uri = "magnet:?xt=urn:btih:" + magnet_uri torrent_file, torrent_name = self.parse_magnet_uri(magnet_uri, no_cache=True, to_torrent=True) resp = Response(torrent_file) resp.headers["Content-Type"] = "application/x-bittorrent" resp.headers["Content-Disposition"] = "attachment; filename*=UTF-8''" + quote(torrent_name + ".torrent") return resp except Exception as e: return jsonify({"success": False, "log": str(e)})
def ajax(sub): try: ret = {} # self - setting if sub == 'setting_save': ret = ModelSetting.setting_save(request) return jsonify(ret) elif sub == 'scheduler': go = request.form['scheduler'] logger.debug('scheduler :%s', go) if go == 'true': Logic.scheduler_start() else: Logic.scheduler_stop() return jsonify(go) elif sub == 'one_execute': ret = Logic.one_execute() return jsonify(ret) elif sub == 'reset_db': ret = Logic.reset_db() return jsonify(ret) # self - site elif sub == 'load_site': ret['site'] = ModelSite2.get_list(by_dict=True) return jsonify(ret) elif sub == 'test': ret = LogicSelf.action_test(request) return jsonify(ret) elif sub == 'site_delete': ret['ret'] = ModelSite2.delete(request.form['site_id']) ret['site'] = ModelSite2.get_list(by_dict=True) return jsonify(ret) elif sub == 'site_edit': ret['ret'] = LogicSelf.site_edit(request) ret['site'] = ModelSite2.get_list(by_dict=True) return jsonify(ret) # self - scheduler elif sub == 'load_scheduler': ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) elif sub == 'add_scheduler': ret['ret'] = LogicSelf.add_scheduler(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) elif sub == 'remove_scheduler_db': ret['ret'] = LogicSelf.remove_scheduler_db_from_id( request.form['db_id']) ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) elif sub == 'remove_scheduler': ret['ret'] = LogicSelf.remove_scheduler(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['scheduler'] = LogicSelf.get_scheduler_list() return jsonify(ret) # self - group elif sub == 'load_group': ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'add_group': ret['ret'] = LogicSelf.add_group(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'remove_group': ret['ret'] = LogicSelf.remove_group(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'add_group_child': ret['ret'] = LogicSelf.add_group_child(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) elif sub == 'remove_group_child': ret['ret'] = LogicSelf.remove_group_child(request) ret['site'] = ModelSite2.get_list(by_dict=True) ret['group'] = LogicSelf.get_group_list() ret['info'] = LogicSelf.get_search_form_info() return jsonify(ret) # self - search elif sub == 'list': ret = LogicSearchSelf.get_list_by_web(request) return jsonify(ret) # 토렌트 인포 elif sub == 'torrent_info': try: from torrent_info import Logic as TorrentInfoLogic data = request.form['hash'] logger.debug(data) if data.startswith('magnet'): ret = TorrentInfoLogic.parse_magnet_uri(data) else: ret = TorrentInfoLogic.parse_torrent_url(data) return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'server_test': logger.debug('server_test') from framework.common.torrent.process import TorrentProcess tmp = db.session.query(ModelBbs2).all() ret = TorrentProcess.server_process(tmp, category='AV') return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return jsonify('fail')
def ajax(sub): # 설정 저장 if sub == 'setting_save': try: ret = Logic.setting_save(request) return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'install': try: ret = Logic.install() return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'is_installed': try: is_installed = Logic.is_installed() if is_installed: ret = {'installed': True, 'version': is_installed} else: ret = {'installed': False} return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'cache': try: if request.form.get('clear', False): Logic.torrent_cache.clear() info = [val['info'] for _, val in Logic.torrent_cache.iteritems()] return jsonify({'success': True, 'info': info}) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return jsonify({'success': False, 'log': str(e)}) elif sub == 'tracker_update': try: Logic.update_tracker() return jsonify({'success': True}) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return jsonify({'success': False, 'log': str(e)}) elif sub == 'tracker_save': try: Logic.tracker_save(request) return jsonify({'success': True}) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return jsonify({'success': False, 'log': str(e)}) elif sub == 'torrent_info': # for global use - default arguments by function itself try: from torrent_info import Logic as TorrentInfoLogic data = request.form['hash'] logger.debug(data) if data.startswith('magnet'): ret = TorrentInfoLogic.parse_magnet_uri(data) else: ret = TorrentInfoLogic.parse_torrent_url(data) return jsonify(ret) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) elif sub == 'get_torrent_info': # for local use - default arguments from user db try: if request.form['uri_url'].startswith('magnet'): arg = ModelSetting.to_dict() func_args = { 'scrape': arg['scrape'] == 'True', 'use_dht': arg['use_dht'] == 'True', 'force_dht': arg['force_dht'] == 'True', 'timeout': int(arg['timeout']), 'n_try': int(arg['n_try']), } torrent_info = Logic.parse_magnet_uri(request.form['uri_url'], **func_args) else: torrent_info = Logic.parse_torrent_url(request.form['uri_url']) return jsonify({'success': True, 'info': torrent_info}) except Exception as e: logger.error('Exception:%s', e) logger.error(traceback.format_exc()) return jsonify({'sueecss': False, 'log': str(e)}) elif sub == 'get_file_info': try: fs = request.files['file'] fs.seek(0) torrent_file = fs.read() torrent_info = Logic.parse_torrent_file(torrent_file) return jsonify({'success': True, 'info': torrent_info}) except Exception as e: logger.error('Exception:%s', str(e)) logger.error(traceback.format_exc()) return jsonify({'success': False, 'log': str(e)})