def _clean_torrent(hsh):
    import magic
    if hsh is None:
        return ''
    m = magic.open(magic.MAGIC_MIME)
    m.load()
    hsh = hsh.read()
    if not 'x-bittorrent' in m.buffer(hsh):
        m.close()
        raise forms.ValidationError, _(
            "Uploaded file doesn't look like torrent.")
    m.close()
    try:
        # do not forget to add LimitRequestBody to apache config
        hsh = bdecode(hsh)
    except ValueError:
        raise forms.ValidationError, _(
            "Uploaded file doesn't look like torrent.")
    hsh['announce'] = ANNOUNCE_URL
    hsh['modified-by'] = [SITE_NAME]
    if hsh.has_key('comment'):
        hsh['comment'] = SITE_NAME
    info_hash = sha.new(bencode(hsh['info'])).hexdigest()
    t = Torrent.objects.filter(info_hash=info_hash)
    if t:
        raise forms.ValidationError, _("This torrent already exists.")
    return (hsh, info_hash)
示例#2
0
def _clean_torrent(hsh):
    import magic
    if hsh is None:
	return ''
    m = magic.open(magic.MAGIC_MIME)
    m.load()
    hsh = hsh.read()
    if not 'x-bittorrent' in m.buffer(hsh):
	m.close()
	raise forms.ValidationError, _("Uploaded file doesn't look like torrent.")
    m.close()
    try:
	# do not forget to add LimitRequestBody to apache config
	hsh = bdecode(hsh)
    except ValueError:
	raise forms.ValidationError, _("Uploaded file doesn't look like torrent.")
    hsh['announce'] = ANNOUNCE_URL
    hsh['modified-by'] = [SITE_NAME]
    if hsh.has_key('comment'):
	hsh['comment'] = SITE_NAME
    info_hash=sha.new(bencode(hsh['info'])).hexdigest()
    t = Torrent.objects.filter(info_hash=info_hash)
    if t:
	raise forms.ValidationError, _("This torrent already exists.")
    return (hsh, info_hash)
def get_info_hash(torrentfile):
    f = open(torrentfile, 'rb')
    try:
        bencoded_data = bdecode(f.read())
    except ValueError:
        print('ERR: Invalid File')
        return
    # encode the value of the info key of the dictionary with the metainfo 
    # in sha1; encode the sha1 hash into hex.
    info_hash = hashlib.sha1(bencode(bencoded_data['info'])).hexdigest()
    return info_hash
示例#4
0
def get_torrent(request, the_id):
    from users.views import login
    import base64
    from benc import bdecode, bencode
    if not OPEN_TRACKER:
	if not request.user.is_authenticated():
	    return HttpResponseRedirect(reverse(login) + '?redirect=' + request.path)
    torrent = get_object_or_404(Torrent, pk=the_id)
    content = base64.b64decode(torrent.info)
    content = bdecode(content)
    if not OPEN_TRACKER:
	content['announce'] += "?passkey=%s"%request.user.passkey
    content = bencode(content)
    response = HttpResponse(content, mimetype='application/x-bittorrent')
    response["Content-Length"] = len(content)
    response["Content-Disposition"] = "attachment; filename=\"%s\""% torrent.fn
    return response
示例#5
0
def get_torrent(request, the_id):
    from users.views import login
    import base64
    from benc import bdecode, bencode
    if not OPEN_TRACKER:
        if not request.user.is_authenticated():
            return HttpResponseRedirect(
                reverse(login) + '?redirect=' + request.path)
    torrent = get_object_or_404(Torrent, pk=the_id)
    content = base64.b64decode(torrent.info)
    content = bdecode(content)
    if not OPEN_TRACKER:
        content['announce'] += "?passkey=%s" % request.user.passkey
    content = bencode(content)
    response = HttpResponse(content, mimetype='application/x-bittorrent')
    response["Content-Length"] = len(content)
    response[
        "Content-Disposition"] = "attachment; filename=\"%s\"" % torrent.fn
    return response
#!/usr/bin/python
import sys
import os
import base64

sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from fs.models import Topic
from tracker.models import Torrent
from benc import bdecode, bencode
from users.models import User

user = User.objects.get(username="******")
dest = os.path.join(os.path.dirname(__file__), "ex")

for t in Topic.objects.all():
    content = base64.b64decode(t.torrent.info)
    content = bdecode(content)
    content["announce"] += "?passkey=%s" % user.passkey
    content = bencode(content)
    f = open(os.path.join(dest, t.torrent.fn), "wb")
    f.write(content)
    f.close()
    print t.torrent.fn
#!/usr/bin/python
import sys
import os
import base64
sys.path.append(os.path.dirname(os.path.dirname(__file__)))
from fs.models import Topic
from tracker.models import Torrent
from benc import bdecode, bencode
from users.models import User

user = User.objects.get(username='******')
dest = os.path.join(os.path.dirname(__file__), 'ex')

for t in Topic.objects.all():
    content = base64.b64decode(t.torrent.info)
    content = bdecode(content)
    content['announce'] += "?passkey=%s" % user.passkey
    content = bencode(content)
    f = open(os.path.join(dest, t.torrent.fn), 'wb')
    f.write(content)
    f.close()
    print t.torrent.fn
示例#8
0
 def parse_file(self, _file ):
     self.meta = bdecode(_file)
     self.meta_info = self.meta['info']