/
crocouser
/
AutoIPTVPlaylist
Обзор
Документация
Войти
/
crocouser
/
AutoIPTVPlaylist
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
main
src/parser.py
56 строк
2 KB
sahadat-savar
Add files via upload
05 июл 2026, 00:25
Не верифицирован
05 июл 2026, 00:25
f91488f
Код
Авторство
О чём код?
"""Minimal, fast M3U/M3U8 parser. Returns a list of channel dicts: { "name": str, "url": str, "attrs": {tvg-id, tvg-name, tvg-logo, group-title, ...}, "extras": [raw #EXTVLCOPT / #KODIPROP lines to preserve headers], "source": str, } """ import re ATTR_RE = re.compile(r'([\w-]+)="([^"]*)"') def parse_m3u(text, source=""): entries = [] pending = None for raw in text.splitlines(): s = raw.strip() if not s: continue if s.startswith("#EXTINF"): attrs = dict(ATTR_RE.findall(s)) name = s.split(",", 1)[1].strip() if "," in s else "" pending = {"attrs": attrs, "name": name, "extras": []} elif s.startswith("#EXTGRP"): grp = s.split(":", 1)[1].strip() if ":" in s else "" if pending is not None: pending["extras"].append(s) if grp: pending["attrs"].setdefault("group-title", grp) elif s.startswith(("#EXTVLCOPT", "#KODIPROP", "#EXTHTTP", "#EXT-X")): # Stream headers (user-agent / referer / drm) — keep them. if pending is not None: pending["extras"].append(s) elif s.startswith("#"): # #EXTM3U and other comments -> ignore continue else: # URL line if pending is None: pending = {"attrs": {}, "name": s, "extras": []} pending["url"] = s pending["source"] = source entries.append(pending) pending = None return entries