Skip to content

Commit

Permalink
Add auto download highest quality
Browse files Browse the repository at this point in the history
Lollipop is lovely, so it should be friendlier
  • Loading branch information
sudospaes committed Jun 15, 2024
1 parent 4971552 commit b0db915
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 16 deletions.
12 changes: 11 additions & 1 deletion src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ app
"#D04848"
)("<3")}`
)
.version(`0.0.1`, "--version")
.version(`0.0.3`, "--version")
.usage("[command]")
.option("--debug", "simple debugger, it's a joke XD")
.addOption(new Option("-h, --help").hideHelp());
Expand Down Expand Up @@ -63,6 +63,9 @@ app
)} youtube_link -v tag_number -a tag_number
${chalk.hex("#DC84F3")(
`In standard download, I download video and audio separately and merging them with ffmpeg`
)}
${chalk.hex("#DC84F3")(
`If you don't provide video tag and audio tag, I'll download highest qualities of them`
)}\n
download only video => ${chalk.yellow("down")} youtube_link -v tag_number\n
download only audio => ${chalk.yellow(
Expand Down Expand Up @@ -118,6 +121,13 @@ app
} else {
Wrong.audioTagNotFound();
}
} else {
const video = await downloadVideo(link, "highest");
const audio = await downloadAudio(link, "highest");
if (options.mp3) {
audio.path = await conevrtToMp3(audio);
}
merging(video, audio);
}
});

Expand Down
51 changes: 36 additions & 15 deletions src/cli/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,23 @@ export async function downloadVideo(link: string, tag: string) {
let quality = "";
let codec = "";
console.log("I am detecting video...");
info.formats.forEach((item) => {
if (item.itag == +tag) {
extension = item.container;
quality = item.qualityLabel;
codec = item.codecs;
}
});
if (tag == "highest") {
const highest = ytdl.chooseFormat(info.formats, {
quality: "highestvideo",
});
extension = highest.container;
quality = highest.qualityLabel;
codec = highest.codecs;
tag = highest.itag.toString();
} else {
info.formats.forEach((item) => {
if (item.itag == +tag) {
extension = item.container;
quality = item.qualityLabel;
codec = item.codecs;
}
});
}
const path = join(
dirname(process.execPath),
`${title}-${quality}-${codec}-video.${extension}`
Expand Down Expand Up @@ -94,14 +104,25 @@ export async function downloadAudio(link: string, tag: string) {
let codec = "";
let channels = 0;
console.log("I am detecting audio...");
info.formats.forEach((item) => {
if (item.itag == +tag) {
extension = item.container;
bitrate = item.audioBitrate!;
codec = item.codecs;
channels = item.audioChannels!;
}
});
if (tag == "highest") {
const highest = ytdl.chooseFormat(info.formats, {
quality: "highestaudio",
});
extension = highest.container;
bitrate = highest.audioBitrate!;
codec = highest.codecs;
channels = highest.audioChannels!;
tag = highest.itag.toString();
} else {
info.formats.forEach((item) => {
if (item.itag == +tag) {
extension = item.container;
bitrate = item.audioBitrate!;
codec = item.codecs;
channels = item.audioChannels!;
}
});
}
const path = join(
dirname(process.execPath),
`${title}-${bitrate}-${codec}-audio.${extension}`
Expand Down

0 comments on commit b0db915

Please sign in to comment.