From 5bacda49839b8403161857edace0078aee26e22d Mon Sep 17 00:00:00 2001 From: Pavel Glotov Date: Sun, 5 Mar 2023 12:39:06 +0400 Subject: [PATCH 1/3] 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() From 614d48381f71074a0ca66ae59da09e552fbbbf97 Mon Sep 17 00:00:00 2001 From: Pavel Glotov Date: Sun, 5 Mar 2023 15:32:33 +0400 Subject: [PATCH 2/3] added creation of separate playlist files by country to the playlists directory --- make_playlist.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/make_playlist.py b/make_playlist.py index a07d26d..daa7aa5 100755 --- a/make_playlist.py +++ b/make_playlist.py @@ -27,14 +27,22 @@ class Channel: else: return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}" tvg-id="{self.epg}" group-title="{self.group}",{self.name}\n{self.url}') + def main(): + dir_playlists = 'playlists' + if not (os.path.isdir(dir_playlists)): + os.mkdir(dir_playlists) with open("playlist.m3u8", "w", encoding='utf-8') as playlist: + head_playlist = '#EXTM3U x-tvg-url="{",".join(EPG_LIST)}"' print(f'#EXTM3U x-tvg-url="{",".join(EPG_LIST)}"', file=playlist) os.chdir("lists") for filename in sorted(os.listdir(".")): if filename == "README.md" or not filename.endswith(".md"): continue with open(filename, encoding='utf-8') as markup_file: + file_country = "../" + dir_playlists + "\playlist_" + filename[:-3:] + ".m3u8" + playlist_country = open(file_country, "w", encoding='utf-8') + playlist_country.write(head_playlist) group = filename.replace(".md", "").title() print(f"Generating {group}") for line in markup_file: @@ -44,6 +52,8 @@ def main(): continue channel = Channel(group, line) print(channel.to_m3u_line(), file=playlist) + print(channel.to_m3u_line(), file=playlist_country) + playlist_country.close() if __name__ == "__main__": main() From 1cb92a772704bcf85be4278036bf9eb4c5f2a212 Mon Sep 17 00:00:00 2001 From: glotovpa <57413895+glotovpa@users.noreply.github.com> Date: Sun, 5 Mar 2023 15:35:08 +0400 Subject: [PATCH 3/3] Delete convert_playlist.py --- convert_playlist.py | 35 ----------------------------------- 1 file changed, 35 deletions(-) delete mode 100644 convert_playlist.py diff --git a/convert_playlist.py b/convert_playlist.py deleted file mode 100644 index 0ae6a3c..0000000 --- a/convert_playlist.py +++ /dev/null @@ -1,35 +0,0 @@ -# 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()