def finalize(self, userabortflag=None, userprogresscallback=None): if self.readonly: raise OperationNotPossibleAtRuntimeException() if self.metainfo_valid: if not self.ts_metainfo_valid: if self.input.has_key('x-ts-properties'): self.metainfo['x-ts-properties'] = self.input[ 'x-ts-properties'] elif self.metainfo.has_key('x-ts-properties'): del self.metainfo['x-ts-properties'] self.ts_metainfo_valid = True return if 'live' in self.input: try: secs = parse_playtime_to_secs(self.input['playtime']) except: secs = 3600 pl = float(self.get_piece_length()) length = float(self.input['bps'] * secs) length *= 8 if DEBUG: print >> sys.stderr, 'TorrentDef: finalize: length', length, 'piecelen', pl diff = length % pl add = (pl - diff) % pl newlen = int(length + add) d = self.input['files'][0] d['length'] = newlen infohash, metainfo = maketorrent.make_torrent_file( self.input, userabortflag=userabortflag, userprogresscallback=userprogresscallback) if infohash is not None: if self.get_url_compat(): url = makeurl.metainfo2p2purl(metainfo) swarmid = makeurl.metainfo2swarmid(metainfo) self.infohash = swarmid else: self.infohash = infohash self.metainfo = metainfo self.input['name'] = metainfo['info']['name'] self.input['piece length'] = metainfo['info']['piece length'] self.metainfo_valid = True
def finalize(self, userabortflag=None, userprogresscallback=None): if self.readonly: raise OperationNotPossibleAtRuntimeException() if self.metainfo_valid: if not self.ts_metainfo_valid: if self.input.has_key("x-ts-properties"): self.metainfo["x-ts-properties"] = self.input["x-ts-properties"] elif self.metainfo.has_key("x-ts-properties"): del self.metainfo["x-ts-properties"] self.ts_metainfo_valid = True return if "live" in self.input: try: secs = parse_playtime_to_secs(self.input["playtime"]) except: secs = 3600 pl = float(self.get_piece_length()) length = float(self.input["bps"] * secs) length *= 8 if DEBUG: print >>sys.stderr, "TorrentDef: finalize: length", length, "piecelen", pl diff = length % pl add = (pl - diff) % pl newlen = int(length + add) d = self.input["files"][0] d["length"] = newlen infohash, metainfo = maketorrent.make_torrent_file( self.input, userabortflag=userabortflag, userprogresscallback=userprogresscallback ) if infohash is not None: if self.get_url_compat(): url = makeurl.metainfo2p2purl(metainfo) swarmid = makeurl.metainfo2swarmid(metainfo) self.infohash = swarmid else: self.infohash = infohash self.metainfo = metainfo self.input["name"] = metainfo["info"]["name"] self.input["piece length"] = metainfo["info"]["piece length"] self.metainfo_valid = True
def get_url(self): if self.metainfo_valid: return makeurl.metainfo2p2purl(self.metainfo) raise TorrentDefNotFinalizedException()