2021-04-13 14:16:51 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
2023-03-03 20:57:55 +01:00
|
|
|
EPG_LIST = open('epglist.txt',"r") # for a clean code
|
2021-04-13 14:16:51 +02:00
|
|
|
|
2022-12-31 00:56:32 +01:00
|
|
|
class Channel:
|
2021-04-13 14:16:51 +02:00
|
|
|
def __init__(self, group, md_line):
|
|
|
|
self.group = group
|
|
|
|
md_line = md_line.strip()
|
2022-12-31 00:56:32 +01:00
|
|
|
parts = md_line.split("|")
|
|
|
|
self.number = parts[1].strip()
|
|
|
|
self.name = parts[2].strip()
|
|
|
|
self.url = parts[3].strip()
|
2021-04-13 14:16:51 +02:00
|
|
|
self.url = self.url[self.url.find("(")+1:self.url.rfind(")")]
|
2022-12-31 00:56:32 +01:00
|
|
|
self.logo = parts[4].strip()
|
2021-04-13 14:16:51 +02:00
|
|
|
self.logo = self.logo[self.logo.find('src="')+5:self.logo.rfind('"')]
|
2022-12-31 00:56:32 +01:00
|
|
|
if len(parts) > 6:
|
|
|
|
self.epg = parts[5].strip()
|
|
|
|
else:
|
|
|
|
self.epg = None
|
2021-04-13 14:16:51 +02:00
|
|
|
|
|
|
|
def to_m3u_line(self):
|
2022-07-23 09:26:45 +02:00
|
|
|
if self.epg is None:
|
|
|
|
return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}" group-title="{self.group}",{self.name}\n{self.url}')
|
|
|
|
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}')
|
2021-04-13 14:16:51 +02:00
|
|
|
|
2023-03-05 12:32:33 +01:00
|
|
|
|
2022-12-31 00:56:32 +01:00
|
|
|
def main():
|
2023-03-05 12:32:33 +01:00
|
|
|
dir_playlists = 'playlists'
|
|
|
|
if not (os.path.isdir(dir_playlists)):
|
|
|
|
os.mkdir(dir_playlists)
|
2021-07-14 15:15:32 +02:00
|
|
|
with open("playlist.m3u8", "w", encoding='utf-8') as playlist:
|
2023-03-15 06:57:43 +01:00
|
|
|
processed_epg_list = ", ".join(EPG_LIST).replace('\n', '')
|
2023-03-15 06:55:55 +01:00
|
|
|
head_playlist = f'#EXTM3U x-tvg-url="{processed_epg_list}"'
|
|
|
|
print(f'#EXTM3U x-tvg-url="{processed_epg_list}"', file=playlist)
|
2022-09-02 13:19:54 +02:00
|
|
|
os.chdir("lists")
|
2021-04-13 14:16:51 +02:00
|
|
|
for filename in sorted(os.listdir(".")):
|
|
|
|
if filename == "README.md" or not filename.endswith(".md"):
|
|
|
|
continue
|
2021-07-14 15:15:32 +02:00
|
|
|
with open(filename, encoding='utf-8') as markup_file:
|
2023-03-14 06:21:22 +01:00
|
|
|
file_country = os.path.join("..", dir_playlists, "playlist_" + filename[:-3:] + ".m3u8")
|
2023-03-05 12:32:33 +01:00
|
|
|
playlist_country = open(file_country, "w", encoding='utf-8')
|
2023-03-18 06:52:44 +01:00
|
|
|
playlist_country.write(head_playlist + "\n")
|
2021-04-13 14:16:51 +02:00
|
|
|
group = filename.replace(".md", "").title()
|
2021-08-17 14:15:41 +02:00
|
|
|
print(f"Generating {group}")
|
2021-04-13 14:16:51 +02:00
|
|
|
for line in markup_file:
|
|
|
|
if "<h1>" in line.lower() and "</h1>" in line.lower():
|
|
|
|
group = re.sub('<[^<>]+>', '', line.strip())
|
|
|
|
if not "[>]" in line:
|
|
|
|
continue
|
|
|
|
channel = Channel(group, line)
|
|
|
|
print(channel.to_m3u_line(), file=playlist)
|
2023-03-05 12:32:33 +01:00
|
|
|
print(channel.to_m3u_line(), file=playlist_country)
|
|
|
|
playlist_country.close()
|
2022-12-31 00:56:32 +01:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|