def test_playlist_durataion_generation(self): """When a user provides a playlist it needs to count the total duration.""" playlist_duration = PlaylistGenerator( playlist_entries=self.playlist_entries).duration self.assertEquals(playlist_duration, 40, msg="Ensure duration is counted")
def test_end_of_is_not_included(self): """Ensures that the end playlist is included""" playlist = PlaylistGenerator(self.playlist_entries, version=3) playlist.end_playlist = False self.assertTrue('#EXT-X-ENDLIST' not in playlist.generate())
def test_end_of_playlist(self): """Ensures that the end playlist is included""" playlist = PlaylistGenerator(self.playlist_entries, version=3).generate() self.assertTrue('#EXT-X-ENDLIST' in playlist)
def test_playlist_header_sequence_generation(self): """Make sure there is the sequence""" header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template() self.assertTrue('EXT-X-MEDIA-SEQUENCE:0' in header)
def test_playlist_header_duration_generation(self): """Make sure there is the duration identifier """ header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template() self.assertTrue('EXT-X-TARGETDURATION:40' in header)
def test_playlist_header_generation(self): """Make sure there is the EXTM3U on the firstline""" header = PlaylistGenerator(self.playlist_entries, version=3)._m3u8_header_template() self.assertTrue('EXTM3U' in header)
dest='append', action='store_true', help='Append Mode') # store_true表示如果解析到该项则赋值为True parser.add_argument('--header', default="", type=str, help='Header (JSON)') # 网络请求头键值对的JSON对象序列化得到的二进制文件 parser.add_argument('--cookie', default="", type=str, help='Cookie (JSON)') # cookie键值对的JSON对象序列化得到的二进制文件 args = parser.parse_args() playlist_url = args.url logger.info("Playlist URL: " + playlist_url) control = requests.Session() # m3u8文件下载会话 data_pool = grequests.Pool(pool_size) # ts文件下载协程池 output_playlist_entries = [] output_playlist = PlaylistGenerator(playlist_entries=output_playlist_entries, version=3) # 输出Playlist output_playlist_files_obsoleted = [] os.makedirs(args.directory, exist_ok=True) # 是否进行断点续传 if args.tail_time: tail_mode = True tail_dur = int(args.tail_time) # 是否存在指定的输出文件,如果没有则单独下载每一个ts文件;否则讲这些ts文件合并到该输出文件中 if args.file: file_mode = True out_file = args.file else: file_mode = False