Skip to content

Commit 1e0c3e7

Browse files
authored
feat: parse contentid from path (#25)
1 parent 3fe191a commit 1e0c3e7

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

demo/demo.js

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,28 @@ document.addEventListener("DOMContentLoaded", () => {
6464
videoElement.src = url;
6565
}
6666

67-
const contentId = url.split("/").pop() || "";
67+
const parsedUrl = new URL(url);
68+
let contentId;
69+
if (
70+
parsedUrl.pathname.endsWith(".m3u8") ||
71+
parsedUrl.pathname.endsWith(".mpd")
72+
) {
73+
// Extract path up to the last slash for manifest files
74+
const lastSlashIndex = parsedUrl.pathname.lastIndexOf("/");
75+
contentId =
76+
lastSlashIndex > 0
77+
? parsedUrl.pathname.substring(0, lastSlashIndex)
78+
: parsedUrl.pathname;
79+
} else {
80+
// Use filename for other files
81+
const pathSegments = parsedUrl.pathname.split("/");
82+
contentId = pathSegments[pathSegments.length - 1];
83+
// Remove file extension from the contentId
84+
const fileExtIndex = contentId.lastIndexOf(".");
85+
if (fileExtIndex > 0) {
86+
contentId = contentId.substring(0, fileExtIndex);
87+
}
88+
}
6889
const { deviceType, deviceModel } = getDeviceInfo();
6990
analytics.reportMetadata({
7091
live: false,

0 commit comments

Comments
 (0)