remove //
This commit is contained in:
parent
14f4753b27
commit
13d3607a54
@ -183,10 +183,10 @@ class DownloadVideo {
|
|||||||
title: info.title,
|
title: info.title,
|
||||||
description: info.description,
|
description: info.description,
|
||||||
uploader: info.uploader,
|
uploader: info.uploader,
|
||||||
duration: info.duration, // секунды
|
duration: info.duration,
|
||||||
thumbnail:
|
thumbnail:
|
||||||
info.thumbnails?.[info.thumbnails.length - 1]?.url ||
|
info.thumbnails?.[info.thumbnails.length - 1]?.url ||
|
||||||
info.thumbnail, // лучшее превью
|
info.thumbnail,
|
||||||
url: info.webpage_url,
|
url: info.webpage_url,
|
||||||
thumbnails: info.thumbnails
|
thumbnails: info.thumbnails
|
||||||
});
|
});
|
||||||
@ -239,33 +239,19 @@ class DownloadVideo {
|
|||||||
const formats = await this.getFormats();
|
const formats = await this.getFormats();
|
||||||
const q = {};
|
const q = {};
|
||||||
|
|
||||||
// Перебираем форматы и группируем по расширению
|
|
||||||
formats.forEach(f => {
|
formats.forEach(f => {
|
||||||
if (!f.ext || !f.format_id) return;
|
if (!f.ext || !f.format_id) return;
|
||||||
//if (!q[f.ext]) q[f.ext] = [];
|
|
||||||
|
|
||||||
const resolution = f.height ? `${f.height}p` : 'audio-only';
|
const resolution = f.height ? `${f.height}p` : 'audio-only';
|
||||||
|
|
||||||
let flag = `bestaudio[ext=${f.ext}]`;
|
let flag = `bestaudio[ext=${f.ext}]`;
|
||||||
if (f.height) {
|
if (f.height) {
|
||||||
//flag = `best[height<=${f.height}][ext=${f.ext}]`;
|
|
||||||
flag = [
|
flag = [
|
||||||
`best[height<=${
|
`best[height<=${
|
||||||
f.height
|
f.height
|
||||||
}]`,
|
}]`,
|
||||||
/*`bestvideo[height<=${
|
|
||||||
f.height
|
|
||||||
}]+bestaudio[ext=m4a]/best`,*/
|
|
||||||
/*`bestvideo[height<=${
|
|
||||||
f.height
|
|
||||||
}][vcodec^=avc1]+bestaudio[ext=m4a]/best[ext=${f.ext}]`,*/
|
|
||||||
/*`bestvideo[height<=${
|
|
||||||
f.height
|
|
||||||
}][vcodec^=mov]+bestaudio[ext=m4a]/best`,*/
|
|
||||||
"--merge-output-format", f.ext
|
"--merge-output-format", f.ext
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
//const flag = f.format_id;
|
|
||||||
|
|
||||||
const mimeType = mime.getType(f.ext);
|
const mimeType = mime.getType(f.ext);
|
||||||
const type = (resolution === "audio-only" || /^audio\//m.test(mimeType)) ? "audio" : (
|
const type = (resolution === "audio-only" || /^audio\//m.test(mimeType)) ? "audio" : (
|
||||||
@ -324,22 +310,17 @@ class DownloadVideo {
|
|||||||
const params = [
|
const params = [
|
||||||
"--cookies", "cookies.txt",
|
"--cookies", "cookies.txt",
|
||||||
"--user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
"--user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)",
|
||||||
//"--extractor-args", "youtube:player-client=default,mweb;po_token=mweb.gvs+XXX",
|
|
||||||
"--extractor-args", "youtube:player_client=default,mweb",
|
"--extractor-args", "youtube:player_client=default,mweb",
|
||||||
"-f", ...flags,
|
"-f", ...flags,
|
||||||
"-o", !isPath ? "-" : isStream, this.url,
|
"-o", !isPath ? "-" : isStream, this.url,
|
||||||
];
|
];
|
||||||
d("yt-dlp " + params.join(" "));
|
d("yt-dlp " + params.join(" "));
|
||||||
//console.debug({ HOME: process.env.HOME });
|
|
||||||
const child = spawn("yt-dlp", params, {
|
const child = spawn("yt-dlp", params, {
|
||||||
env: {
|
env: {
|
||||||
...process.env,
|
...process.env,
|
||||||
//HOME: process.env.HOME,
|
|
||||||
LANG: "en_US.UTF-8",
|
LANG: "en_US.UTF-8",
|
||||||
},
|
},
|
||||||
stdio: ["pipe","pipe","pipe"],
|
stdio: ["pipe","pipe","pipe"],
|
||||||
//stdio: ["pipe","inherit","pipe"],
|
|
||||||
//stdio: ["inherit", "inherit", "inherit"],
|
|
||||||
});
|
});
|
||||||
let downloaded = 0;
|
let downloaded = 0;
|
||||||
let percent = 0;
|
let percent = 0;
|
||||||
@ -349,8 +330,6 @@ class DownloadVideo {
|
|||||||
|
|
||||||
const stderrHandler = (data) => {
|
const stderrHandler = (data) => {
|
||||||
const str = data.toString();
|
const str = data.toString();
|
||||||
//console.debug("DEBUG >>>>>>", str);
|
|
||||||
//console.debug(str);
|
|
||||||
const match = str.match(/(\d+\.\d+)%/);
|
const match = str.match(/(\d+\.\d+)%/);
|
||||||
if (match && cb) {
|
if (match && cb) {
|
||||||
percent = parseFloat(match[1]);
|
percent = parseFloat(match[1]);
|
||||||
@ -364,7 +343,6 @@ class DownloadVideo {
|
|||||||
child.stdout.on("data", stderrHandler);
|
child.stdout.on("data", stderrHandler);
|
||||||
|
|
||||||
child.on("close", async (code) => {
|
child.on("close", async (code) => {
|
||||||
//console.debug(">>>>>>>>>>>>>FINISHED");
|
|
||||||
signal.emit("finish");
|
signal.emit("finish");
|
||||||
fine = true;
|
fine = true;
|
||||||
if (code !== 0) {
|
if (code !== 0) {
|
||||||
@ -377,10 +355,8 @@ class DownloadVideo {
|
|||||||
return resolve(isStream);
|
return resolve(isStream);
|
||||||
const ffmpeg = new FFMPEG(isStream);
|
const ffmpeg = new FFMPEG(isStream);
|
||||||
const fileConverted = isStream +
|
const fileConverted = isStream +
|
||||||
//".converted." +
|
|
||||||
".mp3";
|
".mp3";
|
||||||
const videoInfo = await this.getVideoInfo();
|
const videoInfo = await this.getVideoInfo();
|
||||||
//console.debug("videoInfo::thumbnails", videoInfo.thumbnails);
|
|
||||||
return ffmpeg.convertMusic(FFMPEG.fromFile(
|
return ffmpeg.convertMusic(FFMPEG.fromFile(
|
||||||
isStream, fileConverted, videoInfo.thumbnail
|
isStream, fileConverted, videoInfo.thumbnail
|
||||||
)).then(readyFile => {
|
)).then(readyFile => {
|
||||||
@ -415,11 +391,8 @@ class DownloadVideo {
|
|||||||
});
|
});
|
||||||
|
|
||||||
child.on("error", reject);
|
child.on("error", reject);
|
||||||
//return resolve(stream);
|
|
||||||
//console.debug(this.quality);
|
|
||||||
const resultedStream = this.quality.type === "video" ?
|
const resultedStream = this.quality.type === "video" ?
|
||||||
(await ffmpeg.convert()) : stream;
|
(await ffmpeg.convert()) : stream;
|
||||||
//const resultedStream = stream;
|
|
||||||
|
|
||||||
resultedStream.on("data", chunk => {
|
resultedStream.on("data", chunk => {
|
||||||
sizeTg += chunk.length;
|
sizeTg += chunk.length;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user