Merge branch 'pr-1219'

This commit is contained in:
Kálmán „KAMI” Szalai
2026-10-15 00:56:09 +02:00
+12 -12
View File
@@ -1,8 +1,8 @@
#!/usr/bin/python3 #!/usr/bin/python3
"""Generate M3U playlists from the markdown channel lists in lists/.""" """Generate M3U playlists from the markdown channel lists in lists/."""
import os
import re import re
from pathlib import Path
COUNTRY_CODES = { COUNTRY_CODES = {
"albania": "AL", "albania": "AL",
@@ -135,25 +135,25 @@ class Channel: # pylint: disable=too-few-public-methods,too-many-instance-attri
def main(): # pylint: disable=too-many-locals def main(): # pylint: disable=too-many-locals
"""Build the combined playlist.m3u8 and one per-country playlist.""" """Build the combined playlist.m3u8 and one per-country playlist."""
base_dir = os.path.dirname(os.path.abspath(__file__)) base_dir = Path(__file__).resolve().parent
lists_dir = os.path.join(base_dir, "lists")
dir_playlists = os.path.join(base_dir, "playlists")
if not os.path.isdir(dir_playlists): lists_dir = base_dir / "lists"
os.mkdir(dir_playlists) dir_playlists = base_dir / "playlists"
with open(os.path.join(base_dir, "epglist.txt"), encoding='utf-8') as epg_file: dir_playlists.mkdir(exist_ok=True)
with open(base_dir / "epglist.txt", encoding='utf-8') as epg_file:
epg_urls = [line.strip() for line in epg_file if line.strip()] epg_urls = [line.strip() for line in epg_file if line.strip()]
processed_epg_list = ", ".join(epg_urls) processed_epg_list = ", ".join(epg_urls)
head_playlist = f'#EXTM3U x-tvg-url="{processed_epg_list}"\n' head_playlist = f'#EXTM3U x-tvg-url="{processed_epg_list}"\n'
with open(os.path.join(base_dir, "playlist.m3u8"), "w", encoding='utf-8') as playlist: with open(base_dir / "playlist.m3u8", "w", encoding='utf-8') as playlist:
playlist.write(head_playlist) playlist.write(head_playlist)
for filename in sorted(os.listdir(lists_dir)): for filename in sorted(p.name for p in lists_dir.iterdir() if p.suffix == ".md"):
if filename == "README.md" or not filename.endswith(".md"): if filename == "README.md":
continue continue
markup_path = os.path.join(lists_dir, filename) markup_path = lists_dir / filename
country_path = os.path.join(dir_playlists, "playlist_" + filename[:-3] + ".m3u8") country_path = dir_playlists / f"playlist_{filename[:-3]}.m3u8"
country_key = filename[:-3] country_key = filename[:-3]
group = country_key.replace("_", " ").title() group = country_key.replace("_", " ").title()
country_code = COUNTRY_CODES.get(country_key, "") country_code = COUNTRY_CODES.get(country_key, "")