Merge branch 'codec-filter-fix' into 'master'
codec support check See merge request domi/bashtube!418l-fix
commit
783f9e0970
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue