def state_callback(self, ds): download = ds.get_download() if ds.get_vod_prebuffering_progress() == 1.0: self._logger.debug("Test: state_callback") stream = VODFile(open(download.get_content_dest(), 'rb'), download) # Read last piece lastpieceoff = ( (self.contentlen - 1) / self.piecelen) * self.piecelen lastpiecesize = self.contentlen - lastpieceoff self._logger.debug("stream: lastpieceoff %s %s", lastpieceoff, lastpiecesize) self.stream_read(stream, lastpieceoff, lastpiecesize, self.piecelen) # Read second,3rd,4th byte, only secoff = 1 secsize = 3 blocksize = 3 self.stream_read(stream, secoff, secsize, blocksize) # Read last byte lastoff = self.contentlen - 1 lastsize = 1 self.stream_read(stream, lastoff, lastsize, self.piecelen) self.test_deferred.callback(None) return 0 return 1.0
def get_vod_stream(self, dl_hash, wait=False): if 'stream' not in self.vod_info[ dl_hash] and self.session.get_download(dl_hash): download = self.session.get_download(dl_hash) vod_filename = self.get_vod_destination(download) while wait and not os.path.exists(vod_filename): time.sleep(1) self.vod_info[dl_hash]['stream'] = (VODFile( open(vod_filename, 'rb'), download), RLock()) if self.vod_info[dl_hash].has_key('stream'): return self.vod_info[dl_hash]['stream'] return None, None