Esempio n. 1
0
 def _create(metainfo, protected = False):
     metainfo = validTorrentFile(metainfo)
     t = TorrentDef()
     t.protected = protected
     t.metainfo = metainfo
     t.ts_metainfo_valid = True
     t.metainfo_valid = True
     maketorrent.copy_metainfo_to_input(t.metainfo, t.input)
     if t.get_url_compat():
         t.infohash = makeurl.metainfo2swarmid(t.metainfo)
     else:
         t.infohash = sha(bencode(metainfo['info'], params={'skip_dict_sorting': True})).digest()
     if DEBUG:
         print >> sys.stderr, 'TorrentDef::_create: infohash:', `(t.infohash)`
     return t
Esempio n. 2
0
    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