More functionality
This commit is contained in:
parent
8c991fe062
commit
19bf649ff4
15
main.js
15
main.js
@ -9,6 +9,9 @@ const cp = require('child_process');
|
|||||||
const fs = require('fs');
|
const fs = require('fs');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const terminalLink = require('terminal-link');
|
const terminalLink = require('terminal-link');
|
||||||
|
const hasflag = require('has-flag');
|
||||||
|
const gradient = require('gradient-string');
|
||||||
|
const figlet = require('figlet');
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* log function for logging in one shell line.
|
* log function for logging in one shell line.
|
||||||
@ -31,8 +34,8 @@ const convertTime = (timeString) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
if (process.argv.find(v => v === "help" || v === "-h" || v === "--help")) {
|
if (process.argv.find(v => v === "help" || v === "-h" || v === "--help")) {
|
||||||
console.log(chalk.bold("ytdownloader by Jobbel.nl\n"));
|
console.log(gradient.rainbow.multiline(figlet.textSync("ytdownloader", {horizontalLayout: 'fitted'})));
|
||||||
console.log(chalk.underline("Usage:"));
|
console.log(chalk.underline("\nUsage:"));
|
||||||
console.log(`node main.js ${chalk.italic("<YouTube video url> <?Artist name> <?Song name>")}\n`);
|
console.log(`node main.js ${chalk.italic("<YouTube video url> <?Artist name> <?Song name>")}\n`);
|
||||||
console.log("The arguments starting with <? are optional. If not specified the song won't have id3 tags written to it.");
|
console.log("The arguments starting with <? are optional. If not specified the song won't have id3 tags written to it.");
|
||||||
|
|
||||||
@ -40,7 +43,7 @@ if (process.argv.find(v => v === "help" || v === "-h" || v === "--help")) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv.length !== 5) {
|
if (process.argv.length !== 5) {
|
||||||
console.log(chalk.red("⚠️ Not getting metadata for this song; expected arguments are not given!"));
|
console.log(chalk.yellowBright("⚠️ Not getting metadata for this song; expected arguments are not given!"));
|
||||||
}
|
}
|
||||||
|
|
||||||
const ffmpegPath = path.join(__dirname + "/ffmpeg");
|
const ffmpegPath = path.join(__dirname + "/ffmpeg");
|
||||||
@ -48,7 +51,7 @@ if (fs.existsSync(ffmpegPath)) {
|
|||||||
// On linux, you require the command-line version of ffmpeg.
|
// On linux, you require the command-line version of ffmpeg.
|
||||||
if (process.platform !== "linux") ffmpeg.setFfmpegPath(ffmpegPath);
|
if (process.platform !== "linux") ffmpeg.setFfmpegPath(ffmpegPath);
|
||||||
} else {
|
} else {
|
||||||
console.error(chalk.red("❌ The FFmpeg executable wasn't found. See " + terminalLink("ffmpeg's website", "https://www.ffmpeg.org") + " for downloads."))
|
console.error(chalk.redBright("❌ The FFmpeg executable wasn't found. See " + terminalLink("ffmpeg's website", "https://www.ffmpeg.org") + " for downloads."))
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +81,7 @@ ytdl.getInfo(process.argv[2], (err, info) => {
|
|||||||
);
|
);
|
||||||
})
|
})
|
||||||
.on('error', err => {
|
.on('error', err => {
|
||||||
console.error(chalk.red('❌ Found an error: ' + err.message));
|
console.error(chalk.redBright('❌ Found an error: ' + err.message));
|
||||||
process.exit(1);
|
process.exit(1);
|
||||||
})
|
})
|
||||||
.on("end", () => {
|
.on("end", () => {
|
||||||
@ -116,7 +119,7 @@ ytdl.getInfo(process.argv[2], (err, info) => {
|
|||||||
log(chalk.yellow("✍🏻 Writing tags to mp3 file..."));
|
log(chalk.yellow("✍🏻 Writing tags to mp3 file..."));
|
||||||
|
|
||||||
id3.update(tags, path, () => {
|
id3.update(tags, path, () => {
|
||||||
if (fs.existsSync(path) && process.platform === "darwin") {
|
if (fs.existsSync(path) && process.platform === "darwin" && !hasflag("no-itunes")) {
|
||||||
log(chalk.yellow("🎵 Adding song to Apple Music library..."));
|
log(chalk.yellow("🎵 Adding song to Apple Music library..."));
|
||||||
cp.execSync(`cp "${path}" "/Users/job/Music/Music/Media/Automatically\ Add\ to\ Music.localized"`);
|
cp.execSync(`cp "${path}" "/Users/job/Music/Music/Media/Automatically\ Add\ to\ Music.localized"`);
|
||||||
}
|
}
|
||||||
|
46
package-lock.json
generated
46
package-lock.json
generated
@ -4,6 +4,11 @@
|
|||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
"@types/tinycolor2": {
|
||||||
|
"version": "1.4.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/@types/tinycolor2/-/tinycolor2-1.4.2.tgz",
|
||||||
|
"integrity": "sha512-PeHg/AtdW6aaIO2a+98Xj7rWY4KC1E6yOy7AFknJQ7VXUGNrMlyxDFxJo7HqLtjQms/ZhhQX52mLVW/EX3JGOw=="
|
||||||
|
},
|
||||||
"ajv": {
|
"ajv": {
|
||||||
"version": "6.10.2",
|
"version": "6.10.2",
|
||||||
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz",
|
"resolved": "https://registry.npmjs.org/ajv/-/ajv-6.10.2.tgz",
|
||||||
@ -177,6 +182,11 @@
|
|||||||
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/fast-json-stable-stringify/-/fast-json-stable-stringify-2.0.0.tgz",
|
||||||
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
|
"integrity": "sha1-1RQsDK7msRifh9OnYREGT4bIu/I="
|
||||||
},
|
},
|
||||||
|
"figlet": {
|
||||||
|
"version": "1.2.4",
|
||||||
|
"resolved": "https://registry.npmjs.org/figlet/-/figlet-1.2.4.tgz",
|
||||||
|
"integrity": "sha512-mv8YA9RruB4C5QawPaD29rEVx3N97ZTyNrE4DAfbhuo6tpcMdKnPVo8MlyT3RP5uPcg5M14bEJBq7kjFf4kAWg=="
|
||||||
|
},
|
||||||
"fluent-ffmpeg": {
|
"fluent-ffmpeg": {
|
||||||
"version": "2.1.2",
|
"version": "2.1.2",
|
||||||
"resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz",
|
"resolved": "https://registry.npmjs.org/fluent-ffmpeg/-/fluent-ffmpeg-2.1.2.tgz",
|
||||||
@ -217,6 +227,15 @@
|
|||||||
"assert-plus": "^1.0.0"
|
"assert-plus": "^1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"gradient-string": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/gradient-string/-/gradient-string-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-Lxog7IDMMWNjwo4O0KbdBvSewk4vW6kQe5XaLuuPCyCE65AGQ1P8YqKJa5dq8TYf/Ge31F+KjWzPR5mAJvjlAg==",
|
||||||
|
"requires": {
|
||||||
|
"chalk": "^2.4.1",
|
||||||
|
"tinygradient": "^0.4.1"
|
||||||
|
}
|
||||||
|
},
|
||||||
"har-schema": {
|
"har-schema": {
|
||||||
"version": "2.0.0",
|
"version": "2.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/har-schema/-/har-schema-2.0.0.tgz",
|
||||||
@ -232,9 +251,9 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"has-flag": {
|
"has-flag": {
|
||||||
"version": "3.0.0",
|
"version": "4.0.0",
|
||||||
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
|
||||||
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
"integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ=="
|
||||||
},
|
},
|
||||||
"html-entities": {
|
"html-entities": {
|
||||||
"version": "1.2.1",
|
"version": "1.2.1",
|
||||||
@ -439,6 +458,13 @@
|
|||||||
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
"integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"has-flag": "^3.0.0"
|
"has-flag": "^3.0.0"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"has-flag": {
|
||||||
|
"version": "3.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz",
|
||||||
|
"integrity": "sha1-tdRU3CGZriJWmfNGfloH87lVuv0="
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"supports-hyperlinks": {
|
"supports-hyperlinks": {
|
||||||
@ -474,6 +500,20 @@
|
|||||||
"supports-hyperlinks": "^2.0.0"
|
"supports-hyperlinks": "^2.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"tinycolor2": {
|
||||||
|
"version": "1.4.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/tinycolor2/-/tinycolor2-1.4.1.tgz",
|
||||||
|
"integrity": "sha1-9PrTM0R7wLB9TcjpIJ2POaisd+g="
|
||||||
|
},
|
||||||
|
"tinygradient": {
|
||||||
|
"version": "0.4.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/tinygradient/-/tinygradient-0.4.3.tgz",
|
||||||
|
"integrity": "sha512-tBPYQSs6eWukzzAITBSmqcOwZCKACvRa/XjPPh1mj4mnx4G3Drm51HxyCTU/TKnY8kG4hmTe5QlOh9O82aNtJQ==",
|
||||||
|
"requires": {
|
||||||
|
"@types/tinycolor2": "^1.4.0",
|
||||||
|
"tinycolor2": "^1.0.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
"tough-cookie": {
|
"tough-cookie": {
|
||||||
"version": "2.4.3",
|
"version": "2.4.3",
|
||||||
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
|
"resolved": "https://registry.npmjs.org/tough-cookie/-/tough-cookie-2.4.3.tgz",
|
||||||
|
@ -11,7 +11,10 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"axios": "^0.19.0",
|
"axios": "^0.19.0",
|
||||||
"chalk": "^2.4.2",
|
"chalk": "^2.4.2",
|
||||||
|
"figlet": "^1.2.4",
|
||||||
"fluent-ffmpeg": "^2.1.2",
|
"fluent-ffmpeg": "^2.1.2",
|
||||||
|
"gradient-string": "^1.2.0",
|
||||||
|
"has-flag": "^4.0.0",
|
||||||
"node-id3": "^0.1.11",
|
"node-id3": "^0.1.11",
|
||||||
"request": "^2.88.0",
|
"request": "^2.88.0",
|
||||||
"terminal-link": "^2.0.0",
|
"terminal-link": "^2.0.0",
|
||||||
|
Loading…
Reference in New Issue
Block a user