codec support check

18l-fix
Lauren Liberda 2021-04-16 00:25:43 +02:00
parent 6b43d9ef5f
commit 47b660671a
1 changed files with 26 additions and 1 deletions

View File

@ -110,8 +110,33 @@ window.addEventListener('DOMContentLoaded', (event) => {
}
}
function getMimeType(fmt) {
const mainType = fmt.vcodec !== 'none' ? 'video' : 'audio';
let secondary = {
m4a: 'mp4',
}[fmt.ext] || fmt.ext;
const codecs = [fmt.vcodec, fmt.acodec].filter(c => c && c !== 'none').join(', ');
return `${mainType}/${secondary}; codecs="${codecs}"`;
}
function isFormatSupported(fmt) {
if (!['http', 'https'].includes(fmt.protocol))
return false;
// must be very old: https://developer.mozilla.org/en-US/docs/Web/API/MediaSource/isTypeSupported#browser_compatibility
if (!('MediaSource' in window)) {
if (['avc1', 'none'].includes(fmt.vcodec.substring(0, 4))
&& ['mp4a', 'none'].includes(fmt.acodec.substring(0, 4))) {
return true;
}
return false;
}
return MediaSource.isTypeSupported(getMimeType(fmt));
}
const formats = JSON.parse(document.getElementById('yt_formats').innerText)
.filter((fmt) => ['http', 'https'].includes(fmt.protocol))
.filter((fmt) => isFormatSupported(fmt) === true)
.sort((a, b) => {
if (a.vcodec === 'none' && b.vcodec !== 'none') {
return -1;