Fixed groups/categories

This commit is contained in:
Ignacio Rivero 2025-03-10 02:37:03 -03:00
parent dd34e76002
commit 47aaef4053

View File

@ -27,16 +27,35 @@ def get_channels():
lines = response.text.splitlines()
channels = []
regex = re.compile(r'tvg-logo="(.*?)".*?group-title="(.*?)"', re.IGNORECASE)
# Match tvg-logo and group-title attributes
logo_group_regex = re.compile(r'tvg-logo="(.*?)".*?group-title="(.*?)"', re.IGNORECASE)
for i in range(len(lines)):
if lines[i].startswith("#EXTINF"):
match = regex.search(lines[i])
match = logo_group_regex.search(lines[i])
logo = match.group(1) if match else ""
group = match.group(2) if match else "Other"
# Handle multiple groups separated by semicolons
groups = []
if match and match.group(2):
# Split by semicolon and create a channel entry for each group
groups = [group.strip() for group in match.group(2).split(';')]
# Default to "Other" if no groups found
if not groups:
groups = ["Other"]
name = lines[i].split(",")[-1]
url = lines[i + 1]
# Create a channel entry for the primary group
primary_group = groups[0]
channels.append({"name": name, "url": url, "logo": logo, "group": primary_group})
# Create additional channel entries for secondary groups if present
for group in groups[1:]:
if group: # Skip empty groups
channels.append({"name": name, "url": url, "logo": logo, "group": group})
return channels