codec support check
This commit is contained in:
parent
6b43d9ef5f
commit
47b660671a
|
@ -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)
|
const formats = JSON.parse(document.getElementById('yt_formats').innerText)
|
||||||
.filter((fmt) => ['http', 'https'].includes(fmt.protocol))
|
.filter((fmt) => isFormatSupported(fmt) === true)
|
||||||
.sort((a, b) => {
|
.sort((a, b) => {
|
||||||
if (a.vcodec === 'none' && b.vcodec !== 'none') {
|
if (a.vcodec === 'none' && b.vcodec !== 'none') {
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue