This commit is contained in:
wukko 2023-09-16 18:20:29 +06:00 committed by GitHub
parent 2ca4d67e29
commit 05bb7bcd07
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -149,52 +149,3 @@ export function cleanHTML(html) {
clean = clean.replace(/\n/g, ''); clean = clean.replace(/\n/g, '');
return clean return clean
} }
export function parseM3U8Line(line) {
let result = {};
let str = '', inQuotes = false, keyName = null, escaping = false;
for (let i = 0; i < line.length; i++) {
const char = line[i];
if (char === '"' && !escaping) {
inQuotes = !inQuotes;
continue
} else if (char === ',' && !escaping && !inQuotes) {
if (!keyName) break;
result[keyName] = str;
keyName = null;
str = '';
continue
} else if (char === '\\' && !escaping) {
escaping = true;
continue
} else if (char === '=' && !escaping && !inQuotes) {
keyName = str;
str = '';
continue
}
str += char;
escaping = false
}
if (keyName) result[keyName] = str;
return result
}
export function getM3U8Formats(m3u8body) {
const formatLines = m3u8body.split('\n').slice(2);
let formats = [];
for (let i = 0; i < formatLines.length; i += 3) {
const mediaLine = parseM3U8Line(formatLines[i].split(':')[1]);
const streamLine = parseM3U8Line(formatLines[i + 1].split(':')[1]);
formats.push({
id: mediaLine['GROUP-ID'],
name: mediaLine.NAME,
resolution: streamLine.RESOLUTION ? streamLine.RESOLUTION.split('x') : null,
url: formatLines[i + 2]
})
}
return formats
}