Ejemplo n.º 1
0
 def test_get_name_utf8(self):
     """
     Check whether we can successfully get the UTF-8 encoded torrent name when using a different encoding
     """
     t = TorrentDef()
     t.set_name('\xA1\xC0')
     self.assertEqual(t.get_name_utf8(), u'\xa1\xc0')
Ejemplo n.º 2
0
    def test_get_name_utf8_unknown(self):
        """ Add a TorrentDef with non-utf8 encoding"""
        t = TorrentDef()
        t.set_name('\xA1\xC0')
        t.set_tracker(TRACKER)
        t.finalize()

        self.assertEqual(t.get_name_utf8(), u'\xa1\xc0')
Ejemplo n.º 3
0
 def test_get_name_utf8_unknown(self):
     """
     Test whether we can succesfully get the UTF-8 name
     """
     t = TorrentDef()
     t.set_name('\xA1\xC0')
     t.torrent_parameters['encoding'] = 'euc_kr'
     self.assertEqual(t.get_name_utf8(), u'\xf7')
Ejemplo n.º 4
0
    def test_get_name_utf8_unknown(self):
        """ Add a TorrentDef with non-utf8 encoding"""
        t = TorrentDef()
        t.set_name('\xA1\xC0')
        t.set_tracker(TRACKER)
        t.finalize()

        self.assertEqual(t.get_name_utf8(), u'\xa1\xc0')
Ejemplo n.º 5
0
 def test_set_name(self):
     t = TorrentDef()
     t.set_name("lorem ipsum")
     t.get_name()
Ejemplo n.º 6
0
def make_meta_file(srcpaths, params, userabortflag, progressCallback,
                   torrentfilenameCallback):
    tdef = TorrentDef()

    basedir = None

    nrFiles = len([file for file in srcpaths if os.path.isfile(file)])
    if nrFiles > 1:
        #outpaths should start with a common prefix, this prefix is the swarmname of the torrent
        #if srcpaths contain c:\a\1, c:\a\2 -> basepath should be c:\ and basedir a and outpaths should be a\1 and a\2
        #if srcpaths contain c:\a\1, c:\a\2, c:\a\b\1, c:\a\b\2 -> basepath should be c:\ and outpaths should be a\1, a\2, a\b\1 and a\b\2
        basepath = os.path.abspath(os.path.commonprefix(srcpaths))
        basepath, basedir = os.path.split(basepath)
        for srcpath in srcpaths:
            if os.path.isfile(srcpath):
                outpath = os.path.relpath(srcpath, basepath)

                # h4x0r playtime
                if 'playtime' in params:
                    tdef.add_content(srcpath,
                                     outpath,
                                     playtime=params['playtime'])
                else:
                    tdef.add_content(srcpath, outpath)
    else:
        srcpaths = [file for file in srcpaths if os.path.isfile(file)]

        srcpath = srcpaths[0]
        basepath, _ = os.path.split(srcpath)
        if 'playtime' in params:
            tdef.add_content(srcpath, playtime=params['playtime'])
        else:
            tdef.add_content(srcpath)

        if params.get('urllist', False):
            tdef.set_urllist(params['urllist'])

    if params['name']:
        tdef.set_name(params['name'])
    if params['comment']:
        tdef.set_comment(params['comment'])
    if params['created by']:
        tdef.set_created_by(params['created by'])
    if params['announce']:
        tdef.set_tracker(params['announce'])
    if params['announce-list']:
        tdef.set_tracker_hierarchy(params['announce-list'])
    if params['nodes']:  # mainline DHT
        tdef.set_dht_nodesmax(params['nodes'])
    if params['httpseeds']:
        tdef.set_httpseeds(params['httpseeds'])
    if params['encoding']:
        tdef.set_encoding(params['encoding'])
    if params['piece length']:
        tdef.set_piece_length(params['piece length'])
    if params['makehash_md5']:
        print >> sys.stderr, "TorrentMaker: make MD5"
        tdef.set_add_md5hash(params['makehash_md5'])
    if params['makehash_crc32']:
        print >> sys.stderr, "TorrentMaker: make CRC32"
        tdef.set_add_crc32(params['makehash_crc32'])
    if params['makehash_sha1']:
        print >> sys.stderr, "TorrentMaker: make SHA1"
        tdef.set_add_sha1hash(params['makehash_sha1'])
    if params['createmerkletorrent']:
        tdef.set_create_merkle_torrent(params['createmerkletorrent'])
    if params['torrentsigkeypairfilename']:
        tdef.set_signature_keypair_filename(
            params['torrentsigkeypairfilename'])
    if params['thumb']:
        tdef.set_thumbnail(params['thumb'])

    tdef.finalize(userabortflag=userabortflag,
                  userprogresscallback=progressCallback)

    if params['createmerkletorrent']:
        postfix = TRIBLER_TORRENT_EXT
    else:
        postfix = '.torrent'

    if params.get('target', False):
        torrentfilename = os.path.join(
            params['target'],
            os.path.split(os.path.normpath(srcpath))[1] + postfix)
    else:
        torrentfilename = os.path.join(basepath, tdef.get_name() + postfix)
    tdef.save(torrentfilename)

    # Inform higher layer we created torrent
    torrentfilenameCallback(basepath, basedir, torrentfilename)
Ejemplo n.º 7
0
def make_meta_file(srcpaths, params, userabortflag, progressCallback, torrentfilenameCallback):
    tdef = TorrentDef()

    basedir = None
    if len(srcpaths) > 1:
        basepath = []
        for srcpath in srcpaths:
            path, filename = os.path.split(srcpath)
            basepath.append(path)

        basepath, basedir = os.path.split(os.path.commonprefix(basepath))
        for srcpath in srcpaths:
            outpath = os.path.relpath(srcpath, basepath)

            # h4x0r playtime
            if "playtime" in params:
                tdef.add_content(srcpath, outpath, playtime=params["playtime"])
            else:
                tdef.add_content(srcpath, outpath)
    else:
        srcpath = srcpaths[0]
        basepath, _ = os.path.split(srcpath)
        if "playtime" in params:
            tdef.add_content(srcpath, playtime=params["playtime"])
        else:
            tdef.add_content(srcpath)

    if params["name"]:
        tdef.set_name(params["name"])
    if params["comment"]:
        tdef.set_comment(params["comment"])
    if params["created by"]:
        tdef.set_created_by(params["created by"])
    if params["announce"]:
        tdef.set_tracker(params["announce"])
    if params["announce-list"]:
        tdef.set_tracker_hierarchy(params["announce-list"])
    if params["nodes"]:  # mainline DHT
        tdef.set_dht_nodesmax(params["nodes"])
    if params["httpseeds"]:
        tdef.set_httpseeds(params["httpseeds"])
    if params["encoding"]:
        tdef.set_encoding(params["encoding"])
    if params["piece length"]:
        tdef.set_piece_length(params["piece length"])
    if params["makehash_md5"]:
        print >>sys.stderr, "TorrentMaker: make MD5"
        tdef.set_add_md5hash(params["makehash_md5"])
    if params["makehash_crc32"]:
        print >>sys.stderr, "TorrentMaker: make CRC32"
        tdef.set_add_crc32(params["makehash_crc32"])
    if params["makehash_sha1"]:
        print >>sys.stderr, "TorrentMaker: make SHA1"
        tdef.set_add_sha1hash(params["makehash_sha1"])
    if params["createmerkletorrent"]:
        tdef.set_create_merkle_torrent(params["createmerkletorrent"])
    if params["torrentsigkeypairfilename"]:
        tdef.set_signature_keypair_filename(params["torrentsigkeypairfilename"])
    if params["thumb"]:
        tdef.set_thumbnail(params["thumb"])

    tdef.finalize(userabortflag=userabortflag, userprogresscallback=progressCallback)

    if params["createmerkletorrent"]:
        postfix = TRIBLER_TORRENT_EXT
    else:
        postfix = ".torrent"

    if params.get("target", False):
        torrentfilename = os.path.join(params["target"], os.path.split(os.path.normpath(srcpath))[1] + postfix)
    else:
        torrentfilename = os.path.join(basepath, tdef.get_name() + postfix)
    tdef.save(torrentfilename)

    # Inform higher layer we created torrent
    torrentfilenameCallback(basepath, basedir, torrentfilename)
Ejemplo n.º 8
0
 def test_set_name(self):
     t = TorrentDef()
     t.set_name("lorem ipsum")
     t.get_name()
Ejemplo n.º 9
0
def make_meta_file(srcpaths, params, userabortflag, progressCallback, torrentfilenameCallback):
    tdef = TorrentDef()

    basedir = None

    nrFiles = len([file for file in srcpaths if os.path.isfile(file)])
    if nrFiles > 1:
        # outpaths should start with a common prefix, this prefix is the swarmname of the torrent
        # if srcpaths contain c:\a\1, c:\a\2 -> basepath should be c:\ and basedir a and outpaths should be a\1 and a\2
        # if srcpaths contain c:\a\1, c:\a\2, c:\a\b\1, c:\a\b\2 -> basepath should be c:\ and outpaths should be a\1, a\2, a\b\1 and a\b\2
        basepath = os.path.abspath(os.path.commonprefix(srcpaths))
        basepath, basedir = os.path.split(basepath)
        for srcpath in srcpaths:
            if os.path.isfile(srcpath):
                outpath = os.path.relpath(srcpath, basepath)

                # h4x0r playtime
                if 'playtime' in params:
                    tdef.add_content(srcpath, outpath, playtime=params['playtime'])
                else:
                    tdef.add_content(srcpath, outpath)
    else:
        srcpaths = [file for file in srcpaths if os.path.isfile(file)]

        srcpath = srcpaths[0]
        basepath, _ = os.path.split(srcpath)
        if 'playtime' in params:
            tdef.add_content(srcpath, playtime=params['playtime'])
        else:
            tdef.add_content(srcpath)

        if params.get('urllist', False):
            tdef.set_urllist(params['urllist'])

    if params['name']:
        tdef.set_name(params['name'])
    if params['comment']:
        tdef.set_comment(params['comment'])
    if params['created by']:
        tdef.set_created_by(params['created by'])
    if params['announce']:
        tdef.set_tracker(params['announce'])
    if params['announce-list']:
        tdef.set_tracker_hierarchy(params['announce-list'])
    if params['nodes']:  # mainline DHT
        tdef.set_dht_nodesmax(params['nodes'])
    if params['httpseeds']:
        tdef.set_httpseeds(params['httpseeds'])
    if params['encoding']:
        tdef.set_encoding(params['encoding'])
    if params['piece length']:
        tdef.set_piece_length(params['piece length'])
    if params['makehash_md5']:
        print >> sys.stderr, "TorrentMaker: make MD5"
        tdef.set_add_md5hash(params['makehash_md5'])
    if params['makehash_crc32']:
        print >> sys.stderr, "TorrentMaker: make CRC32"
        tdef.set_add_crc32(params['makehash_crc32'])
    if params['makehash_sha1']:
        print >> sys.stderr, "TorrentMaker: make SHA1"
        tdef.set_add_sha1hash(params['makehash_sha1'])
    if params['createmerkletorrent']:
        tdef.set_create_merkle_torrent(params['createmerkletorrent'])
    if params['torrentsigkeypairfilename']:
        tdef.set_signature_keypair_filename(params['torrentsigkeypairfilename'])
    if params['thumb']:
        tdef.set_thumbnail(params['thumb'])

    tdef.finalize(userabortflag=userabortflag, userprogresscallback=progressCallback)

    if params['createmerkletorrent']:
        postfix = TRIBLER_TORRENT_EXT
    else:
        postfix = '.torrent'

    if params.get('target', False):
        torrentfilename = os.path.join(params['target'], os.path.split(os.path.normpath(srcpath))[1] + postfix)
    else:
        torrentfilename = os.path.join(basepath, tdef.get_name() + postfix)
    tdef.save(torrentfilename)

    # Inform higher layer we created torrent
    torrentfilenameCallback(basepath, basedir, torrentfilename)