mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-24 12:08:55 +01:00
api/youtube: disable hls if user prefers av1
This commit is contained in:
parent
b6e827c6f9
commit
8b972c7a85
1 changed files with 13 additions and 11 deletions
|
@ -132,9 +132,16 @@ export default async function(o) {
|
||||||
} else throw e;
|
} else throw e;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let useHLS = o.youtubeHLS;
|
||||||
|
|
||||||
|
// HLS playlists don't contain the av1 video format, at least with the iOS client
|
||||||
|
if (useHLS && o.format === "av1") {
|
||||||
|
useHLS = false;
|
||||||
|
}
|
||||||
|
|
||||||
let info;
|
let info;
|
||||||
try {
|
try {
|
||||||
info = await yt.getBasicInfo(o.id, o.youtubeHLS ? 'IOS' : 'ANDROID');
|
info = await yt.getBasicInfo(o.id, useHLS ? 'IOS' : 'ANDROID');
|
||||||
} catch(e) {
|
} catch(e) {
|
||||||
if (e?.info?.reason === "This video is private") {
|
if (e?.info?.reason === "This video is private") {
|
||||||
return { error: "content.video.private" };
|
return { error: "content.video.private" };
|
||||||
|
@ -210,7 +217,7 @@ export default async function(o) {
|
||||||
let video, audio, dubbedLanguage,
|
let video, audio, dubbedLanguage,
|
||||||
format = o.format || "h264";
|
format = o.format || "h264";
|
||||||
|
|
||||||
if (o.youtubeHLS) {
|
if (useHLS) {
|
||||||
const hlsManifest = info.streaming_data.hls_manifest_url;
|
const hlsManifest = info.streaming_data.hls_manifest_url;
|
||||||
|
|
||||||
if (!hlsManifest) {
|
if (!hlsManifest) {
|
||||||
|
@ -239,11 +246,6 @@ export default async function(o) {
|
||||||
return { error: "youtube.no_hls_streams" };
|
return { error: "youtube.no_hls_streams" };
|
||||||
}
|
}
|
||||||
|
|
||||||
// HLS playlists don't contain AV1 format, at least with the iOS client
|
|
||||||
if (format === "av1") {
|
|
||||||
format = "vp9";
|
|
||||||
}
|
|
||||||
|
|
||||||
const matchHlsCodec = codecs => (
|
const matchHlsCodec = codecs => (
|
||||||
codecs.includes(hlsCodecList[format].videoCodec)
|
codecs.includes(hlsCodecList[format].videoCodec)
|
||||||
);
|
);
|
||||||
|
@ -388,7 +390,7 @@ export default async function(o) {
|
||||||
let bestAudio = format === "h264" ? "m4a" : "opus";
|
let bestAudio = format === "h264" ? "m4a" : "opus";
|
||||||
let urls = audio.url;
|
let urls = audio.url;
|
||||||
|
|
||||||
if (o.youtubeHLS) {
|
if (useHLS) {
|
||||||
bestAudio = "mp3";
|
bestAudio = "mp3";
|
||||||
urls = audio.uri;
|
urls = audio.uri;
|
||||||
}
|
}
|
||||||
|
@ -400,14 +402,14 @@ export default async function(o) {
|
||||||
filenameAttributes,
|
filenameAttributes,
|
||||||
fileMetadata,
|
fileMetadata,
|
||||||
bestAudio,
|
bestAudio,
|
||||||
isHLS: o.youtubeHLS,
|
isHLS: useHLS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (video && audio) {
|
if (video && audio) {
|
||||||
let resolution;
|
let resolution;
|
||||||
|
|
||||||
if (o.youtubeHLS) {
|
if (useHLS) {
|
||||||
resolution = normalizeQuality(video.resolution);
|
resolution = normalizeQuality(video.resolution);
|
||||||
filenameAttributes.resolution = `${video.resolution.width}x${video.resolution.height}`;
|
filenameAttributes.resolution = `${video.resolution.width}x${video.resolution.height}`;
|
||||||
filenameAttributes.extension = hlsCodecList[format].container;
|
filenameAttributes.extension = hlsCodecList[format].container;
|
||||||
|
@ -437,7 +439,7 @@ export default async function(o) {
|
||||||
],
|
],
|
||||||
filenameAttributes,
|
filenameAttributes,
|
||||||
fileMetadata,
|
fileMetadata,
|
||||||
isHLS: o.youtubeHLS,
|
isHLS: useHLS,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue