2021-04-13 14:16:51 +02:00
|
|
|
#!/usr/bin/python3
|
|
|
|
|
|
|
|
import os
|
|
|
|
import re
|
|
|
|
|
|
|
|
class Channel():
|
|
|
|
|
|
|
|
def __init__(self, group, md_line):
|
|
|
|
self.group = group
|
|
|
|
md_line = md_line.strip()
|
|
|
|
(before, number, name, url, logo, after) = md_line.split("|")
|
|
|
|
self.number = number.strip()
|
|
|
|
self.name = name.strip()
|
|
|
|
self.url = url.strip()
|
|
|
|
self.url = self.url[self.url.find("(")+1:self.url.rfind(")")]
|
|
|
|
self.logo = logo.strip()
|
|
|
|
self.logo = self.logo[self.logo.find('src="')+5:self.logo.rfind('"')]
|
|
|
|
|
|
|
|
def to_m3u_line(self):
|
2021-08-17 14:15:41 +02:00
|
|
|
return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}" group-title="{self.group}",{self.name}\n{self.url}')
|
2021-04-13 14:16:51 +02:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2021-07-14 15:15:32 +02:00
|
|
|
with open("playlist.m3u8", "w", encoding='utf-8') as playlist:
|
2021-04-13 14:16:51 +02:00
|
|
|
print("#EXTM3U", file=playlist)
|
|
|
|
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:
|
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)
|
2021-08-17 14:15:41 +02:00
|
|
|
|