Add channel number to M3U line formatting

Add tvg-chno support using channel number from markdown lists

- Extract channel number from md lists
- Add tvg-chno attribute to M3U output
- Skip invalid values (e.g. 0)

Improves channel ordering in IPTV clients like Jellyfin
pull/1017/head
Giacinto Lo Meo 2026-04-07 22:34:16 +02:00 committed by GitHub
parent bce5e4ff6b
commit 15a049edc2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 4 additions and 2 deletions

View File

@ -93,6 +93,7 @@ COUNTRY_CODES = {
class Channel:
def __init__(self, group, md_line, country_code=""):
self.chno = self.number if self.number and self.number != "0" else None
self.group = group
self.country_code = country_code
md_line = md_line.strip()
@ -110,10 +111,11 @@ class Channel:
def to_m3u_line(self):
country = f' tvg-country="{self.country_code}"' if self.country_code else ""
chno = f' tvg-chno="{self.chno}"' if self.chno else ""
if self.epg is None:
return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}"{country} group-title="{self.group}",{self.name}\n{self.url}')
return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}"{chno}{country} group-title="{self.group}",{self.name}\n{self.url}')
else:
return (f'#EXTINF:-1 tvg-name="{self.name}" tvg-logo="{self.logo}" tvg-id="{self.epg}"{country} group-title="{self.group}",{self.name}\n{self.url}')
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 main():