Skip to content

Commit

Permalink
api/youtube: disable hls if user prefers av1
Browse files Browse the repository at this point in the history
  • Loading branch information
wukko committed Nov 13, 2024
1 parent b6e827c commit 8b972c7
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions api/src/processing/services/youtube.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,16 @@ export default async function(o) {
} 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;
try {
info = await yt.getBasicInfo(o.id, o.youtubeHLS ? 'IOS' : 'ANDROID');
info = await yt.getBasicInfo(o.id, useHLS ? 'IOS' : 'ANDROID');
} catch(e) {
if (e?.info?.reason === "This video is private") {
return { error: "content.video.private" };
Expand Down Expand Up @@ -210,7 +217,7 @@ export default async function(o) {
let video, audio, dubbedLanguage,
format = o.format || "h264";

if (o.youtubeHLS) {
if (useHLS) {
const hlsManifest = info.streaming_data.hls_manifest_url;

if (!hlsManifest) {
Expand Down Expand Up @@ -239,11 +246,6 @@ export default async function(o) {
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 => (
codecs.includes(hlsCodecList[format].videoCodec)
);
Expand Down Expand Up @@ -388,7 +390,7 @@ export default async function(o) {
let bestAudio = format === "h264" ? "m4a" : "opus";
let urls = audio.url;

if (o.youtubeHLS) {
if (useHLS) {
bestAudio = "mp3";
urls = audio.uri;
}
Expand All @@ -400,14 +402,14 @@ export default async function(o) {
filenameAttributes,
fileMetadata,
bestAudio,
isHLS: o.youtubeHLS,
isHLS: useHLS,
}
}

if (video && audio) {
let resolution;

if (o.youtubeHLS) {
if (useHLS) {
resolution = normalizeQuality(video.resolution);
filenameAttributes.resolution = `${video.resolution.width}x${video.resolution.height}`;
filenameAttributes.extension = hlsCodecList[format].container;
Expand Down Expand Up @@ -437,7 +439,7 @@ export default async function(o) {
],
filenameAttributes,
fileMetadata,
isHLS: o.youtubeHLS,
isHLS: useHLS,
}
}

Expand Down

0 comments on commit 8b972c7

Please sign in to comment.