Beispiel #1
0
def browse_category(category):
    '''
    Renderiza la página de navegacion de categoria
    '''
    g.cache_code = "B"
    get_query_info(None, category)
    g.must_cache = 7200

    g.title.append(_(singular_filter(g.category.title) + " torrents"))
    pop_searches = torrentsdb.get_ranking(category)["final_ranking"]

    g.page_description = _("popular_category_desc", category=_(singular_filter(g.category.title)).lower(), categorys=_(g.category.title).lower()).capitalize()

    return render_template('browse_category.html', pop_searches = pop_searches)
Beispiel #2
0
def user_sitemap():
    structure = [
                    [("Home page", url_for(".home"), []), ("Copyright", url_for(".copyright"), [])] +
                    [("Popular searches", None, [(info[-1], url_for(".popular_searches", interval=interval)) for interval, info in POPULAR_SEARCHES_INTERVALS.iteritems()])] +
                    [("Popular torrents", None, [(info[-1], url_for(".popular_torrents", interval=interval)) for interval, info in POPULAR_TORRENTS_INTERVALS.iteritems()])]
                 ] + [
                    [(category.title, url_for(".browse_category", category=category.url),
                        [(_("popular_category", category=_(singular_filter(category.title)).lower(), categorys=_(category.title).lower()), url_for(".category", category=category.url))] +
                        [(subcategory, url_for(".category", category=category.url, subcategory=clean_query(subcategory)), "%s_subcat_%d"%(category.url, index)) for index, subcategory in enumerate(category.subcategories)])]
                                for category in g.categories
                ]
    return render_template('sitemap.html', canonical=url_for("files.user_sitemap", _external=True, _secure=False), structure=structure, column_count=4, column_width=5)
Beispiel #3
0
def browse_category(category):
    '''
    Renderiza la página de navegacion de categoria
    '''
    g.cache_code = "B"
    get_query_info(None, category)
    g.must_cache = 7200

    g.title.append(singular_filter(g.category.title) + " torrents")
    pop_searches = torrentsdb.get_ranking(category)["final_ranking"]

    g.page_description = "Popular %s torrents at %s, the free and fast torrent search engine."%(singular_filter(g.category.title).capitalize(), g.domain_capitalized)

    return render_template('browse_category.html', pop_searches = pop_searches)
Beispiel #4
0
def download(file_id, file_name=""):
    g.page_type = FILE_PAGE_TYPE
    if request.referrer:
        try:
            posibles_queries = referrer_parser.match(request.referrer)
            if posibles_queries:
                query = posibles_queries.group(1) or posibles_queries.group(2) or ""
                if query:
                    get_query_info(u(urllib2.unquote_plus(query).decode("utf-8")))
        except:
            pass

    error = None
    file_data=None
    if file_id is not None: #si viene un id se comprueba que sea correcto
        try: #intentar convertir el id que viene de la url a uno interno
            file_id=url2mid(file_id)
        except TypeError as e:
            try: #comprueba si se trate de un ID antiguo
                possible_file_id = filesdb.get_newid(file_id)
                if possible_file_id is None:
                    logging.warn("Identificadores numericos antiguos sin resolver: %s."%e, extra={"fileid":file_id})
                    error=404
                else:
                    logging.warn("Identificadores numericos antiguos encontrados: %s."%e, extra={"fileid":file_id})
                    return {"html": empty_redirect(url_for(".download", file_id=mid2url(possible_file_id), file_name=file_name), 301),"error":301}

            except BaseException as e:
                logging.exception(e)
                error=503

            file_id=None

        if file_id:
            try:
                file_data=get_file_metadata(file_id, file_name.replace("-"," "))
            except DatabaseError:
                error=503
            except FileNotExist:
                error=404
            except (FileRemoved, FileFoofindRemoved, FileNoSources):
                error=410
            except FileUnknownBlock:
                error=404

            if error is None and not file_data: #si no ha habido errores ni hay datos, es porque existe y no se ha podido recuperar
                error=503

    if error:
        abort(error)

    # completa datos de torrent
    file_data = torrents_data(file_data, True, g.category)
    if not file_data:
        abort(404)

    if file_data["view"]["category"]:
        g.category = file_data["view"]["category"]
        if file_data["view"]["category"].tag=="p**n":
            g.is_adult_content = True
    else:
        g.category = file_data["view"]["category_type"]

    # no permite acceder ficheros que deberian ser bloqueados
    prepared_phrase = blacklists.prepare_phrase(file_data['view']['nfn'])
    if prepared_phrase in blacklists["forbidden"] or (prepared_phrase in blacklists["misconduct"] and prepared_phrase in blacklists["underage"]):
        g.blacklisted_content = "File"
        if not g.show_blacklisted_content:
            abort(404)

    query = download_search(file_data, file_name, "torrent").replace("-"," ")
    related = single_search(query, category=None, not_category=(None if g.is_adult_content else "p**n"), title=("Related torrents",3,None), zone="File / Related", last_items=[], limit=30, max_limit=15, ignore_ids=[mid2hex(file_id)], show_order=None)

    # elige el titulo de la página
    title = file_data['view']['fn']

    # recorta el titulo hasta el proximo separador
    if len(title)>101:
        for pos in xrange(101, 30, -1):
            if title[pos] in SEPPER:
                title = title[:pos].strip()
                break
        else:
            title = title[:101]

    g.title = [title]

    page_description = ""
    if "description" in file_data["view"]["md"]:
        page_description = file_data["view"]["md"]["description"].replace("\n", " ")

    if not page_description:
        if g.category:
            page_description = _("download_category_desc", category=singular_filter(g.category.title).lower(), categorys=g.category.title.lower()).capitalize()
        else:
            page_description = _("download_desc")


    if len(page_description)<50:
        if page_description:
           page_description += ". "
        page_description += " ".join(text.capitalize()+"." for text in related[1]["files_text"])

    if len(page_description)>180:
        last_stop = page_description[:180].rindex(".") if "." in page_description[:180] else 0
        if last_stop<100:
            last_stop = page_description[:180].rindex(" ") if " " in page_description[:180] else 0
        if last_stop<100:
            last_stop = 180
        page_description = page_description[:last_stop]+"."

    g.page_description = page_description

    is_canonical_filename = file_data["view"]["seo-fn"]==file_name

    # registra visita al fichero
    if g.search_bot:
        searchd.log_bot_event(g.search_bot, True)
    else:
        save_visited([file_data])

    if related[0]:
        g.must_cache = 3600

    # last-modified
    g.last_modified = file_data["file"]["ls"]

    return render_template('file.html', related_query = query, file_data=file_data, related_files=related, is_canonical_filename=is_canonical_filename, featured=get_featured(related[1]["count"]+len(file_data["view"]["md"]), 1))
Beispiel #5
0
def category(category, query=None, subcategory=None):

    g.page_type = CATEGORY_PAGE_TYPE

    g.subcategory = None
    get_query_info(query, category, subcategory)

    # categoria invalida
    if not g.category:
        return abort(404)

    group_count_search = pop_searches = None
    results_template = "browse.html"

    page_title = _(singular_filter(g.category.title)+" torrents")
    limit = 150
    page_size = 30
    pages_limit = 10

    _category = _(singular_filter(g.category.title)).lower()
    _categorys = _(g.category.title).lower()

    if g.query:
        page_title = _("category_search_torrents", query=g.query, category=_category, categorys=_categorys).capitalize()
        g.page_description = _("category_desc", query=g.query,  category=_category, categorys=_categorys).capitalize()
        order, show_order, order_title = get_order(SEARCH_ORDER)
        group_count_search = start_guess_categories_with_results(g.query)
        results_template = "results.html"
        limit=75
        page_size=50
    elif subcategory:
        if not g.subcategory:
            return abort(404)
        g.cache_code = "B"
        page_title = _("category_search_torrents", query=g.subcategory, category=_(singular_filter(g.category.title)).lower(), categorys=_(g.category.title).lower()).capitalize()
        g.page_description = _("category_desc", query=g.subcategory, category=_category, categorys=_categorys).capitalize()
        order, show_order, order_title = get_order(SUBCATEGORY_ORDER)
    else:
        page_title = _("popular_category", category=_(singular_filter(g.category.title)).lower(), categorys=_(g.category.title).lower()).capitalize()
        g.page_description = _("popular_category_desc", category=_category, categorys=_categorys).capitalize()
        order, show_order, order_title = get_order(CATEGORY_ORDER)

    skip = get_skip(pages_limit)
    if skip>0:
        g.title.append(_("page_number", number=int(skip) + 1))

    if order_title:
        g.title.append(order_title)

    g.title.append(page_title)

    results, search_info = single_search("("+g.subcategory.replace(" ","")+")" if g.subcategory else g.query, category=g.category.tag, not_category=None if g.is_adult_content else "p**n", order=order, zone=g.category.url, title=(None, 2, g.category.tag), limit=limit, max_limit=page_size, skip=skip, show_order=show_order or True, results_template=results_template, details=not g.query)

    if g.query:
        if g.search_bot:
            searchd.log_bot_event(g.search_bot, (search_info["total_found"]>0 or search_info["sure"]))
        else:
            g.track = bool(results)

        if group_count_search:
            g.categories_results = end_guess_categories_with_results(group_count_search)

        return render_template('category.html', results=results, search_info=search_info, show_order=show_order, featured=get_featured(search_info["count"])), 200 if bool(results) else 404
    else:
        pagination = get_browse_pagination(search_info, skip, page_size, pages_limit)

        return render_template('subcategory.html', results=results, search_info=search_info, pagination=pagination, show_order=show_order), 200 if bool(results) else 404