Beispiel #1
0
def info(id_torrent):
    torrent = get_torrent_by_id(id_torrent)
    if torrent:
        try:
            data = open(app.config['UPLOAD_FOLDER'] + torrent.filename,
                        "rb").read()
        except IOError:
            return redirect('/')

        # todo check this part
        info = None
        error = None
        if data:
            torrent_ = decode(data)
            if 'files' in torrent_["info"]:
                info = torrent_["info"]["files"]
            else:
                error = True
                info = torrent_

        return render_template('info.html',
                               torrent=torrent,
                               info=info,
                               error=error)
    else:
        return redirect('/')
Beispiel #2
0
def upload_torrent_file(name, description, file_context, filename, user_id):
    if name != "" and description and filename != "":
        if os.path.exists(app.config['UPLOAD_FOLDER']):
            uid = uniqid()
            filename = "".join([uid, ".torrent"])
            file_context.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))

            try:
                data = open(app.config['UPLOAD_FOLDER'] + filename, "rb").read()
                if data:
                    torrent_ = decode(data)
                    size = 0
                    try:
                        info = torrent_["info"]["files"]
                        for file_context in info:
                            size = size + file_context["length"]
                    except KeyError:
                        size = torrent_["info"]["length"]
                    size = round((size * 0.001) * 0.001, 2)
                    add_torrent(name, description, filename, user_id, size)
            except IOError:
                return
Beispiel #3
0
def info(id_torrent):
    torrent = get_torrent_by_id(id_torrent)
    if torrent:
        try:
            data = open(app.config['UPLOAD_FOLDER'] + torrent.filename, "rb").read()
        except IOError:
            return redirect('/')

        # todo check this part
        info = None
        error = None
        if data:
            torrent_ = decode(data)
            if 'files' in torrent_["info"]:
                info = torrent_["info"]["files"]
            else:
                error = True
                info = torrent_

        return render_template('info.html', torrent=torrent, info=info, error=error)
    else:
        return redirect('/')