def _download_file(self, f): l = HLS.make_url(self._file_playlist.url, f['file']) name = urlparse.urlparse(f['file']).path.split('/')[-1] path = os.path.join(self.path, name) d = self._download_page(l, path) d.addCallback(self._got_file, l, f) return d
def _download_segment(self, f): url = HLS.make_url(self._file_playlist.url, f['file']) name = urlparse.urlparse(f['file']).path.split('/')[-1] path = os.path.join(self.path, name) d = self._download_page(url, path) if self.n_segments_keep != 0: file = open(path, 'w') d.addCallback(lambda x: file.write(x)) d.addBoth(lambda _: file.close()) d.addCallback(lambda _: path) d.addErrback(self._got_file_failed) d.addCallback(self._got_file, url, f) else: d.addCallback(lambda _: (None, path, f)) return d
def _playlist_updated(self, pl): if pl.has_programs(): # if we got a program playlist, save it and start a program self._program_playlist = pl (program_url, _) = pl.get_program_playlist(self.program, self.bitrate) l = HLS.make_url(self.url, program_url) return self._reload_playlist(M3U8(l)) elif pl.has_files(): # we got sequence playlist, start reloading it regularly, and get files self._file_playlist = pl if not self._files: self._files = pl.iter_files() if not pl.endlist(): reactor.callLater(pl.reload_delay(), self._reload_playlist, pl) if self._file_playlisted: self._file_playlisted.callback(pl) self._file_playlisted = None else: raise return pl