Beispiel #1
0
 def __init__(self, infohash, metainfo, kvconfig, multihandler, get_extip_func, listenport, videoanalyserpath, vodfileindex, extra_vodfileindex, set_error_func, pstate, lmvodeventcallback, lmhashcheckcompletecallback):
     self.dow = None
     self.set_error_func = set_error_func
     self.videoinfo = None
     self.videostatus = None
     self.metainfo = metainfo
     self.dlmode = kvconfig['mode']
     self.extra_vodfileindex = extra_vodfileindex
     self.lmvodeventcallback = lmvodeventcallback
     self.lmhashcheckcompletecallback = lmhashcheckcompletecallback
     self.logmsgs = []
     self._hashcheckfunc = None
     self._getstatsfunc = None
     self.infohash = infohash
     self.b64_infohash = b64encode(infohash)
     self.repexer = None
     self.log_prefix = 'sd::' + binascii.hexlify(self.infohash) + ':'
     self.lock = Lock()
     self.download_id = binascii.hexlify(self.infohash) + '-' + str(long(time.time())) + '-' + str(random.randint(0, 100000))
     try:
         self.dldoneflag = Event()
         self.dlrawserver = multihandler.newRawServer(infohash, self.dldoneflag)
         self.lmvodeventcallback = lmvodeventcallback
         if pstate is not None:
             self.hashcheckfrac = pstate['dlstate']['progress']
         else:
             self.hashcheckfrac = 0.0
         self.peerid = createPeerID()
         self.dow = BT1Download(self.hashcheckprogressfunc, self.finishedfunc, self.fatalerrorfunc, self.nonfatalerrorfunc, self.logerrorfunc, self.dldoneflag, kvconfig, metainfo, infohash, self.peerid, self.dlrawserver, get_extip_func, listenport, videoanalyserpath)
         file = self.dow.saveAs(self.save_as)
         if vodfileindex is not None:
             index = vodfileindex['index']
             if index == -1:
                 index = 0
             outpathindex = self.dow.get_dest(index)
             vodfileindex['outpath'] = outpathindex
             self.videoinfo = vodfileindex
             if 'live' in metainfo['info']:
                 authparams = metainfo['info']['live']
             else:
                 authparams = None
             self.videostatus = VideoStatus(metainfo['info']['piece length'], self.dow.files, vodfileindex, authparams)
             self.videoinfo['status'] = self.videostatus
             self.dow.set_videoinfo(vodfileindex, self.videostatus)
         if DEBUG:
             log(self.log_prefix + '__init__: setting vodfileindex', vodfileindex)
         if kvconfig['initialdlstatus'] == DLSTATUS_REPEXING:
             if pstate is not None and pstate.has_key('dlstate'):
                 swarmcache = pstate['dlstate'].get('swarmcache', {})
             else:
                 swarmcache = {}
             self.repexer = RePEXer(self.infohash, swarmcache)
         else:
             self.repexer = None
         if pstate is None:
             resumedata = None
         else:
             resumedata = pstate['engineresumedata']
         self._hashcheckfunc = self.dow.initFiles(resumedata=resumedata)
     except Exception as e:
         self.fatalerrorfunc(e)