Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 20 additions & 4 deletions web-ui/src/lib/m3u-parser.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import type { PlayerSegment } from "../mpegts";
import type { Channel, M3UMetadata, Source } from "../types/player";
import { toPlaylistRelativePath } from "./url";

/**
* Parse M3U playlist content
Expand Down Expand Up @@ -34,15 +35,15 @@ export function parseM3U(content: string): M3UMetadata {
if (line.startsWith("#EXTM3U")) {
const tvgUrlMatch = line.match(/x-tvg-url="([^"]+)"/);
if (tvgUrlMatch) {
tvgUrl = tvgUrlMatch[1];
tvgUrl = toPlaylistRelativePath(tvgUrlMatch[1]);
}
const catchupMatch = line.match(/catchup="([^"]+)"/);
if (catchupMatch) {
defaultCatchup = catchupMatch[1];
}
const catchupSourceMatch = line.match(/catchup-source="([^"]+)"/);
if (catchupSourceMatch) {
defaultCatchupSource = catchupSourceMatch[1];
defaultCatchupSource = toPlaylistRelativePath(catchupSourceMatch[1]);
}
continue;
}
Expand Down Expand Up @@ -77,7 +78,7 @@ export function parseM3U(content: string): M3UMetadata {
tvgId: tvgIdMatch?.[1],
tvgName: tvgNameMatch?.[1],
catchup: catchupMatch?.[1] || defaultCatchup,
catchupSource: catchupSourceMatch?.[1] || defaultCatchupSource,
catchupSource: resolveCatchupSource(catchupSourceMatch?.[1] || defaultCatchupSource),
};
continue;
}
Expand All @@ -87,6 +88,9 @@ export function parseM3U(content: string): M3UMetadata {
// Extract optional $<label> suffix from URL (e.g., "http://...url$UHD" → label "UHD")
const labelMatch = line.match(/\$([^$]+)$/);
const sourceLabel = labelMatch ? labelMatch[1] : undefined;
const urlWithoutLabel = labelMatch ? line.slice(0, line.lastIndexOf("$")) : line;
const resolvedUrl =
toPlaylistRelativePath(urlWithoutLabel) + (labelMatch ? line.slice(line.lastIndexOf("$")) : "");

channels.push({
id: `${channels.length + 1}`,
Expand All @@ -96,7 +100,12 @@ export function parseM3U(content: string): M3UMetadata {
tvgId: currentExtinf.tvgId,
tvgName: currentExtinf.tvgName,
sources: [
{ url: line, catchup: currentExtinf.catchup, catchupSource: currentExtinf.catchupSource, label: sourceLabel },
{
url: resolvedUrl,
catchup: currentExtinf.catchup,
catchupSource: currentExtinf.catchupSource,
label: sourceLabel,
},
],
});
currentExtinf = null;
Expand All @@ -114,6 +123,13 @@ function isPlaylistUrl(line: string): boolean {
return line.startsWith("/") || line.startsWith("http://") || line.startsWith("https://");
}

function resolveCatchupSource(value: string | undefined): string | undefined {
if (!value) {
return value;
}
return toPlaylistRelativePath(value);
}

function parseGroupTitles(line: string): string[] {
const seenGroups = new Set<string>();
const groups: string[] = [];
Expand Down
22 changes: 22 additions & 0 deletions web-ui/src/lib/url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,25 @@ export function buildStatusPath(suffix: string): string {

return `${basePath}${normalizedSuffix}`;
}

/**
* Strip scheme/host from playlist URLs, leaving site-root-relative paths.
* Matches server use-relative-path-in-m3u output (e.g. /app/rtp2httpd/Channel).
* Query-only templates (e.g. ?playseek=...) are returned unchanged.
*/
export function toPlaylistRelativePath(url: string): string {
if (!url) {
return url;
}

if (!url.startsWith("http://") && !url.startsWith("https://")) {
return url;
}

try {
const parsed = new URL(url);
return `${parsed.pathname}${parsed.search}${parsed.hash}`;
Comment thread
stackia marked this conversation as resolved.
} catch {
return url;
}
}
Loading