MCPcopy
hub / github.com/Free-TV/IPTV / main

Function main

make_playlist.py:123–158  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

121
122
123def main():
124 base_dir = os.path.dirname(os.path.abspath(__file__))
125 lists_dir = os.path.join(base_dir, "lists")
126 dir_playlists = os.path.join(base_dir, "playlists")
127
128 if not os.path.isdir(dir_playlists):
129 os.mkdir(dir_playlists)
130
131 with open(os.path.join(base_dir, "epglist.txt"), encoding='utf-8') as epg_file:
132 epg_urls = [line.strip() for line in epg_file if line.strip()]
133 processed_epg_list = ", ".join(epg_urls)
134 head_playlist = f'#EXTM3U x-tvg-url="{processed_epg_list}"\n'
135
136 with open(os.path.join(base_dir, "playlist.m3u8"), "w", encoding='utf-8') as playlist:
137 playlist.write(head_playlist)
138 for filename in sorted(os.listdir(lists_dir)):
139 if filename == "README.md" or not filename.endswith(".md"):
140 continue
141 markup_path = os.path.join(lists_dir, filename)
142 country_path = os.path.join(dir_playlists, "playlist_" + filename[:-3] + ".m3u8")
143 country_key = filename[:-3]
144 group = country_key.replace("_", " ").title()
145 country_code = COUNTRY_CODES.get(country_key, "")
146 print(f"Generating {group}")
147 with open(markup_path, encoding='utf-8') as markup_file, \
148 open(country_path, "w", encoding='utf-8') as playlist_country:
149 playlist_country.write(head_playlist)
150 for line in markup_file:
151 if "<h1>" in line.lower() and "</h1>" in line.lower():
152 group = re.sub('<[^<>]+>', '', line.strip())
153 if "[>]" not in line:
154 continue
155 channel = Channel(group, line, country_code)
156 m3u_line = channel.to_m3u_line()
157 print(m3u_line, file=playlist)
158 print(m3u_line, file=playlist_country)
159
160if __name__ == "__main__":
161 main()

Callers 1

make_playlist.pyFile · 0.85

Calls 2

to_m3u_lineMethod · 0.95
ChannelClass · 0.85

Tested by

no test coverage detected