^^
This commit is contained in:
parent
8d103c0c48
commit
cba9ccd288
6 changed files with 30 additions and 37 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1,3 +1,4 @@
|
|||
node_modules
|
||||
dist
|
||||
build
|
||||
package-lock.json
|
|
@ -1,6 +1,7 @@
|
|||
# lollipop 🍭
|
||||
|
||||
A friendly and lovely cli youtube downloader written in typescript for Linux, MacOS, Windows.
|
||||
<br>
|
||||
|
||||

|
||||
|
||||
## Features
|
||||
|
@ -23,7 +24,7 @@ A friendly and lovely cli youtube downloader written in typescript for Linux, Ma
|
|||
```
|
||||
Windows
|
||||
```ps
|
||||
./lollipop.exe
|
||||
lollipop.exe
|
||||
```
|
||||
Lollipop has a built-in guide. Type these commands to find out what the commands and them flags do:
|
||||
<br>
|
||||
|
@ -34,8 +35,8 @@ A friendly and lovely cli youtube downloader written in typescript for Linux, Ma
|
|||
```
|
||||
Windows
|
||||
```ps
|
||||
./lollipop.exe help get
|
||||
./lollipop.exe help down
|
||||
lollipop.exe help get
|
||||
lollipop.exe help down
|
||||
```
|
||||
## How to use (example)
|
||||
Lollipop uses tags to download from YouTube. You have to provide it your desired video tag and audio tag, for example, the command below:
|
||||
|
|
14
package.json
14
package.json
|
@ -27,11 +27,11 @@
|
|||
"dev": "nodemon src/app.ts",
|
||||
"build": "tsc",
|
||||
"build-w": "tsc -w",
|
||||
"make-linux-x64": "npm run build && pkg --targets node20-linux-x64 --compress GZip dist/app.js -o lollipop-linux-x64",
|
||||
"make-linux-arm64": "npm run build && pkg --targets node20-linux-arm64 --compress GZip dist/app.js -o lollipop-linux-arm64",
|
||||
"make-win-x64": "npm run build && pkg --targets node20-win-x64 --compress GZip dist/app.js -o lollipop-win-x64",
|
||||
"make-win-arm64": "npm run build && pkg --targets node20-win-arm64 --compress GZip dist/app.js -o lollipop-win-arm64",
|
||||
"make-macos-x64": "npm run build && pkg --targets node20-macos-x64 --compress GZip dist/app.js -o lollipop-macos-x64",
|
||||
"make-macos-arm64": "npm run build && pkg --targets node20-macos-arm64 --compress GZip dist/app.js -o lollipop-macos-arm64"
|
||||
"make-linux-x64": "npm run build && pkg --targets node20-linux-x64 --compress GZip dist/app.js -o build/lollipop-linux-x64",
|
||||
"make-linux-arm64": "npm run build && pkg --targets node20-linux-arm64 --compress GZip dist/app.js -o build/lollipop-linux-arm64",
|
||||
"make-win-x64": "npm run build && pkg --targets node20-win-x64 --compress GZip dist/app.js -o build/lollipop-win-x64",
|
||||
"make-win-arm64": "npm run build && pkg --targets node20-win-arm64 --compress GZip dist/app.js -o build/lollipop-win-arm64",
|
||||
"make-macos-x64": "npm run build && pkg --targets node20-macos-x64 --compress GZip dist/app.js -o build/lollipop-macos-x64",
|
||||
"make-macos-arm64": "npm run build && pkg --targets node20-macos-arm64 --compress GZip dist/app.js -o build/lollipop-macos-arm64"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -11,7 +11,7 @@ import {
|
|||
drawBasicTable,
|
||||
} from "./tables";
|
||||
import { Successful, Wrong } from "./logs";
|
||||
import { secondstoTime, kbToSize } from "../utils/ulits";
|
||||
import { secondstoTime, formatBytes } from "../utils/ulits";
|
||||
import { IVideoObject, IAudioObject } from "./interface";
|
||||
|
||||
export const debug = {
|
||||
|
@ -71,7 +71,7 @@ export async function downloadVideo(link: string, tag: string) {
|
|||
readline.clearLine(process.stdout, 0);
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Downloading video: ${kbToSize(downloaded)} / ${kbToSize(total)}`
|
||||
`Downloading video: ${formatBytes(downloaded)} / ${formatBytes(total)}`
|
||||
);
|
||||
})
|
||||
.on("finish", () => {
|
||||
|
@ -134,7 +134,7 @@ export async function downloadAudio(link: string, tag: string) {
|
|||
readline.clearLine(process.stdout, 0);
|
||||
readline.cursorTo(process.stdout, 0);
|
||||
process.stdout.write(
|
||||
`Downloaging audio: ${kbToSize(downloaded)} / ${kbToSize(total)}`
|
||||
`Downloaging audio: ${formatBytes(downloaded)} / ${formatBytes(total)}`
|
||||
);
|
||||
})
|
||||
.on("finish", () => {
|
||||
|
|
|
@ -3,7 +3,7 @@ import table from "easy-table";
|
|||
import chalk from "chalk";
|
||||
import moment from "moment";
|
||||
|
||||
import { secondstoTime, kbToSize } from "../utils/ulits";
|
||||
import { secondstoTime, formatBytes } from "../utils/ulits";
|
||||
|
||||
export function drawBasicTable(info: videoInfo) {
|
||||
const title = `${chalk.bold.inverse(" Title ")} ==> ${
|
||||
|
@ -31,7 +31,7 @@ export function drawVideoQualityTable(formats: videoFormat[]) {
|
|||
t.cell(chalk.magenta("Quality"), chalk.magenta(i.qualityLabel));
|
||||
t.cell(chalk.blue("Format"), chalk.blue(i.container));
|
||||
t.cell(chalk.green("Codec"), chalk.green(i.videoCodec));
|
||||
t.cell(chalk.yellow("Size"), chalk.yellow(kbToSize(+i.contentLength)));
|
||||
t.cell(chalk.yellow("Size"), chalk.yellow(formatBytes(+i.contentLength)));
|
||||
t.sort([`${chalk.blue("Format")}|des`]);
|
||||
t.newRow();
|
||||
}
|
||||
|
@ -47,7 +47,7 @@ export async function drawAudioQualityTable(formats: videoFormat[]) {
|
|||
t.cell(chalk.cyan("Tag"), chalk.cyan(i.itag));
|
||||
t.cell(chalk.magenta("Bitrate"), chalk.magenta(i.audioBitrate));
|
||||
t.cell(chalk.green("Codec"), chalk.green(i.audioCodec));
|
||||
t.cell(chalk.yellow("Size"), chalk.yellow(kbToSize(+i.contentLength)));
|
||||
t.cell(chalk.yellow("Size"), chalk.yellow(formatBytes(+i.contentLength)));
|
||||
t.sort([`${chalk.magenta("Bitrate")}|des`]);
|
||||
t.newRow();
|
||||
}
|
||||
|
|
|
@ -13,24 +13,15 @@ export function secondstoTime(s: number) {
|
|||
return time;
|
||||
}
|
||||
|
||||
export function kbToSize(kilobit: number) {
|
||||
if (Number.isNaN(kilobit)) {
|
||||
return "Incalculable";
|
||||
}
|
||||
const megabytes = kilobit / 1024 / 1024;
|
||||
if (megabytes >= 1024) {
|
||||
const gigabyte = megabytes / 1024;
|
||||
return gigabyte.toFixed(2) + "GB";
|
||||
}
|
||||
return megabytes.toFixed(2) + "MB";
|
||||
}
|
||||
export function formatBytes(bytes: number, decimals: number = 2) {
|
||||
if (Number.isNaN(bytes)) return "Incalculable";
|
||||
if (!+bytes) return "0 B";
|
||||
|
||||
//? It's for future :)
|
||||
// export function toSize(kilobyte: number) {
|
||||
// const megabytes = kilobyte / 1024;
|
||||
// if (megabytes >= 1024) {
|
||||
// const gigabyte = megabytes / 1024;
|
||||
// return gigabyte.toFixed(2) + "GB";
|
||||
// }
|
||||
// return megabytes.toFixed(2) + "MB";
|
||||
// }
|
||||
let i = 0;
|
||||
for (i; bytes >= 1024; i++) bytes /= 1024;
|
||||
|
||||
const dm = bytes % 1 === 0 ? 0 : decimals;
|
||||
const units = ["B", "KB", "MB", "GB", "TB", "PB"];
|
||||
|
||||
return `${bytes.toFixed(dm)} ${units[i]}`;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue