i fucking hate youtube
youtube-related changes: - fixed silly mistake that made all shorts download in default format instead of preferred one - made youtube module return full video (audio + video) if it's available and matches selected quality (usually 720p) - changed the order of streams in video render (now video is first) other changes: - hopefully fixed zoom in on input in safari - moved match module from sub to main modules directory
This commit is contained in:
parent
ec105fb333
commit
9081f790ff
7 changed files with 46 additions and 46 deletions
|
@ -61,7 +61,7 @@ if (fs.existsSync('./.env') && fs.existsSync('./config.json')) {
|
||||||
req.query.url.trim(),
|
req.query.url.trim(),
|
||||||
req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip,
|
req.header('x-forwarded-for') ? req.header('x-forwarded-for') : req.ip,
|
||||||
req.header('Accept-Language') ? req.header('Accept-Language').slice(0, 2) : "en",
|
req.header('Accept-Language') ? req.header('Accept-Language').slice(0, 2) : "en",
|
||||||
req.query.format ? req.query.format.slice(0, 5) : "webm",
|
req.query.format ? req.query.format.slice(0, 5) : "mp4",
|
||||||
req.query.quality ? req.query.quality.slice(0, 3) : "max"
|
req.query.quality ? req.query.quality.slice(0, 3) : "max"
|
||||||
)
|
)
|
||||||
res.status(j.status).json(j.body);
|
res.status(j.status).json(j.body);
|
||||||
|
|
|
@ -147,7 +147,7 @@ async function download(url) {
|
||||||
changeDownloadButton(2, '...');
|
changeDownloadButton(2, '...');
|
||||||
eid("url-input-area").disabled = true;
|
eid("url-input-area").disabled = true;
|
||||||
let format = '';
|
let format = '';
|
||||||
if (url.includes(".youtube.com/") || url.includes("/youtu.be/")) {
|
if (url.includes("youtube.com/") || url.includes("/youtu.be/")) {
|
||||||
format = `&format=${localStorage.getItem("youtubeFormat")}`
|
format = `&format=${localStorage.getItem("youtubeFormat")}`
|
||||||
}
|
}
|
||||||
fetch(`/api/json?quality=${localStorage.getItem("quality")}${format}&url=${encodeURIComponent(url)}`).then(async (response) => {
|
fetch(`/api/json?quality=${localStorage.getItem("quality")}${format}&url=${encodeURIComponent(url)}`).then(async (response) => {
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { services as patterns } from "./config.js";
|
||||||
import { cleanURL, apiJSON } from "./sub/api-helper.js";
|
import { cleanURL, apiJSON } from "./sub/api-helper.js";
|
||||||
import { errorUnsupported } from "./sub/errors.js";
|
import { errorUnsupported } from "./sub/errors.js";
|
||||||
import loc from "./sub/loc.js";
|
import loc from "./sub/loc.js";
|
||||||
import match from "./sub/match.js";
|
import match from "./match.js";
|
||||||
|
|
||||||
export async function getJSON(originalURL, ip, lang, format, quality) {
|
export async function getJSON(originalURL, ip, lang, format, quality) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
import { apiJSON } from "./api-helper.js";
|
import { apiJSON } from "./sub/api-helper.js";
|
||||||
import { errorUnsupported, genericError } from "./errors.js";
|
import { errorUnsupported, genericError } from "./sub/errors.js";
|
||||||
|
|
||||||
import bilibili from "../services/bilibili.js";
|
import bilibili from "./services/bilibili.js";
|
||||||
import reddit from "../services/reddit.js";
|
import reddit from "./services/reddit.js";
|
||||||
import twitter from "../services/twitter.js";
|
import twitter from "./services/twitter.js";
|
||||||
import youtube from "../services/youtube.js";
|
import youtube from "./services/youtube.js";
|
||||||
import vk from "../services/vk.js";
|
import vk from "./services/vk.js";
|
||||||
|
|
||||||
export default async function (host, patternMatch, url, ip, lang, format, quality) {
|
export default async function (host, patternMatch, url, ip, lang, format, quality) {
|
||||||
try {
|
try {
|
||||||
|
@ -47,6 +47,9 @@ export default async function (host, patternMatch, url, ip, lang, format, qualit
|
||||||
lang: lang, quality: quality,
|
lang: lang, quality: quality,
|
||||||
format: "mp4"
|
format: "mp4"
|
||||||
};
|
};
|
||||||
|
if (url.match('music.youtube.com')) {
|
||||||
|
format = "audio"
|
||||||
|
}
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case "webm":
|
case "webm":
|
||||||
fetchInfo["format"] = "webm";
|
fetchInfo["format"] = "webm";
|
||||||
|
@ -57,9 +60,6 @@ export default async function (host, patternMatch, url, ip, lang, format, qualit
|
||||||
fetchInfo["quality"] = "max";
|
fetchInfo["quality"] = "max";
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (url.match('music.youtube.com')) {
|
|
||||||
fetchInfo["isAudioOnly"] = true;
|
|
||||||
}
|
|
||||||
let r = await youtube(fetchInfo);
|
let r = await youtube(fetchInfo);
|
||||||
return (!r.error) ? apiJSON(2, {
|
return (!r.error) ? apiJSON(2, {
|
||||||
type: r.type, urls: r.urls, service: host, ip: ip,
|
type: r.type, urls: r.urls, service: host, ip: ip,
|
|
@ -24,7 +24,7 @@ export default function(obj) {
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=5" />
|
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=${isIOS ? `1` : `5`}" />
|
||||||
|
|
||||||
<title>${appName}</title>
|
<title>${appName}</title>
|
||||||
|
|
||||||
|
|
|
@ -9,50 +9,50 @@ export default async function (obj) {
|
||||||
if (info) {
|
if (info) {
|
||||||
info = info.formats;
|
info = info.formats;
|
||||||
if (!info[0]["isLive"]) {
|
if (!info[0]["isLive"]) {
|
||||||
if (obj.isAudioOnly) {
|
let videoMatch = [], fullVideoMatch = [], video = [], audio = info.filter((a) => {
|
||||||
obj.format = "webm"
|
if (!a["isHLS"] && !a["isDashMPD"] && a["hasAudio"] && !a["hasVideo"] && a["container"] == obj.format) return true;
|
||||||
obj.quality = "max"
|
|
||||||
}
|
|
||||||
let selectedVideo, videoMatch = [], video = [], audio = info.filter((a) => {
|
|
||||||
if (!a["isLive"] && !a["isHLS"] && !a["isDashMPD"] && a["hasAudio"] && !a["hasVideo"] && a["container"] == obj.format) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}).sort((a, b) => Number(b.bitrate) - Number(a.bitrate));
|
}).sort((a, b) => Number(b.bitrate) - Number(a.bitrate));
|
||||||
if (!obj.isAudioOnly) {
|
if (!obj.isAudioOnly) {
|
||||||
video = info.filter((a) => {
|
video = info.filter((a) => {
|
||||||
if (!a["isLive"] && !a["isHLS"] && !a["isDashMPD"] && !a["hasAudio"] && a["hasVideo"] && a["container"] == obj.format && a["height"] != 4320) {
|
if (!a["isHLS"] && !a["isDashMPD"] && a["hasVideo"] && a["container"] == obj.format && a["height"] != 4320) {
|
||||||
if (obj.quality != "max" && mq[obj.quality] == a["height"]) {
|
|
||||||
videoMatch.push(a)
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}).sort((a, b) => Number(b.bitrate) - Number(a.bitrate));
|
|
||||||
selectedVideo = video[0]
|
|
||||||
if (obj.quality != "max") {
|
if (obj.quality != "max") {
|
||||||
if (videoMatch.length > 0) {
|
if (a["hasAudio"] && mq[obj.quality] == a["height"]) {
|
||||||
selectedVideo = videoMatch[0]
|
fullVideoMatch.push(a)
|
||||||
} else {
|
} else if (!a["hasAudio"] && mq[obj.quality] == a["height"]) {
|
||||||
let ss = selectQuality("youtube", obj.quality, video[0]["height"])
|
videoMatch.push(a);
|
||||||
selectedVideo = video.filter((a) => {
|
}
|
||||||
if (a["height"] == ss) {
|
}
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
}).sort((a, b) => Number(b.bitrate) - Number(a.bitrate));
|
||||||
|
if (obj.quality != "max") {
|
||||||
|
if (videoMatch.length == 0) {
|
||||||
|
let ss = selectQuality("youtube", obj.quality, video[0]["height"])
|
||||||
|
videoMatch = video.filter((a) => {
|
||||||
|
if (a["height"] == ss) return true;
|
||||||
})
|
})
|
||||||
selectedVideo = selectedVideo[0]
|
} else if (fullVideoMatch.length > 0) {
|
||||||
}
|
videoMatch = [fullVideoMatch[0]]
|
||||||
}
|
|
||||||
if (obj.quality == "los") {
|
|
||||||
selectedVideo = video[video.length - 1]
|
|
||||||
}
|
}
|
||||||
|
} else videoMatch = [video[0]];
|
||||||
|
if (obj.quality == "los") videoMatch = [video[video.length - 1]];
|
||||||
}
|
}
|
||||||
if (audio[0]["approxDurationMs"] <= maxVideoDuration) {
|
if (audio[0]["approxDurationMs"] <= maxVideoDuration) {
|
||||||
if (!obj.isAudioOnly && video.length > 0) {
|
if (!obj.isAudioOnly && videoMatch.length > 0) {
|
||||||
let filename = `youtube_${obj.id}_${selectedVideo["width"]}x${selectedVideo["height"]}.${obj.format}`;
|
|
||||||
if (video.length > 0 && audio.length > 0) {
|
if (video.length > 0 && audio.length > 0) {
|
||||||
return { type: "render", urls: [selectedVideo["url"], audio[0]["url"]], time: video[0]["approxDurationMs"], filename: filename };
|
if (videoMatch[0]["hasVideo"] && videoMatch[0]["hasAudio"]) {
|
||||||
|
return { type: "bridge", urls: videoMatch[0]["url"], time: videoMatch[0]["approxDurationMs"],
|
||||||
|
filename: `youtube_${obj.id}_${videoMatch[0]["width"]}x${videoMatch[0]["height"]}.${obj.format}` };
|
||||||
|
} else {
|
||||||
|
return { type: "render", urls: [videoMatch[0]["url"], audio[0]["url"]], time: videoMatch[0]["approxDurationMs"],
|
||||||
|
filename: `youtube_${obj.id}_${videoMatch[0]["width"]}x${videoMatch[0]["height"]}.${obj.format}` };
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return { error: loc('en', 'apiError', 'youtubeBroke') };
|
return { error: loc('en', 'apiError', 'youtubeBroke') };
|
||||||
}
|
}
|
||||||
|
} else if (!obj.isAudioOnly) {
|
||||||
|
return { type: "render", urls: [video[0]["url"], audio[0]["url"]], time: video[0]["approxDurationMs"],
|
||||||
|
filename: `youtube_${obj.id}_${video[0]["width"]}x${video[0]["height"]}.${video[0]["container"]}` };
|
||||||
} else if (audio.length > 0) {
|
} else if (audio.length > 0) {
|
||||||
return { type: "render", isAudioOnly: true, urls: [audio[0]["url"]], filename: `youtube_${obj.id}_${audio[0]["audioBitrate"]}kbps.opus` };
|
return { type: "render", isAudioOnly: true, urls: [audio[0]["url"]], filename: `youtube_${obj.id}_${audio[0]["audioBitrate"]}kbps.opus` };
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -40,8 +40,8 @@ export async function streamLiveRender(streamInfo, res) {
|
||||||
'-loglevel', '-8',
|
'-loglevel', '-8',
|
||||||
'-i', 'pipe:3',
|
'-i', 'pipe:3',
|
||||||
'-i', 'pipe:4',
|
'-i', 'pipe:4',
|
||||||
'-map', '0:a',
|
'-map', '0:v',
|
||||||
'-map', '1:v',
|
'-map', '1:a',
|
||||||
'-c:v', 'copy',
|
'-c:v', 'copy',
|
||||||
'-c:a', 'copy',
|
'-c:a', 'copy',
|
||||||
];
|
];
|
||||||
|
@ -75,11 +75,11 @@ export async function streamLiveRender(streamInfo, res) {
|
||||||
});
|
});
|
||||||
res.setHeader('Content-Disposition', `attachment; filename="${streamInfo.filename}"`);
|
res.setHeader('Content-Disposition', `attachment; filename="${streamInfo.filename}"`);
|
||||||
ffmpegProcess.stdio[5].pipe(res);
|
ffmpegProcess.stdio[5].pipe(res);
|
||||||
audio.pipe(ffmpegProcess.stdio[3]).on('error', (err) => {
|
video.pipe(ffmpegProcess.stdio[3]).on('error', (err) => {
|
||||||
ffmpegProcess.kill();
|
ffmpegProcess.kill();
|
||||||
internalError(res);
|
internalError(res);
|
||||||
});
|
});
|
||||||
video.pipe(ffmpegProcess.stdio[4]).on('error', (err) => {
|
audio.pipe(ffmpegProcess.stdio[4]).on('error', (err) => {
|
||||||
ffmpegProcess.kill();
|
ffmpegProcess.kill();
|
||||||
internalError(res);
|
internalError(res);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue