-
Notifications
You must be signed in to change notification settings - Fork 727
/
make_playlist.py
39 lines (32 loc) · 1.45 KB
/
make_playlist.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/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):
return('#EXTINF:-1 tvg-name="%(name)s" tvg-logo="%(logo)s" group-title="%(group)s",%(name)s\n%(url)s' \
% {'name':self.name, 'logo':self.logo, 'group':self.group, 'url':self.url})
if __name__ == "__main__":
with open("playlist.m3u8", "w") as playlist:
print("#EXTM3U", file=playlist)
for filename in sorted(os.listdir(".")):
if filename == "README.md" or not filename.endswith(".md"):
continue
with open(filename) as markup_file:
group = filename.replace(".md", "").title()
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)