Ejemplo n.º 1
0
    def test_set_trackers(self):
        t = TorrentDef()
        t.set_tracker_hierarchy([["http://tracker.org", "http://tracker2.org/", "http/tracker3.org"]])
        self.assertEqual(len(t.get_tracker_hierarchy()[0]), 2)
        self.assertEqual(t.get_tracker_hierarchy()[0][0], "http://tracker.org")
        self.assertEqual(t.get_tracker_hierarchy()[0][1], "http://tracker2.org")

        self.assertEqual(t.get_trackers_as_single_tuple(), ('http://tracker.org', 'http://tracker2.org'))
Ejemplo n.º 2
0
    def test_set_trackers(self):
        t = TorrentDef()
        t.set_tracker_hierarchy([[
            "http://tracker.org", "http://tracker2.org/", "http/tracker3.org"
        ]])
        self.assertEqual(len(t.get_tracker_hierarchy()[0]), 2)
        self.assertEqual(t.get_tracker_hierarchy()[0][0], "http://tracker.org")
        self.assertEqual(t.get_tracker_hierarchy()[0][1],
                         "http://tracker2.org")

        self.assertEqual(t.get_trackers_as_single_tuple(),
                         ('http://tracker.org', 'http://tracker2.org'))
Ejemplo n.º 3
0
    def subtest_add_content_announce_list(self):
        """ Add a single file with announce-list to a TorrentDef """
        t = TorrentDef()
        fn = os.path.join(TESTS_API_DIR, "video.avi")

        t.add_content(fn)
        t.set_tracker(TRACKER)
        exphier = [[TRACKER], ['http://tracker1.tribler.org:6969/announce', 'http://tracker2.tribler.org:7070/ann'],
                   ['http://www.cs.vu.nl', 'http://www.st.ewi.tudelft.nl', 'http://www.vuze.com']]
        t.set_tracker_hierarchy(exphier)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        realhier = metainfo['announce-list']
        self.assert_(realhier == exphier)
Ejemplo n.º 4
0
    def test_add_content_announce_list(self):
        """ Add a single file with announce-list to a TorrentDef """
        t = TorrentDef()
        fn = os.path.join(TESTS_DATA_DIR, self.VIDEO_FILE_NAME)

        t.add_content(fn)
        t.set_tracker(TRACKER)
        exphier = [[TRACKER],
                   [
                       'http://tracker1.tribler.org:6969/announce',
                       'http://tracker2.tribler.org:7070/ann'
                   ],
                   [
                       'http://www.cs.vu.nl', 'http://www.st.ewi.tudelft.nl',
                       'http://www.vuze.com'
                   ]]
        t.set_tracker_hierarchy(exphier)
        t.finalize()

        metainfo = t.get_metainfo()
        self.general_check(metainfo)
        realhier = metainfo['announce-list']
        self.assertEqual(realhier, exphier)
Ejemplo n.º 5
0
 def test_set_trackers_no_list_tier(self):
     t = TorrentDef()
     t.set_tracker_hierarchy(["http://tracker.org"])
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()
    
    if len(srcpaths) > 1:
        basepath = []
        for srcpath in srcpaths:
            path, filename = os.path.split(srcpath)
            basepath.append(path)
            
        basepath, _ = 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['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 'target' in params and params['target']:
        torrentfilename = os.path.join(params['target'], os.path.split(os.path.normpath(srcpath))[1] + postfix)
    else:
        a, b = os.path.split(srcpaths[0])
        if b == '':
            torrentfilename = a + postfix
        else:
            torrentfilename = os.path.join(a, b + postfix)
    tdef.save(torrentfilename)
    
    # Inform higher layer we created torrent
    torrentfilenameCallback(basepath, torrentfilename)
Ejemplo n.º 8
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.º 9
0
 def test_set_trackers_no_list_tier(self):
     t = TorrentDef()
     t.set_tracker_hierarchy(["http://tracker.org"])
Ejemplo n.º 10
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)