This commit is contained in:
Fredrik Burmester
2025-02-16 16:01:49 +01:00
parent 696543d1b2
commit 1a2e044da6
31 changed files with 639 additions and 3062 deletions

View File

@@ -0,0 +1,44 @@
import { XMLParser } from "fast-xml-parser";
export interface Boot {
Version: string;
HLSMoviePackageType: string;
Streams: {
Stream: Stream[];
};
MasterPlaylist: {
NetworkURL: string;
};
DataItems: {
Directory: string;
DataItem: DataItem;
};
}
export interface Stream {
ID: string;
NetworkURL: string;
Path: string;
Complete: string; // "YES" or "NO"
}
export interface DataItem {
ID: string;
Category: string;
Name: string;
DescriptorPath: string;
DataPath: string;
Role: string;
}
export async function parseBootXML(xml: string): Promise<Boot> {
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "",
parseAttributeValue: true,
});
const jsonObj = parser.parse(xml);
const b = jsonObj.HLSMoviePackage as Boot;
console.log(b.Streams);
return jsonObj.HLSMoviePackage as Boot;
}

View File

@@ -0,0 +1,45 @@
import { XMLParser } from "fast-xml-parser";
export interface StreamInfo {
Version: string;
Complete: string;
PeakBandwidth: number;
Compressable: string;
MediaPlaylist: MediaPlaylist;
Type: string;
MediaSegments: {
SEG: SEG[];
};
EvictionPolicy: string;
MediaBytesStored: number;
}
export interface MediaPlaylist {
NetworkURL: string;
PathToLocalCopy: string;
}
export interface SEG {
Dur: number;
Len: number;
Off: number;
PATH: string;
SeqNum: number;
Tim: number;
URL: string;
}
export async function parseStreamInfoXml(xml: string): Promise<StreamInfo> {
const parser = new XMLParser({
ignoreAttributes: false,
attributeNamePrefix: "",
parseAttributeValue: true,
isArray: (tagName, jPath) => {
// Force SEG elements to always be an array
if (jPath === "StreamInfo.MediaSegments.SEG") return true;
return false;
},
});
const jsonObj = parser.parse(xml);
return jsonObj.StreamInfo as StreamInfo;
}