예제 #1
0
def administer_page():
    if request.method == 'POST':
        st = CacheSetting.getInstance()
        return custom_render_template("page_administer.html")
    else:
        st = CacheSetting.getInstance()
        return custom_render_template("page_administer.html")
예제 #2
0
def show_download_page(fid, uuid_key):
    redis_cache = MyRedisCache.getInstance()
    url = redis_cache.get(generate_flag(search_flag, uuid_key))                  # uuid:file_url键对, 未注册用户有5分钟超时
    if url:
        one_download = {"fid": fid, "uuid": uuid_key}
        return custom_render_template("page_download.html", exist=True, form=one_download)  # will generate download-url
    else:
        return custom_render_template("page_download.html", exist=False, msg=_("URL does not exist!"))
예제 #3
0
    def decorated_view(*args, **kwargs):

        if current_user.is_anonymous:
            # 游客下载限制
            msg = check_anonymous(session.get('fppkcookie'),
                                  request.remote_addr)
            if msg:
                flash(msg, 'error')
                return custom_render_template("page_home.html",
                                              form=SearchForm())
        elif current_user.brick <= 0:
            # 免费下载检查
            num, msg = check_free_user(current_user.username)
            if num > 0:
                flash(msg, 'error')
                return custom_render_template("page_home.html",
                                              form=SearchForm())

        # Call the actual view
        return func(*args, **kwargs)
예제 #4
0
def search_page(uuid_key):
    form = SearchForm()
    redis_cache = MyRedisCache.getInstance()
    file_url = redis_cache.get(generate_flag(search_flag, uuid_key))        # uuid:file_url键对, 未注册用户有5分钟超时
    if not file_url:
        flash(_("Please search by home page!"), 'error')
        return custom_render_template("page_home.html", form=form, gettext=_)

    form.file_url.data = file_url
    try:
        gl = gevent.spawn(_fetch_information, file_url)
        gl.join(5)                                              # 等待5s,如遇I/O block 会自动切换到其他greenlet
        result = gl.value
        if isinstance(result, list):
            fmts_form = FormatsForm()
            fmts_form.url_uuid = uuid_key
            fmts_form.file_url = file_url
            for dt in result:
                fmts_form.file_title = dt["file_title"]
                detail_form = DetailForm(dt=dt)
                fmts_form.video_fmts.append_entry(detail_form)

            form.file_url.data = ""                             # 清空搜索框
            return custom_render_template("page_home.html", title=fmts_form.file_title, form=form, fmts_form=fmts_form)
        else:
            if gl.exception:
                err_msg = gl.exception                          # 用于保存,真实的错误
                #app.logger.error(err_msg)
                flash(_('An error occurred, please try again later!'), 'error')
            elif isinstance(result, string_types):
                err_msg = result
                #app.logger.error(err_msg)
                flash(error_message_filter(err_msg), 'error')
            else:
                err_msg = 'Unknown error'
                #app.logger.error(err_msg)
                flash(_('An error occurred, please try again later!'), 'error')
            return custom_render_template("page_home.html", form=form, gettext=_)
    except gevent.Timeout as exc:
        flash(_('Fetch file information timeout, Please try again later!'), 'error')
        return custom_render_template("page_home.html", form=form, gettext=_)
예제 #5
0
def home_page():
    if request.method == 'POST':
        form = SearchForm(request.form)
        if form.validate_on_submit():
            try:
                url_uuid = uuid.uuid1()                                                   # 一次搜索,一个uuid
            except ValueError:
                url_uuid = generate_crc_number(32)

            register = not current_user.is_anonymous
            timeout = 0 if register else app.config['CACHE_VISITOR_SEARCH_LIMIT']         # 若是游客,设置搜索结果超时机制
            redis_cache = MyRedisCache.getInstance()
            redis_cache.set(generate_flag(search_flag, url_uuid), form.file_url.data, timeout)

            return redirect(url_for('bwg360.search_page', uuid_key=url_uuid))
        else:
            flash(_('Please enter a valid URL'), 'error')
            return custom_render_template("page_home.html", form=form)
    else:
        form = SearchForm()
        return custom_render_template("page_home.html", form=form)
예제 #6
0
def file_download():
    redis_cache = MyRedisCache.getInstance()
    uuid_key = request.args.get('seq', None)
    file_url = redis_cache.get(generate_flag(search_flag, uuid_key))
    details  = redis_cache.get(generate_prefix(search_prefix, file_url), True)
    if uuid_key is None or not file_url or not details or not len(details):
        return custom_render_template("page_download.html", exist=False, msg=_("Waiting time is too long, timeout!"))

    # 免费下载文件不能大于500M
    format_id = request.args.get('fid')
    if is_free_download(current_user):
        file_size = get_file_size_of_format_id(file_url, format_id)
        if file_size > free_download_max_once:
            return custom_render_template("page_download.html", exist=False, msg=_("Free download can not be greater than %dM" % free_download_max_once))
        elif file_size < 0:
            return custom_render_template("page_download.html", exist=False, msg=_("An error occur when downloading"))

    # 开始下载
    ydl = make_file_dl(file_url, test_support=False)
    try:
        if not app.config['DEBUG']:
            redis_cache.delete(generate_flag(search_flag, uuid_key))                 # 非调试下,开始下载后,从缓存中删除本次的uuid

        # 直接传入current_user, on_close时获取不到正确的user对象,为NoneType
        username = '******' if current_user.is_anonymous else current_user.username
        user_info = (username, request.cookies.get('fppkcookie'), request.remote_addr)
        response = ydl.start_downloads(format_id, details[0], user_info)
        if isinstance(response, Response):
            return response
        elif isinstance(response, string_types):
            flash(response, 'error')
    except BaseException as e:
        print("exception is:{}".format(e))
        flash(_('Please enter a valid URL'), 'error')

    form = SearchForm()
    form.file_url.data = file_url                                                        # 用来在输入框显示 file_url
    return custom_render_template("page_home.html", form=form)
예제 #7
0
def download_record():
    show_limit = 25
    download_record_class = DownloadRecord.model()
    records = download_record_class.query.filter_by(user_id=current_user.id).order_by(download_record_class.time.desc()).limit(show_limit).all()
    now_tag = download_record_class.model_tag
    while len(records) < show_limit:
        remain = show_limit - len(records)
        pre_tag = DownloadRecord.previous_tag(now_tag)
        if pre_tag is None:
            break
        pre_download_record_class = DownloadRecord.model(pre_tag)
        pre_records = pre_download_record_class.query.filter_by(user_id=current_user.id).order_by(pre_download_record_class.time.desc()).limit(remain).all()
        records.extend(pre_records)
        now_tag = pre_tag
    return custom_render_template("download_record.html", records=records, limit=show_limit)
예제 #8
0
def file_cache():
    return custom_render_template("file_cache.html")
예제 #9
0
def download():
    return custom_render_template("download_problem.html")
예제 #10
0
def traffic():
    return custom_render_template("traffic.html")
예제 #11
0
def tutorial():
    return custom_render_template("tutorial.html")
예제 #12
0
def do_recharge():
    return custom_render_template("do_recharge.html")
예제 #13
0
def support_list():

    return custom_render_template("support_list.html", lists=site_list)
예제 #14
0
def disclaimer():
    return custom_render_template("disclaimer.html")
예제 #15
0
def recharge_record():
    return custom_render_template("recharge_record.html")