added creation of separate playlist files by country to the playlists directory

pull/309/head
Pavel Glotov 2023-03-05 15:32:33 +04:00
parent c4103457e1
commit 614d48381f
1 changed files with 10 additions and 0 deletions

View File

@ -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()