mirror of
https://github.com/wukko/cobalt.git
synced 2024-11-17 22:00:00 +00:00
clean up
This commit is contained in:
parent
2ca4d67e29
commit
05bb7bcd07
1 changed files with 0 additions and 49 deletions
|
@ -149,52 +149,3 @@ export function cleanHTML(html) {
|
|||
clean = clean.replace(/\n/g, '');
|
||||
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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue