diff --git a/make_playlist.py b/make_playlist.py index 143655c..8ecfcf2 100755 --- a/make_playlist.py +++ b/make_playlist.py @@ -90,6 +90,16 @@ COUNTRY_CODES = { "venezuela": "VE", } +ARABIC_PRIORITY_COUNTRIES = { + "chad", + "egypt", + "iraq", + "qatar", + "saudi_arabia", + "somalia", + "united_arab_emirates", +} + class Channel: def __init__(self, group, md_line, country_code=""): @@ -120,6 +130,12 @@ class Channel: return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}" tvg-id="{self.epg}"{chno}{country} group-title="{self.group}",{self.name}\n{self.url}') +def playlist_sort_key(filename): + country_key = filename[:-3] + arabic_priority = country_key.endswith("_ar") or country_key in ARABIC_PRIORITY_COUNTRIES + return (0 if arabic_priority else 1, filename) + + def main(): base_dir = os.path.dirname(os.path.abspath(__file__)) lists_dir = os.path.join(base_dir, "lists") @@ -135,7 +151,7 @@ def main(): with open(os.path.join(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(os.listdir(lists_dir), key=playlist_sort_key): if filename == "README.md" or not filename.endswith(".md"): continue markup_path = os.path.join(lists_dir, filename)