def test_get_name_utf8(self): """ Add a TorrentDef with non-utf8 encoding""" t = TorrentDef() t.set_name('\xA1\xC0') t.set_encoding('euc_kr') t.set_tracker(TRACKER) t.finalize() self.assertEqual(t.get_name_utf8(), u'\xf7')
def test_torrent_encoding(self): t = TorrentDef() t.set_encoding("my_fancy_encoding") self.assertEqual(t.get_encoding(), "my_fancy_encoding")
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)
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)
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)
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)