From 5bacda49839b8403161857edace0078aee26e22d Mon Sep 17 00:00:00 2001 From: Pavel Glotov Date: Sun, 5 Mar 2023 12:39:06 +0400 Subject: [PATCH] Add converter - "convert_playlist.py" playlist.m3u8 to playlists by country in the folder "playlists" --- convert_playlist.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 convert_playlist.py diff --git a/convert_playlist.py b/convert_playlist.py new file mode 100644 index 0000000..0ae6a3c --- /dev/null +++ b/convert_playlist.py @@ -0,0 +1,35 @@ +# converts playlist.m3u8 to playlists by country in the playlists folder +import os + + +def main(): + dir_playlists = 'playlists' + # create folders for playlist countries + if not (os.path.isdir(dir_playlists)): + os.mkdir(dir_playlists) + # convert playlist to playlist countries + file_playlist = open("playlist.m3u8", "r", encoding='utf-8') + country_curent = 'not' + for line in file_playlist: + if line[:7] == '#EXTM3U': + head_playlist = line + elif line[:7] == '#EXTINF': + start_country = line.find('group-title') + 13 + end_country = line.find('"', start_country) + country_new = line[start_country:end_country] + if country_curent != country_new: + if not(country_curent == 'not'): + file_playlist_country.close() + country_curent = country_new + file_playlist_country = open(dir_playlists + "\playlist_" + country_curent + ".m3u8", "w", encoding='utf-8') + file_playlist_country.write(head_playlist) + file_playlist_country.write(line) + else: + file_playlist_country.write(line) + elif line[:4] == 'http': + file_playlist_country.write(line) + file_playlist_country.close() + + +if __name__ == "__main__": + main()