From e4569f68bceffd2decb631c930b43dc79c154dfe Mon Sep 17 00:00:00 2001 From: Gerardo Zinno Date: Sun, 11 Oct 2026 18:25:00 +0200 Subject: [PATCH 1/4] Use Path instead of os.path --- make_playlist.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/make_playlist.py b/make_playlist.py index 84a591a..b972edb 100755 --- a/make_playlist.py +++ b/make_playlist.py @@ -1,8 +1,8 @@ #!/usr/bin/python3 """Generate M3U playlists from the markdown channel lists in lists/.""" -import os import re +from pathlib import Path COUNTRY_CODES = { "albania": "AL", @@ -135,25 +135,26 @@ class Channel: # pylint: disable=too-few-public-methods,too-many-instance-attri def main(): # pylint: disable=too-many-locals """Build the combined playlist.m3u8 and one per-country playlist.""" - base_dir = os.path.dirname(os.path.abspath(__file__)) - lists_dir = os.path.join(base_dir, "lists") - dir_playlists = os.path.join(base_dir, "playlists") + base_dir = Path(__file__).resolve().parent - if not os.path.isdir(dir_playlists): - os.mkdir(dir_playlists) + lists_dir = base_dir / "lists" + dir_playlists = base_dir / "playlists" - with open(os.path.join(base_dir, "epglist.txt"), encoding='utf-8') as epg_file: + if not dir_playlists.is_dir(): + dir_playlists.mkdir() + + with open(base_dir / "epglist.txt", encoding='utf-8') as epg_file: epg_urls = [line.strip() for line in epg_file if line.strip()] processed_epg_list = ", ".join(epg_urls) 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) - for filename in sorted(os.listdir(lists_dir)): + for filename in sorted(p.name for p in lists_dir.iterdir()): if filename == "README.md" or not filename.endswith(".md"): continue - markup_path = os.path.join(lists_dir, filename) - country_path = os.path.join(dir_playlists, "playlist_" + filename[:-3] + ".m3u8") + markup_path = lists_dir / filename + country_path = dir_playlists / ("playlist_" + filename[:-3] + ".m3u8") country_key = filename[:-3] group = country_key.replace("_", " ").title() country_code = COUNTRY_CODES.get(country_key, "") From 091f40530a129cc09ca26b178bfe0289a5d095f9 Mon Sep 17 00:00:00 2001 From: Gerardo Zinno Date: Sun, 11 Oct 2026 18:30:18 +0200 Subject: [PATCH 2/4] Use f-string instead of concat --- make_playlist.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/make_playlist.py b/make_playlist.py index b972edb..6bf6c5b 100755 --- a/make_playlist.py +++ b/make_playlist.py @@ -154,7 +154,7 @@ def main(): # pylint: disable=too-many-locals if filename == "README.md" or not filename.endswith(".md"): continue markup_path = lists_dir / filename - country_path = dir_playlists / ("playlist_" + filename[:-3] + ".m3u8") + country_path = dir_playlists / f"playlist_{filename[:-3]}.m3u8" country_key = filename[:-3] group = country_key.replace("_", " ").title() country_code = COUNTRY_CODES.get(country_key, "") From 48406cea0395f14bb36b24d199ae747ac4e3171d Mon Sep 17 00:00:00 2001 From: Gerardo Zinno Date: Sun, 11 Oct 2026 18:35:48 +0200 Subject: [PATCH 3/4] Filter suffixes in list generator --- make_playlist.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/make_playlist.py b/make_playlist.py index 6bf6c5b..2f4a637 100755 --- a/make_playlist.py +++ b/make_playlist.py @@ -150,8 +150,8 @@ def main(): # pylint: disable=too-many-locals with open(base_dir / "playlist.m3u8", "w", encoding='utf-8') as playlist: playlist.write(head_playlist) - for filename in sorted(p.name for p in lists_dir.iterdir()): - if filename == "README.md" or not filename.endswith(".md"): + for filename in sorted(p.name for p in lists_dir.iterdir() if p.suffix == ".md"): + if filename == "README.md": continue markup_path = lists_dir / filename country_path = dir_playlists / f"playlist_{filename[:-3]}.m3u8" From 62c5db50d4c2cbf1311efc82a9fdd50d642890a4 Mon Sep 17 00:00:00 2001 From: Gerardo Zinno Date: Sun, 11 Oct 2026 18:40:28 +0200 Subject: [PATCH 4/4] Replace if check with mkdir exist_ok --- make_playlist.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/make_playlist.py b/make_playlist.py index 2f4a637..a9764c7 100755 --- a/make_playlist.py +++ b/make_playlist.py @@ -140,8 +140,7 @@ def main(): # pylint: disable=too-many-locals lists_dir = base_dir / "lists" dir_playlists = base_dir / "playlists" - if not dir_playlists.is_dir(): - dir_playlists.mkdir() + 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()]