Add support for optional channel-id in M3U endpoint

This commit is contained in:
Mat Gadd
2025-11-07 02:34:54 +00:00
parent b7812f4d23
commit 629171b1d0
2 changed files with 16 additions and 1 deletions

View File

@@ -118,6 +118,7 @@ GET /m3u
- `wanted_groups` (optional): A comma-separated list of group names to include (takes precedence over unwanted_groups)
- `nostreamproxy` (optional): Set to 'true' to disable stream proxying
- `proxy_url` (optional): Custom base URL for proxied content (overrides auto-detection)
- `include_channel_id` (optional): Set to 'true' to include `channel-id` in M3U, useful for [Channels](https://getchannels.com)
Note: For `unwanted_groups` and `wanted_groups`, you can use wildcard patterns with `*` and `?` characters. For example:
- `US*` will match all groups starting with "US"

16
run.py
View File

@@ -617,12 +617,14 @@ def generate_m3u():
wanted_groups = parse_group_list(data.get("wanted_groups", ""))
no_stream_proxy = str(data.get("nostreamproxy", "")).lower() == "true"
include_vod = str(data.get("include_vod", "false")).lower() == "true"
include_channel_id = str(data.get("include_channel_id", "false")).lower() == "true"
logger.info("🔄 Processing POST request for M3U generation")
else:
unwanted_groups = parse_group_list(request.args.get("unwanted_groups", ""))
wanted_groups = parse_group_list(request.args.get("wanted_groups", ""))
no_stream_proxy = request.args.get("nostreamproxy", "").lower() == "true"
include_vod = request.args.get("include_vod", "false").lower() == "true"
include_channel_id = request.args.get("include_channel_id", "false") == "true"
logger.info("🔄 Processing GET request for M3U generation")
# For M3U generation, warn about VOD performance impact
@@ -722,12 +724,24 @@ def generate_m3u():
if include_stream:
included_groups.add(group_title)
tags = [
f'tvg-name="{stream_name}"',
f'group-title="{group_title}"',
]
# Handle logo URL - proxy only if stream proxying is enabled
original_logo = stream.get("stream_icon", "")
if original_logo and not no_stream_proxy:
logo_url = f"{proxy_url}/image-proxy/{encode_url(original_logo)}"
else:
logo_url = original_logo
tags.append(f'tvg-logo="{logo_url}"')
# Handle channel id if enabled
if include_channel_id:
channel_id = stream.get("epg_channel_id")
if channel_id:
tags.append(f'channel-id="{channel_id}"')
# Create the stream URL based on content type
if content_type == "live":
@@ -756,7 +770,7 @@ def generate_m3u():
# Add stream to playlist
m3u_playlist += (
f'#EXTINF:0 tvg-name="{stream_name}" group-title="{group_title}" tvg-logo="{logo_url}",{stream_name}\n'
f'#EXTINF:0 {" ".join(tags)},{stream_name}\n'
)
m3u_playlist += f"{stream_url}\n"