Skip to content

Commit 9594188

Browse files
committed
feat: Enhance M3U parser to normalize URLs based on server address
- Added a `normalizeUrl` function to replace protocol, hostname, and port in URLs with the current window location if they match the server address. - Updated `parseM3U` function to accept an optional `serverAddress` parameter and normalize `tvgUrl`, `catchupSource`, and channel URLs accordingly. - Modified `PlayerPage` to extract the server address from the `X-Server-Address` header and pass it to the `parseM3U` function.
1 parent 32e97cf commit 9594188

File tree

6 files changed

+6634
-6553
lines changed

6 files changed

+6634
-6553
lines changed

src/connection.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -967,12 +967,25 @@ static void handle_playlist_request(connection_t *c)
967967
}
968968

969969
size_t playlist_len = strlen(playlist);
970-
char extra_headers[128];
970+
char *server_addr = get_server_address();
971+
char extra_headers[256];
971972

972-
snprintf(extra_headers, sizeof(extra_headers),
973-
"Content-Type: audio/x-mpegurl\r\n"
974-
"Content-Length: %zu\r\n",
975-
playlist_len);
973+
if (server_addr)
974+
{
975+
snprintf(extra_headers, sizeof(extra_headers),
976+
"Content-Type: audio/x-mpegurl\r\n"
977+
"Content-Length: %zu\r\n"
978+
"X-Server-Address: %s\r\n",
979+
playlist_len, server_addr);
980+
free(server_addr);
981+
}
982+
else
983+
{
984+
snprintf(extra_headers, sizeof(extra_headers),
985+
"Content-Type: audio/x-mpegurl\r\n"
986+
"Content-Length: %zu\r\n",
987+
playlist_len);
988+
}
976989

977990
send_http_headers(c, STATUS_200, CONTENT_HTML, extra_headers);
978991
connection_queue_output_and_flush(c, (const uint8_t *)playlist, playlist_len);

src/m3u.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ static int is_private_ipv4(const char *ip_str)
254254
* Priority: hostname config > non-upstream interface private IP > non-upstream interface public IP > upstream interface IP > localhost
255255
* Returns: malloc'd string (caller must free)
256256
*/
257-
static char *get_server_address(void)
257+
char *get_server_address(void)
258258
{
259259
struct ifaddrs *ifaddr, *ifa;
260260
char *result = NULL;

src/m3u.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,10 @@ void m3u_reset_transformed_playlist(void);
3737
*/
3838
void m3u_reset_external_playlist(void);
3939

40+
/* Get server hostname or IP address with priority logic
41+
* Priority: hostname config > non-upstream interface private IP > non-upstream interface public IP > upstream interface IP > localhost
42+
* Returns: malloc'd string (caller must free)
43+
*/
44+
char *get_server_address(void);
45+
4046
#endif /* __M3U_H__ */

0 commit comments

Comments
 (0)