def make_torrent_file(input, userabortflag = None, userprogresscallback = lambda x: None): """ Create a torrent file from the supplied input. Returns a (infohash,metainfo) pair, or (None,None) on userabort. """ (info,piece_length) = makeinfo(input,userabortflag,userprogresscallback) if userabortflag is not None and userabortflag.isSet(): return (None,None) if info is None: return (None,None) #if DEBUG: # print >>sys.stderr,"mktorrent: makeinfo returned",`info` check_info(info) metainfo = {'info': info, 'encoding': input['encoding'], 'creation date': long(time())} # http://www.bittorrent.org/DHT_protocol.html says both announce and nodes # are not allowed, but some torrents (Azureus?) apparently violate this. if input['nodes'] is None and input['announce'] is None: raise ValueError('No tracker set') for key in ['announce','announce-list','nodes','comment','created by','httpseeds']: if input[key] is not None and len(input[key]) > 0: metainfo[key] = input[key] if key == 'comment': metainfo['comment.utf-8'] = uniconvert(input['comment'],'utf-8') # Assuming 1 file, Azureus format no support multi-file torrent with diff # bitrates bitrate = None for file in input['files']: if file['playtime'] is not None: secs = parse_playtime_to_secs(file['playtime']) bitrate = file['length']/secs break if input.get('bps') is not None: bitrate = input['bps'] break if bitrate is not None or input['thumb'] is not None: mdict = {} mdict['Publisher'] = 'Tribler' if input['comment'] is None: descr = '' else: descr = input['comment'] mdict['Description'] = descr if bitrate is not None: mdict['Progressive'] = 1 mdict['Speed Bps'] = bitrate else: mdict['Progressive'] = 0 mdict['Title'] = metainfo['info']['name'] mdict['Creation Date'] = long(time()) # Azureus client source code doesn't tell what this is, so just put in random value from real torrent mdict['Content Hash'] = 'PT3GQCPW4NPT6WRKKT25IQD4MU5HM4UY' mdict['Revision Date'] = long(time()) if input['thumb'] is not None: mdict['Thumbnail'] = input['thumb'] cdict = {} cdict['Content'] = mdict metainfo['azureus_properties'] = cdict if input['torrentsigkeypairfilename'] is not None: create_torrent_signature(metainfo,input['torrentsigkeypairfilename']) infohash = sha(bencode(info)).digest() return (infohash,metainfo)
def make_torrent_file(input, userabortflag=None, userprogresscallback=lambda x: None): """ Create a torrent file from the supplied input. Returns a (infohash,metainfo) pair, or (None,None) on userabort. """ (info, piece_length) = makeinfo(input, userabortflag, userprogresscallback) if userabortflag is not None and userabortflag.isSet(): return (None, None) if info is None: return (None, None) # if DEBUG: # print >>sys.stderr,"mktorrent: makeinfo returned",`info` metainfo = {'info': info, 'encoding': input['encoding'], 'creation date': long(time())} validTorrentFile(metainfo) # http://www.bittorrent.org/DHT_protocol.html says both announce and nodes # are not allowed, but some torrents (Azureus?) apparently violate this. if input['nodes'] is None and input['announce'] is None: raise ValueError('No tracker set') for key in ['announce', 'announce-list', 'nodes', 'comment', 'created by', 'httpseeds', 'url-list']: if input[key] is not None and len(input[key]) > 0: metainfo[key] = input[key] if key == 'comment': metainfo['comment.utf-8'] = uniconvert(input['comment'], 'utf-8') # Assuming 1 file, Azureus format no support multi-file torrent with diff # bitrates bitrate = None for file in input['files']: if file['playtime'] is not None: secs = parse_playtime_to_secs(file['playtime']) bitrate = file['length'] / secs break if input.get('bps') is not None: bitrate = input['bps'] break if bitrate is not None or input['thumb'] is not None: mdict = {} mdict['Publisher'] = 'Tribler' if input['comment'] is None: descr = '' else: descr = input['comment'] mdict['Description'] = descr if bitrate is not None: mdict['Progressive'] = 1 mdict['Speed Bps'] = int(bitrate) # bencode fails for float else: mdict['Progressive'] = 0 mdict['Title'] = metainfo['info']['name'] mdict['Creation Date'] = long(time()) # Azureus client source code doesn't tell what this is, so just put in random value from real torrent mdict['Content Hash'] = 'PT3GQCPW4NPT6WRKKT25IQD4MU5HM4UY' mdict['Revision Date'] = long(time()) if input['thumb'] is not None: mdict['Thumbnail'] = input['thumb'] cdict = {} cdict['Content'] = mdict metainfo['azureus_properties'] = cdict if input['torrentsigkeypairfilename'] is not None: from Tribler.Core.Overlay.permid import create_torrent_signature create_torrent_signature(metainfo, input['torrentsigkeypairfilename']) if 'url-compat' in input: metainfo['info']['url-compat'] = input['url-compat'] # Arno, 2010-03-02: # Theoretically should go into 'info' field, to get infohash protection # because the video won't play without them. In the future we'll sign # the whole .torrent IMHO so it won't matter. Keeping it out of 'info' # at the moment makes the .tstream files more stable (in case you restart # the live source, and the Ogg header generated contains some date or # what not, we'd need a new .tstream to be distributed to all. # if 'ogg-headers' in input: metainfo['ogg-headers'] = input['ogg-headers'] # Two places where infohash calculated, here and in TorrentDef. # Elsewhere: must use TorrentDef.get_infohash() to allow P2PURLs. infohash = sha(bencode(info)).digest() return (infohash, metainfo)
def make_torrent_file(input, userabortflag = None, userprogresscallback = lambda x: None): """ Create a torrent file from the supplied input. Returns a (infohash,metainfo) pair, or (None,None) on userabort. """ (info,piece_length) = makeinfo(input,userabortflag,userprogresscallback) if userabortflag is not None and userabortflag.isSet(): return (None,None) if info is None: return (None,None) #if DEBUG: # print >>sys.stderr,"mktorrent: makeinfo returned",`info` check_info(info) metainfo = {'info': info, 'encoding': input['encoding'], 'creation date': long(time())} # http://www.bittorrent.org/DHT_protocol.html says both announce and nodes # are not allowed, but some torrents (Azureus?) apparently violate this. if input['nodes'] is None and input['announce'] is None: raise ValueError('No tracker set') for key in ['announce','announce-list','nodes','comment','created by','httpseeds', 'url-list']: if input[key] is not None and len(input[key]) > 0: metainfo[key] = input[key] if key == 'comment': metainfo['comment.utf-8'] = uniconvert(input['comment'],'utf-8') # Assuming 1 file, Azureus format no support multi-file torrent with diff # bitrates bitrate = None for file in input['files']: if file['playtime'] is not None: secs = parse_playtime_to_secs(file['playtime']) bitrate = file['length']/secs break if input.get('bps') is not None: bitrate = input['bps'] break if bitrate is not None or input['thumb'] is not None: mdict = {} mdict['Publisher'] = 'Tribler' if input['comment'] is None: descr = '' else: descr = input['comment'] mdict['Description'] = descr if bitrate is not None: mdict['Progressive'] = 1 mdict['Speed Bps'] = int(bitrate) # bencode fails for float else: mdict['Progressive'] = 0 mdict['Title'] = metainfo['info']['name'] mdict['Creation Date'] = long(time()) # Azureus client source code doesn't tell what this is, so just put in random value from real torrent mdict['Content Hash'] = 'PT3GQCPW4NPT6WRKKT25IQD4MU5HM4UY' mdict['Revision Date'] = long(time()) if input['thumb'] is not None: mdict['Thumbnail'] = input['thumb'] cdict = {} cdict['Content'] = mdict metainfo['azureus_properties'] = cdict if input['torrentsigkeypairfilename'] is not None: from Tribler.Core.Overlay.permid import create_torrent_signature create_torrent_signature(metainfo,input['torrentsigkeypairfilename']) if 'url-compat' in input: metainfo['info']['url-compat'] = input['url-compat'] # Arno, 2010-03-02: # Theoretically should go into 'info' field, to get infohash protection # because the video won't play without them. In the future we'll sign # the whole .torrent IMHO so it won't matter. Keeping it out of 'info' # at the moment makes the .tstream files more stable (in case you restart # the live source, and the Ogg header generated contains some date or # what not, we'd need a new .tstream to be distributed to all. # if 'ogg-headers' in input: metainfo['ogg-headers'] = input['ogg-headers'] # Two places where infohash calculated, here and in TorrentDef. # Elsewhere: must use TorrentDef.get_infohash() to allow P2PURLs. infohash = sha(bencode(info)).digest() return (infohash,metainfo)
def make_torrent_file(input, userabortflag=None, userprogresscallback=lambda x: None): """ Create a torrent file from the supplied input. Returns a (infohash,metainfo) pair, or (None,None) on userabort. """ (info, piece_length) = makeinfo(input, userabortflag, userprogresscallback) if userabortflag is not None and userabortflag.isSet(): return (None, None) if info is None: return (None, None) #if DEBUG: # print >>sys.stderr,"mktorrent: makeinfo returned",`info` check_info(info) metainfo = { 'info': info, 'encoding': input['encoding'], 'creation date': long(time()) } # http://www.bittorrent.org/DHT_protocol.html says both announce and nodes # are not allowed, but some torrents (Azureus?) apparently violate this. if input['nodes'] is None and input['announce'] is None: raise ValueError('No tracker set') for key in [ 'announce', 'announce-list', 'nodes', 'comment', 'created by', 'httpseeds' ]: if input[key] is not None and len(input[key]) > 0: metainfo[key] = input[key] if key == 'comment': metainfo['comment.utf-8'] = uniconvert(input['comment'], 'utf-8') # Assuming 1 file, Azureus format no support multi-file torrent with diff # bitrates bitrate = None for file in input['files']: if file['playtime'] is not None: secs = parse_playtime_to_secs(file['playtime']) bitrate = file['length'] / secs break if input.get('bps') is not None: bitrate = input['bps'] break if bitrate is not None or input['thumb'] is not None: mdict = {} mdict['Publisher'] = 'Tribler' if input['comment'] is None: descr = '' else: descr = input['comment'] mdict['Description'] = descr if bitrate is not None: mdict['Progressive'] = 1 mdict['Speed Bps'] = bitrate else: mdict['Progressive'] = 0 mdict['Title'] = metainfo['info']['name'] mdict['Creation Date'] = long(time()) # Azureus client source code doesn't tell what this is, so just put in random value from real torrent mdict['Content Hash'] = 'PT3GQCPW4NPT6WRKKT25IQD4MU5HM4UY' mdict['Revision Date'] = long(time()) if input['thumb'] is not None: mdict['Thumbnail'] = input['thumb'] cdict = {} cdict['Content'] = mdict metainfo['azureus_properties'] = cdict if input['torrentsigkeypairfilename'] is not None: create_torrent_signature(metainfo, input['torrentsigkeypairfilename']) infohash = sha(bencode(info)).digest() return (infohash, metainfo)