Esempio n. 1
0
async def chapter(request):
    """
    返回小说章节目录页
    : content_url   这决定当前U页面url的生成方式
    : url           章节目录页源url
    : novels_name   小说名称
    :return: 小说章节内容页
    """
    url = request.args.get('url', None)
    novels_name = request.args.get('novels_name', None)
    netloc = get_netloc(url)
    if netloc not in RULES.keys():
        return redirect(url)
    if netloc in REPLACE_RULES.keys():
        url = url.replace(REPLACE_RULES[netloc]['old'],
                          REPLACE_RULES[netloc]['new'])
    content_url = RULES[netloc].content_url
    content = await cache_owllook_novels_chapter(url=url, netloc=netloc)
    if content:
        content = str(content).strip('[],, Jjs').replace(', ', '').replace(
            'onerror', '').replace('js', '').replace('加入书架', '')
        return template('chapter.html',
                        novels_name=novels_name,
                        url=url,
                        content_url=content_url,
                        soup=content)
    else:
        return text('解析失败,请将失败页面反馈给本站,请重新刷新一次,或者访问源网页:{url}'.format(url=url))
Esempio n. 2
0
async def owl_novels_chapters(request):
    """
    返回章节目录 基本达到通用
    :param request: 
    :param chapter_url: 章节源目录页url
    :param novels_name: 小说名称
    :return: 小说目录信息
    """
    chapters_url = request.args.get('chapters_url', None)
    novels_name = request.args.get('novels_name', None)
    netloc = get_netloc(chapters_url)
    try:
        res = await cache_owllook_novels_chapter(url=chapters_url,
                                                 netloc=netloc)
        chapters_sorted = []
        if res:
            chapters_sorted = extract_chapters(chapters_url, res)
            result = {'status': 200}
        else:
            result = {'status': 204}
        result.update({
            'data': {
                'novels_name': novels_name,
                'chapter_url': chapters_url,
                'all_chapters': chapters_sorted
            },
            'msg': "ok"
        })
    except Exception as e:
        LOGGER.exception(e)
        result = {'status': 500, 'msg': e}
    result.update({'finished_at': get_time()})
    return response.json(result)
Esempio n. 3
0
async def owl_novels_chapters(request, **kwargs):
    """
    返回章节目录 基本达到通用
    :param request: 
    :param chapter_url: 章节源目录页url
    :param novels_name: 小说名称
    :return: 小说目录信息
    """
    request_params = kwargs["request_params"]
    chapters_url = request_params.get('chapters_url', None)
    novels_name = request_params.get('novels_name', None)
    netloc = get_netloc(chapters_url)
    try:
        res = await cache_owllook_novels_chapter(url=chapters_url, netloc=netloc)
        chapters_sorted = []
        if res:
            chapters_sorted = extract_chapters(chapters_url, res)
        UniResponse.SUCCESS.update({ResponseField.DATA: {
            'novels_name': novels_name,
            'chapter_url': chapters_url,
            'all_chapters': chapters_sorted
        }, ResponseField.FINISH_AT: get_time()})
        return response_handle(request, UniResponse.SUCCESS, 200)
    except Exception as e:
        LOGGER.exception(e)
        return response_handle(request, UniResponse.SERVER_UNKNOWN_ERR, 500)
Esempio n. 4
0
async def chapter(request):
    """
    返回小说章节目录页
    : content_url   这决定当前U页面url的生成方式
    : url           章节目录页源url
    : novels_name   小说名称
    :return: 小说章节内容页
    """
    url = request.args.get('url', None)
    novels_name = request.args.get('novels_name', None)
    netloc = get_netloc(url)
    if netloc not in RULES.keys():
        return redirect(url)
    if netloc in REPLACE_RULES.keys():
        url = url.replace(REPLACE_RULES[netloc]['old'],
                          REPLACE_RULES[netloc]['new'])
    content_url = RULES[netloc].content_url
    content = await cache_owllook_novels_chapter(url=url, netloc=netloc)
    if content:
        content = str(content).strip('[],, Jjs').replace(', ', '').replace(
            'onerror', '').replace('js', '').replace('加入书架', '')
        if request.args.get('add_kindle', None):
            h = areader()
            h.feed(content)
            if (content_url == '1'):
                content_url = ''
            elif (content_url == '0'):
                content_url = url
            elif (content_url == '-1'):
                content_url = url
            (a, b) = h.chapters[0]
            link = "http://127.0.0.1:8001/owllook_content?url=" + content_url + "%s&name=%s&chapter_url=" + url + "&novels_name=%s"
            s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            s.connect(('127.0.0.1', 31419))
            f = open('/tmp/ow_links', 'w')
            print(len(h.chapters))
            jjj.dump([{
                'title':
                title,
                'url':
                link % (curl, urllib.parse.quote(title),
                        urllib.parse.quote(novels_name))
            } for (title, curl) in h.chapters], f)
            f.close()
            s.send(
                pickle.dumps(
                    (novels_name, len(h.chapters), "*****@*****.**")))
            return redirect("https://fss.cjwddtc.win")
        return template('chapter.html',
                        novels_name=novels_name,
                        url=url,
                        content_url=content_url,
                        soup=content)
    else:
        return text('解析失败,请将失败页面反馈给本站,请重新刷新一次,或者访问源网页:{url}'.format(url=url))
Esempio n. 5
0
async def owllook_content(request):
    """
    返回小说章节内容页
    : content_url   这决定当前U页面url的生成方式
    : url           章节内容页源url
    : chapter_url   小说目录源url
    : novels_name   小说名称
    :return: 小说章节内容页
    """
    url = request.args.get('url', None)
    chapter_url = request.args.get('chapter_url', None)
    novels_name = request.args.get('novels_name', None)
    name = request.args.get('name', '')
    is_ajax = request.args.get('is_ajax', '')
    # 当小说内容url不在解析规则内 跳转到原本url
    netloc = get_netloc(url)
    if netloc not in RULES.keys():
        return redirect(url)
    user = request['session'].get('user', None)
    # 拼接小说目录url
    book_url = "/chapter?url={chapter_url}&novels_name={novels_name}".format(
        chapter_url=chapter_url,
        novels_name=novels_name)
    motor_db = motor_base.get_db()
    if url == chapter_url:
        # 阅读到最后章节时候 在数据库中保存最新阅读章节
        if user and is_ajax == "owl_cache":
            owl_referer = request.headers.get('Referer', '').split('owllook_content')[1]
            if owl_referer:
                latest_read = "/owllook_content" + owl_referer
                await motor_db.user_message.update_one(
                    {'user': user, 'books_url.book_url': book_url},
                    {'$set': {'books_url.$.last_read_url': latest_read}})
        return redirect(book_url)
    content_url = RULES[netloc].content_url
    content_data = await cache_owllook_novels_content(url=url, netloc=netloc)
    if content_data:
        try:
            content = content_data.get('content', '获取失败')
            next_chapter = content_data.get('next_chapter', [])
            title = content_data.get('title', '').replace(novels_name, '')
            name = title if title else name
            # 拼接小说书签url
            bookmark_url = "{path}?url={url}&name={name}&chapter_url={chapter_url}&novels_name={novels_name}".format(
                path=request.path,
                url=url,
                name=name,
                chapter_url=chapter_url,
                novels_name=novels_name
            )
            # 破坏广告链接
            content = str(content).strip('[]Jjs,').replace('http', 'hs')
            if user:
                bookmark = await motor_db.user_message.find_one({'user': user, 'bookmarks.bookmark': bookmark_url})
                book = await motor_db.user_message.find_one({'user': user, 'books_url.book_url': book_url})
                bookmark = 1 if bookmark else 0
                if book:
                    # 当书架中存在该书源
                    book = 1
                    # 保存最后一次阅读记录
                    if is_ajax == "owl_cache":
                        owl_referer = request.headers.get('Referer', bookmark_url).split('owllook_content')[1]
                        latest_read = "/owllook_content" + owl_referer
                        await motor_db.user_message.update_one(
                            {'user': user, 'books_url.book_url': book_url},
                            {'$set': {'books_url.$.last_read_url': latest_read}})
                else:
                    book = 0
                if is_ajax == "owl_cache":
                    owl_cache_dict = dict(
                        is_login=1,
                        user=user,
                        name=name,
                        url=url,
                        bookmark=bookmark,
                        book=book,
                        content_url=content_url,
                        chapter_url=chapter_url,
                        novels_name=novels_name,
                        next_chapter=next_chapter,
                        soup=content
                    )
                    return json(owl_cache_dict)
                return template(
                    'content.html',
                    is_login=1,
                    user=user,
                    name=name,
                    url=url,
                    bookmark=bookmark,
                    book=book,
                    content_url=content_url,
                    chapter_url=chapter_url,
                    novels_name=novels_name,
                    next_chapter=next_chapter,
                    soup=content)
            else:
                if is_ajax == "owl_cache":
                    owl_cache_dict = dict(
                        is_login=0,
                        name=name,
                        url=url,
                        bookmark=0,
                        book=0,
                        content_url=content_url,
                        chapter_url=chapter_url,
                        novels_name=novels_name,
                        next_chapter=next_chapter,
                        soup=content
                    )
                    return json(owl_cache_dict)
                return template(
                    'content.html',
                    is_login=0,
                    name=name,
                    url=url,
                    bookmark=0,
                    book=0,
                    content_url=content_url,
                    chapter_url=chapter_url,
                    novels_name=novels_name,
                    next_chapter=next_chapter,
                    soup=content)
        except Exception as e:
            LOGGER.exception(e)
            return redirect(book_url)
    else:
        if user:
            is_login = 1
            user = user
            return template('parse_error.html', url=url, is_login=is_login, user=user)
        else:
            is_login = 0
            return template('parse_error.html', url=url, is_login=is_login)
Esempio n. 6
0
async def owllook_content(request):
    """
    返回小说章节内容页
    : content_url   这决定当前U页面url的生成方式
    : url           章节内容页源url
    : chapter_url   小说目录源url
    : novels_name   小说名称
    :return: 小说章节内容页
    """
    url = request.args.get('url', None)
    chapter_url = request.args.get('chapter_url', None)
    novels_name = request.args.get('novels_name', None)
    name = request.args.get('name', '')
    # 当小说内容url不在解析规则内 跳转到原本url
    netloc = get_netloc(url)
    if netloc not in RULES.keys():
        return redirect(url)
    # 拼接小说目录url
    book_url = "/chapter?url={chapter_url}&novels_name={novels_name}".format(
        chapter_url=chapter_url,
        novels_name=novels_name)
    if url == chapter_url:
        return redirect(book_url)
    content_url = RULES[netloc].content_url
    content_data = await cache_owllook_novels_content(url=url, netloc=netloc)
    if content_data:
        user = request['session'].get('user', None)
        try:
            content = content_data.get('content', '获取失败')
            next_chapter = content_data.get('next_chapter', [])
            title = content_data.get('title', '').replace(novels_name, '')
            name = title if title else name
            # 拼接小说书签url
            bookmark_url = "{path}?url={url}&name={name}&chapter_url={chapter_url}&novels_name={novels_name}".format(
                path=request.path,
                url=url,
                name=name,
                chapter_url=chapter_url,
                novels_name=novels_name
            )
            # 破坏广告链接
            content = str(content).strip('[]Jjs,').replace('http', 'hs')
            if user:
                motor_db = motor_base.db
                bookmark = await motor_db.user_message.find_one({'user': user, 'bookmarks.bookmark': bookmark_url})
                book = await motor_db.user_message.find_one({'user': user, 'books_url.book_url': book_url})
                bookmark = 1 if bookmark else 0
                if book:
                    # 当书架中存在该书源
                    book = 1
                    # 保存最后一次阅读记录
                    await motor_db.user_message.update_one(
                        {'user': user, 'books_url.book_url': book_url},
                        {'$set': {'books_url.$.last_read_url': bookmark_url}})
                else:
                    book = 0
                return template(
                    'content.html',
                    is_login=1,
                    user=user,
                    name=name,
                    url=url,
                    bookmark=bookmark,
                    book=book,
                    content_url=content_url,
                    chapter_url=chapter_url,
                    novels_name=novels_name,
                    next_chapter=next_chapter,
                    soup=content)
            else:
                return template(
                    'content.html',
                    is_login=0,
                    name=name,
                    url=url,
                    bookmark=0,
                    book=0,
                    content_url=content_url,
                    chapter_url=chapter_url,
                    novels_name=novels_name,
                    next_chapter=next_chapter,
                    soup=content)
        except Exception as e:
            LOGGER.exception(e)
            return redirect(book_url)
    else:
        return text('解析失败或者是没有下一页了,请将失败页面反馈给本站,请重新刷新一次,或者访问源网页:{url}'.format(url=url))