コード例 #1
0
ファイル: addtorrent.py プロジェクト: gr0gmint/Hermes
def addtorrent(context, request):
    u = get_current_user(request)
    announce_url = (
        'http://%s/%s/announce' %
        (request.registry.settings['hostname'], u.passkey)).encode('utf-8')
    if request.method == "POST":
        form = AddTorrentForm(request.params)
        if form.validate():

            filename = save_torrent(form.torrent_file.data, request)
            abs_filename = os.path.join(
                request.registry.settings['torrent_dir'], filename)
            info = bencode.bencode(
                bencode.bdecode(open(abs_filename).read())['info'])
            name = form.name.data
            info_hash = hashlib.sha1(info).hexdigest()
            log.error('INFOHASH: ' + info_hash)
            torrent = Torrent()
            torrent.info_hash = info_hash
            torrent.name = unicode(name)
            torrent.info = {}
            torrent.uploaded_time = datetime.datetime.now()
            torrent.torrent_file = filename
            torrent.last_checked = datetime.datetime.now()
            DBSession.add(torrent)
            DBSession.commit()
            log.error(filename)
        return {'form': form, 'announce': announce_url}
    else:
        form = AddTorrentForm()
        return {'form': form, 'announce': announce_url}
コード例 #2
0
ファイル: addtorrent.py プロジェクト: gr0gmint/Hermes
def addtorrent(context, request):
    u = get_current_user(request)
    announce_url = ('http://%s/%s/announce' % (request.registry.settings['hostname'], u.passkey)).encode('utf-8')
    if request.method=="POST":
        form = AddTorrentForm(request.params)
        if form.validate():
            
            filename = save_torrent(form.torrent_file.data, request)
            abs_filename = os.path.join(request.registry.settings['torrent_dir'], filename)
            info = bencode.bencode(bencode.bdecode(open(abs_filename).read())['info'])
            name = form.name.data
            info_hash = hashlib.sha1(info).hexdigest()
            log.error('INFOHASH: '+info_hash)
            torrent = Torrent()
            torrent.info_hash = info_hash
            torrent.name = unicode(name) 
            torrent.info = {}
            torrent.uploaded_time = datetime.datetime.now()
            torrent.torrent_file = filename
            torrent.last_checked = datetime.datetime.now()
            DBSession.add(torrent)
            DBSession.commit()
            log.error(filename)
        return {'form': form, 'announce': announce_url}
    else:
        form = AddTorrentForm()
        return {'form': form, 'announce': announce_url}
コード例 #3
0
def get_torrent(context, request):
    id_ = request.matchdict['id']
    u = get_current_user(request)
    torrent = DBSession.query(Torrent).filter_by(torrent_id = id_).first()
    abs_filename = os.path.join(request.registry.settings['torrent_dir'], torrent.torrent_file)
    f = open(abs_filename)
    torrentdata = f.read()
    torb = bencode.bdecode(torrentdata)
    
    torb['announce'] = ('http://%s/%s/announce' % (request.registry.settings['hostname'], u.passkey)).encode('utf-8')
    return Response(bencode.bencode(torb), headerlist=[('Content-Type', 'application/x-bittorrent'), ('Content-Disposition', 'attachment; filename=\"'+torrent.name+".torrent\"")])