Example #1
0
    def __get_torrent_info(magnet_list, scheduler_instance):
        ret = None
        try:
            #if not ModelSetting.get_bool('use_torrent_info'):
            #    return ret
            # 스케쥴링
            if scheduler_instance is not None:
                if not scheduler_instance.use_torrent_info:
                    return ret
            else:
                #테스트
                if not ModelSetting.get_bool('use_torrent_info'):
                    return ret

            ret = []
            from torrent_info import Logic as TorrentInfoLogic
            for m in magnet_list:
                logger.debug('Get_torrent_info:%s', m)
                for i in range(1):
                    tmp = None
                    try:
                        tmp = TorrentInfoLogic.parse_magnet_uri(m,
                                                                no_cache=True)
                    except:
                        logger.debug('Timeout..')
                    if tmp is not None:
                        break

                if tmp is not None:
                    ret.append(tmp)
                    #ret[m] = tmp
        except Exception as e:
            logger.debug('Exception:%s', e)
            logger.debug(traceback.format_exc())
        return ret
Example #2
0
 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)
Example #3
0
 def make_torrent_info(self):
     try:
         if self.job.use_tracer and self.torrent_info is None and self.link.startswith('magnet'):
             from torrent_info import Logic as TorrentInfoLogic
             tmp = TorrentInfoLogic.parse_magnet_uri(self.link)
             if tmp is not None:
                 self.torrent_info = tmp
                 flag_modified(self, "torrent_info")
                 info = Util.get_max_size_fileinfo(tmp)
                 self.filename = info['filename']
                 self.dirname = info['dirname']
                 self.filecount = tmp['num_files']
                 return True
     except Exception as e: 
         logger.error('Exception:%s', e)
         logger.error(traceback.format_exc())
     return False
Example #4
0
    def process_ajax(self, sub, req):
        try:
            p = request.form.to_dict(
            ) if request.method == 'POST' else request.args.to_dict()
            if sub == 'list':
                search = p.get('search', '')
                page = p.get('page', '1')
                b_id = p.get('b_id')

                ret = self.tf_list(b_id, page=page, search=search)
                return jsonify({
                    'success': True,
                    'list': ret,
                    'nomore': len(ret) != 35
                })
            elif sub == 'get_src_url':
                href = p.get('href', '')
                if href:
                    src_url = ModelSetting.get('site_url').rstrip(
                        '/') + '/board.php?' + href.split('?')[1]
                    return jsonify({'success': True, 'url': src_url})
            elif sub == 'get_torrent_info':
                href = p.get('href', '')
                if href:
                    query_string = href.split('?')[1]
                    item_no = int(parse_qs(query_string).get('item_no', '0'))
                    fcontent, _ = self.tf_down(query_string, item_no=item_no)
                    from torrent_info import Logic as TorrentInfoLogic
                    return jsonify({
                        'success':
                        True,
                        'info':
                        TorrentInfoLogic.parse_torrent_file(fcontent)
                    })
            elif sub == 'get_more':
                href = p.get('href', '')
                if href:
                    src_url = ModelSetting.get('site_url').rstrip(
                        '/') + '/board.php?' + href.split('?')[1]
                    items = self.tf_view(src_url)['items']
                    if items and len(items) > 0:
                        return jsonify({'success': True, 'items': items})
                    else:
                        return jsonify({
                            'success': False,
                            'log': '다운로드 가능한 링크를 찾을 수 없음'
                        })
            elif sub == 'add_download':
                try:
                    import downloader
                    magnet = p.get('magnet', '')
                    path_id = p.get('download_path_id')
                    path_id = int(path_id.split('_')[1])
                    path_list = [''] + [
                        x.strip()
                        for x in ModelSetting.get('download_path').split('\n')
                        if x.strip()
                    ]
                    download_path = path_list[path_id]
                    result = downloader.Logic.add_download2(
                        magnet,
                        ModelSetting.get('download_program'),
                        download_path,
                        request_type=package_name,
                        request_sub_type='')
                    logger.debug(result)
                    return jsonify({'success': True})
                except Exception as e:
                    raise e
        except Exception as e:
            logger.error('Exception: %s', str(e))
            logger.error(traceback.format_exc())
            return jsonify({'success': False, 'log': str(e)})
            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)


    def process_api(self, sub, req):
        if sub == 'add_download':
            ret = self.add_download_api(request)
            return jsonify(ret)
Example #6
0
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')
Example #7
0
    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)})
Example #8
0
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')
Example #9
0
    def server_process_av(cls, save_list, av_type):
        lists = []
        for item in save_list:
            item = item.as_dict()
            logger.debug(item['title'])
            #av_type = item['board']
            # 2020-05-31 javdb,141jav-NONE, avnori-torrent_ymav, javnet censored_tor
            #av_type = 'censored' if av_type in ['NONE', 'torrent_ymav', 'censored_tor'] else av_type
            #av_type = 'uncensored' if av_type in ['torrent_nmav', 'uncensored_tor'] else av_type
            #av_type = 'western' if av_type in ['torrent_amav', 'white_tor'] else av_type

            #logger.debug(json.dumps(item, indent=4))
            
            if item['torrent_info'] is None:
                from torrent_info import Logic as TorrentInfoLogic
                for m in item['magnet']:
                    logger.debug('Get_torrent_info:%s', m)
                    for i in range(1):
                        tmp = None
                        try:
                            tmp = TorrentInfoLogic.parse_magnet_uri(m, no_cache=True)
                        except:
                            logger.debug('Timeout..')
                        if tmp is not None:
                            break
                    if tmp is not None:
                        if item['torrent_info'] is None:
                            item['torrent_info'] = []
                        item['torrent_info'].append(tmp)



            if item['torrent_info'] is not None:
                # 하나의 마그넷 단위
                try:
                    for info in item['torrent_info']:


                        fileinfo = cls.get_max_size_fileinfo(info)
                        av = cls.server_process_av2(fileinfo['filename'], av_type)
                        #logger.debug(fileinfo)
                        #logger.debug(json.dumps(av, indent=4))

                        #2020-05-31 검색안되는건 그냥 방송안함.
                        if av is None:
                            logger.debug(u'AV 검색 실패')
                            logger.debug(fileinfo['filename'])
                            #logger.debug(av_type)
                            continue
                        
                        if info['num_files'] > 30:
                            continue
                        try:
                            if fileinfo['filename'].lower().find('ch_sd') != -1:
                                continue
                        except: pass
                        torrent_info = {}
                        torrent_info['name'] = info['name']
                        torrent_info['size'] = info['total_size']
                        torrent_info['num'] = info['num_files']
                        torrent_info['hash'] = info['info_hash']
                        torrent_info['filename'] = fileinfo['filename']
                        torrent_info['dirname'] = fileinfo['dirname']
                        torrent_info['url'] = item['url']

                        av_info = None
                        if av is not None:
                            av_info = {}
                            av_info['meta'] = av['type']
                            av_info['code_show'] = av['data']['originaltitle']
                            av_info['title'] = av['data']['title']
                            try:
                                av_info['poster'] = av['data']['thumb'][1]['value']
                            except:
                                try:
                                    av_info['poster'] = av['data']['thumb'][0]['value']
                                except:
                                    av_info['poster'] = None
                            av_info['genre'] = av['data']['genre']
                            if av_info['genre'] is None:
                                av_info['genre'] = []
                            av_info['performer'] = []
                            if av['data']['actor'] is not None:
                                for actor in av['data']['actor']:
                                    av_info['performer'].append(actor['name'])
                            av_info['studio'] = av['data']['studio']
                            av_info['date'] = av['data']['premiered']
                            av_info['trailer'] = ''
                            if av['data']['extras'] is not None and len(av['data']['extras']) > 0:
                                av_info['trailer'] = av['data']['extras'][0]['content_url']
                        else:
                            logger.debug('AV 검색 실패')
                            logger.debug(fileinfo['filename'])
                            #av_info = {}
                            #av_info['title'] = info['name']
                        
                        ret = {'av_type' :av_type}
                        ret['server_id'] = item['id']
                        if av_info is not None:
                            ret['av'] = av_info
                        ret['t'] = torrent_info
                        lists.append(ret)

                        # 방송
                        telegram = {}
                        telegram['plugin'] = 'bot_downloader_av'
                        telegram['data'] = ret
                        
                        text = json.dumps(telegram, indent=2)
                        from framework.common.telegram_bot import TelegramBot
                        TelegramBot.super_send_message(text)
                        time.sleep(0.5)
                        #return lists
                        
                except Exception as exception: 
                    logger.error('Exception:%s', exception)
                    logger.error(traceback.format_exc())     


                
        return lists
Example #10
0
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)})