def main(): if (len(sys.argv)) != 2: Log.fatal('Needs channel to record!') channel_name = sys.argv[1] recorder = Recorder() signal.signal(signal.SIGINT, lambda sig, frame: recorder.stop()) recorder.record(channel_name)
def main(): (start_time, end_time, vod_id) = CommandLineParser().parse_command_line() m3u8_playlist = PlaylistFetcher().fetch_for_vod(vod_id) if m3u8_playlist is None: Log.fatal("Seems like vod {} doesn't exist".format(vod_id)) playlist = Chunks.get(m3u8_playlist.segments, start_time, end_time) file_name = FileMaker.make_avoiding_overwrite(Vod.title(vod_id) + '.ts') downloader = PlaylistDownloader(playlist) signal.signal(signal.SIGINT, lambda sig, frame: downloader.stop()) downloader.download_to(file_name)
def download_to(self, file_name): playlist = self.playlist progress_bar = ProgressBar(file_name, len(playlist.segments)) with open(file_name, 'wb+') as file: for segment in playlist.segments: if self.stopped: print('') break try: for chunk in Contents.chunked(segment): if chunk: file.write(chunk) except IOError as e: Log.fatal(str(e)) progress_bar.update_by(1)
def parse_command_line(self): (options, args) = self.parse_args() if len(args) != 1: Log.fatal(self.get_usage()) if options.end_time <= options.start_time: Log.fatal("End time can't be earlier than start time\n") try: return options.start_time, options.end_time, int(args[0]) except ValueError: Log.fatal(self.get_usage())