Beispiel #1
0
 def process_insert_feed():
     try:
         job_list = ModelOffcloud2Job.get_list()
         for job in job_list:
             try:
                 logger.debug('Offcloud job:%s', job.id)
                 feed_list = RssUtil.get_rss(job.rss_url)
                 if not feed_list:
                     continue
                 flag_commit = False
                 count = 0
                 #
                 for feed in reversed(feed_list):
                     if db.session.query(ModelOffcloud2Item).filter_by(
                             job_id=job.id, link=feed.link).first() is None:
                         r = ModelOffcloud2Item()
                         r.title = feed.title
                         r.link = feed.link
                         #db.session.add(r)
                         job.rss_list.append(r)
                         flag_commit = True
                         count += 1
                 if flag_commit:
                     db.session.commit()
                 logger.debug('Offcloud job:%s flag_commit:%s count:%s',
                              job.id, flag_commit, count)
             except Exception as e:
                 logger.error(e)
                 logger.error(traceback.format_exc())
     except Exception as e:
         logger.error(e)
         logger.error(traceback.format_exc())
Beispiel #2
0
def api(sub):
    try:
        # 텔레그램 & sjva.me
        if sub == 'cache_download':
            ret = LogicCache.cache_download(request)
            return jsonify(ret)
        elif sub == 'rss':
            ret = ModelOffcloud2Item.api_list(request)
            data = []
            for t in ret:
                item = {}
                item['title'] = t.title
                item['link'] = t.link
                item['created_time'] = t.created_time
                data.append(item)
            from framework.common.rss import RssUtil
            xml = RssUtil.make_rss(package_name, data)
            return Response(xml, mimetype='application/xml')
        elif sub == 'cache':
            ret = ModelOffcloud2Cache.api_list(request)
            data = []
            for t in ret:
                item = {}
                item['title'] = t.name
                item['link'] = t.magnet
                item['created_time'] = t.created_time
                data.append(item)
            from framework.common.rss import RssUtil
            xml = RssUtil.make_rss(package_name, data)
            return Response(xml, mimetype='application/xml')
        elif sub == 'hash':
            ret = LogicBase.hash(request)
            return jsonify(ret)
        elif sub == 'add_remote':
            ret = LogicBase.add_remote_default_setting(request)
            logger.debug(ret)
            return jsonify(ret)
    except Exception as e: 
        logger.error('Exception:%s', e)
        logger.error(traceback.format_exc())
 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)
         data = []
         for t in ret:
             item = {}
             item['title'] = t.filename
             item['link'] = t.magnet
             item['created_time'] = t.created_time
             data.append(item)
         from framework.common.rss import RssUtil
         xml = RssUtil.make_rss(package_name, data)
         return Response(xml, mimetype='application/xml')
 def process_api(self, sub, req):
     if sub == 'add_download':
         db_id = request.args.get('id')
         ret = self.add_download(db_id)
         return jsonify(ret)
     elif sub == 'rss':
         ret = ModelItem.api_list(request)
         data = []
         for item in ret:
             entity = {}
             entity['title'] = '[%s] %s' % (item.code, item.filename)
             entity['link'] = item.magnet
             entity['created_time'] = item.created_time
             data.append(entity)
         logger.debug(ret)
         logger.debug(data)
         from framework.common.rss import RssUtil
         xml = RssUtil.make_rss(package_name, data)
         return Response(xml, mimetype='application/xml')
Beispiel #5
0
def api(sub):
    try:
        if sub == 'add_download':
            ret = LogicNormal.add_download_api(request)
            return jsonify(ret)
        elif sub == 'rss':
            ret = ModelBotDownloaderKtvItem.itemlist_by_api(request)
            data = []
            for t in ret:
                item = {}
                item['title'] = t.filename
                item['link'] = t.magnet
                item['created_time'] = t.created_time
                data.append(item)
            from framework.common.rss import RssUtil
            xml = RssUtil.make_rss(package_name, data)
            return Response(xml, mimetype='application/xml')

    except Exception as e:
        logger.error('Exception:%s', e)
        logger.error(traceback.format_exc())
Beispiel #6
0
 def process_insert_feed():
     try:
         rss_list = ModelRss.get_list()
         for rss in rss_list:
             try:
                 logger.debug('Rss :%s', rss.id)
                 feed_list = RssUtil.get_rss(rss.rss_url)
                 #logger.debug(feed_list)
                 if not feed_list:
                     continue
                 flag_commit = False
                 count = 0
                 #
                 for feed in reversed(feed_list):
                     if ModelSetting.get_bool('allow_duplicate'):
                         entity = db.session.query(ModelFeed).filter_by(
                             rss_id=rss.id, link=feed.link).first()
                     else:
                         entity = db.session.query(ModelFeed).filter_by(
                             link=feed.link).first()
                     if entity is None:
                         r = ModelFeed()
                         r.title = feed.title
                         r.link = feed.link
                         #db.session.add(r)
                         rss.feed_list.append(r)
                         flag_commit = True
                         count += 1
                 if flag_commit:
                     db.session.commit()
                 logger.debug('Rss:%s flag_commit:%s count:%s', rss.id,
                              flag_commit, count)
             except Exception as e:
                 logger.error(e)
                 logger.error(traceback.format_exc())
     except Exception as e:
         logger.error(e)
         logger.error(traceback.format_exc())
Beispiel #7
0
def api(sub):
    try:
        if sub == 'add_download':
            db_id = request.args.get('id')
            ret1 = LogicNormal.add_download(db_id)
            return jsonify(ret1)
        elif sub == 'rss':
            ret = ModelItem.api_list(request)
            data = []
            for item in ret:
                entity = {}
                entity['title'] = '[%s] %s' % (item.code, item.filename)
                entity['link'] = item.magnet
                entity['created_time'] = item.created_time
                data.append(entity)
            logger.debug(ret)
            logger.debug(data)
            from framework.common.rss import RssUtil
            xml = RssUtil.make_rss(package_name, data)
            return Response(xml, mimetype='application/xml')
    except Exception as e:
        logger.error('Exception:%s', e)
        logger.error(traceback.format_exc())
Beispiel #8
0
def api(sub):
    try:
        if sub == 'add_download':
            db_id = request.args.get('id')
            ret1 = LogicNormal.add_download(db_id)
            ret2 = LogicNormal.add_download_sub(db_id, -1)
            return jsonify(ret1)
        elif sub == 'rss':
            ret = ModelMovieItem.api_list(request)
            data = []
            for item in ret:
                entity = {}
                entity['title'] = item.filename
                entity['link'] = item.magnet
                entity['created_time'] = item.created_time
                data.append(entity)
                if item.sub is not None:
                    for idx, sub in enumerate(item.sub):
                        url = '%s/%s/api/attach?id=%s_%s' % (
                            SystemModelSetting.get('ddns'), package_name,
                            item.id, idx)
                        if SystemModelSetting.get_bool('auth_use_apikey'):
                            url += '&apikey=%s' % SystemModelSetting.get(
                                'auth_apikey')
                        entity = {}
                        entity['title'] = sub[1]
                        entity['link'] = url
                        entity['created_time'] = item.created_time
                        data.append(entity)

            from framework.common.rss import RssUtil
            xml = RssUtil.make_rss(package_name, data)
            return Response(xml, mimetype='application/xml')
        elif sub == 'attach':
            tmp = request.args.get('id').split('_')
            entity = ModelMovieItem.get_by_id(tmp[0])
            if entity is not None:
                import requests
                import io
                session = requests.Session()

                if entity.sub[int(tmp[1])][2] != 'NONE':
                    logger.debug('url : %s', entity.sub[int(tmp[1])][2])
                    page = get_html(session,
                                    entity.sub[int(tmp[1])][2],
                                    stream=True)
                else:
                    logger.debug('url : %s', entity.url)
                    logger.debug('url : %s', entity.sub[int(tmp[1])][0])
                    page = get_html(session, entity.url)
                    page = get_html(session,
                                    entity.sub[int(tmp[1])][0],
                                    referer=entity.url,
                                    stream=True)

                byteio = io.BytesIO()
                for chunk in page.iter_content(1024):
                    byteio.write(chunk)

                filedata = byteio.getvalue()
                logger.debug('LENGTH : %s', len(filedata))

                attach_filename = entity.sub[int(tmp[1])][1]
                if ModelSetting.get_bool('sub_change_filename'):
                    ext = os.path.splitext(attach_filename)[1].lower()
                    if ext in ['.smi', '.srt', '.ass']:
                        attach_filename = '%s%s' % (os.path.splitext(
                            entity.filename)[0], ext)

                logger.debug('filename : %s', attach_filename)
            return send_file(io.BytesIO(filedata),
                             mimetype='application/octet-stream',
                             as_attachment=True,
                             attachment_filename=attach_filename)
    except Exception as e:
        logger.error('Exception:%s', e)
        logger.error(traceback.format_exc())
Beispiel #9
0
    def make_rss(title,
                 rss_list,
                 torrent_mode,
                 ddns,
                 is_bot=False,
                 search_word=None):
        from framework.common.rss import RssUtil
        xml = '<rss xmlns:showrss="http://showrss.info/" version="2.0">\n'
        xml += '\t<channel>\n'
        xml += '\t\t<title>' + '%s</title>\n' % title
        xml += '\t\t<link></link>\n'
        xml += '\t\t<description></description>\n'
        magnet_flag = False
        for bbs in rss_list:
            _dict = bbs.as_dict()
            if bbs.torrent_info is None and 'magnet' in _dict and _dict[
                    'magnet'] is not None:
                for magnet in _dict['magnet']:
                    magnet_flag = True
                    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' % magnet
                    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

            else:
                if bbs.torrent_info is not None:
                    for info in bbs.torrent_info:
                        magnet_flag = True
                        item_str = '\t\t<item>\n'
                        if search_word is not None and search_word != '' and info[
                                'name'].find(search_word) == -1:
                            continue
                        tmp = '\t\t\t<title>%s</title>\n' % RssUtil.replace_xml(
                            info['name'])
                        item_str += tmp
                        item_str += '\t\t\t<link>magnet:?xt=urn:btih:%s</link>\n' % info[
                            'info_hash']
                        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

            if _dict['files']:
                for index, download in enumerate(_dict['files']):
                    try:
                        item_str = '\t\t<item>\n'
                        if magnet_flag and download[1].lower().endswith(
                                '.torrent'):
                            continue
                        item_str += '\t\t\t<title>%s</title>\n' % RssUtil.replace_xml(
                            download[1])
                        url = '%s/%s/api/download/%s_%s' % (ddns, package_name,
                                                            bbs.id, index)
                        if SystemModelSetting.get_bool('auth_use_apikey'):
                            url += '?apikey=%s' % SystemModelSetting.get(
                                'auth_apikey')
                        item_str += '\t\t\t<link>%s</link>\n' % url
                        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 e:
                        logger.debug('Exception:%s', e)
                        logger.debug(traceback.format_exc())

        xml += '\t</channel>\n'
        xml += '</rss>'
        return xml
Beispiel #10
0
    def process_insert_feed():
        try:
            job_list = ModelOffcloud2Job.get_list()
            for job in job_list:
                try:
                    logger.debug('Offcloud job:%s', job.id)
                    feed_list = RssUtil.get_rss(job.rss_url)
                    if not feed_list:
                        continue
                    flag_commit = False
                    count = 0
                    #
                    try:
                        values = [x.strip() for x in job.rss_regex.split('\n')]
                        regex_list = Util.get_list_except_empty(values)
                    except:
                        regex_list = []
                    #logger.warning(regex_list)
                    #logger.warning(job.rss_mode)
                    for feed in reversed(feed_list):
                        if db.session.query(ModelOffcloud2Item).filter_by(
                                job_id=job.id, link=feed.link).first() is None:
                            # 2021-05-21
                            if job.rss_mode:  #화이트리스트
                                flag_append = False
                                try:
                                    for regex in regex_list:
                                        if re.compile(regex).search(
                                                feed.title):
                                            flag_append = True
                                            break
                                except Exception as e:
                                    logger.error(e)
                                    logger.error(traceback.format_exc())
                                if flag_append == False:
                                    continue
                            else:  #블랙리스트
                                flag_append = True
                                try:
                                    for regex in regex_list:
                                        if re.compile(regex).search(
                                                feed.title):
                                            flag_append = False
                                            break
                                except Exception as e:
                                    logger.error(e)
                                    logger.error(traceback.format_exc())
                            if flag_append == False:
                                continue

                            r = ModelOffcloud2Item()
                            r.title = u'%s' % feed.title
                            r.link = feed.link
                            #db.session.add(r)
                            job.rss_list.append(r)
                            flag_commit = True
                            count += 1
                    if flag_commit:
                        db.session.commit()
                    logger.debug('Offcloud job:%s flag_commit:%s count:%s',
                                 job.id, flag_commit, count)
                except Exception as e:
                    logger.error(e)
                    logger.error(traceback.format_exc())
        except Exception as e:
            logger.error(e)
            logger.error(traceback.format_exc())