More work done
This commit is contained in:
parent
19bf649ff4
commit
e5fcabdd37
10
main.js
10
main.js
@ -63,13 +63,13 @@ ytdl.getInfo(process.argv[2], (err, info) => {
|
||||
//filter: 'audioonly',
|
||||
});
|
||||
|
||||
const path = `${__dirname}/music/${info.title}.mp3`;
|
||||
const filePath = path.join(__dirname, `/music/${info.title}.mp3`);
|
||||
|
||||
log(chalk.yellow("🏁 Starting download..."));
|
||||
|
||||
ffmpeg(stream)
|
||||
.audioBitrate(128)
|
||||
.save(path)
|
||||
.save(filePath)
|
||||
.on("progress", p => {
|
||||
const progress = convertTime(p.timemark);
|
||||
log(
|
||||
@ -118,10 +118,10 @@ ytdl.getInfo(process.argv[2], (err, info) => {
|
||||
|
||||
log(chalk.yellow("✍🏻 Writing tags to mp3 file..."));
|
||||
|
||||
id3.update(tags, path, () => {
|
||||
if (fs.existsSync(path) && process.platform === "darwin" && !hasflag("no-itunes")) {
|
||||
id3.update(tags, filePath, () => {
|
||||
if (fs.existsSync(filePath) && process.platform === "darwin" && !hasflag("no-itunes")) {
|
||||
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 "${filePath}" "/Users/job/Music/Music/Media/Automatically\ Add\ to\ Music.localized"`);
|
||||
}
|
||||
|
||||
log(chalk.green(`✅ Successfully downloaded ${info.title}.mp3!\n`));
|
||||
|
55
tags.js
Normal file
55
tags.js
Normal file
@ -0,0 +1,55 @@
|
||||
const id3 = require('node-id3');
|
||||
const path = require('path');
|
||||
const chalk = require('chalk');
|
||||
const axios = require('axios');
|
||||
const request = require("request").defaults({ encoding: null });
|
||||
const fs = require('fs');
|
||||
const hasflag = require('has-flag');
|
||||
const cp = require('child_process');
|
||||
|
||||
const filePath = path.join(__dirname, '/music/', process.argv[2]);
|
||||
|
||||
const artist = process.argv[3];
|
||||
const song = process.argv[4];
|
||||
|
||||
console.log(chalk.yellow("🎵 Calling iTunes api..."));
|
||||
|
||||
axios.get(`https://itunes.apple.com/search?term=${artist} ${song}&entity=song`).then(res => {
|
||||
request.get(res.data.results[0].artworkUrl100.replace('100x100', '3000x3000'), function(err, _res, body) {
|
||||
axios.get(`https://itunes.apple.com/search?term=${artist} ${res.data.results[0].collectionName}&entity=album`).then(album => {
|
||||
console.log(chalk.green("✅ Retreived information!"));
|
||||
|
||||
var tags = {
|
||||
title: res.data.results[0].trackName,
|
||||
artist: res.data.results[0].artistName,
|
||||
performerInfo: album.data.results[0].artistName,
|
||||
album: res.data.results[0].collectionName,
|
||||
copyright: album.data.results[0].copyright,
|
||||
year: new Date(res.data.results[0].releaseDate).getFullYear(),
|
||||
image: {
|
||||
mime: "jpeg",
|
||||
type: {
|
||||
id: 3,
|
||||
name: "front cover"
|
||||
},
|
||||
imageBuffer: body
|
||||
},
|
||||
fileType: "mp3",
|
||||
genre: res.data.results[0].primaryGenreName
|
||||
};
|
||||
|
||||
console.log(chalk.yellow("✍🏻 Writing tags to mp3 file..."));
|
||||
|
||||
id3.update(tags, filePath, () => {
|
||||
if (fs.existsSync(filePath) && process.platform === "darwin" && !hasflag("no-itunes")) {
|
||||
console.log(chalk.yellow("🎵 Adding song to Apple Music library..."));
|
||||
cp.execSync(`cp "${filePath}" "/Users/job/Music/Music/Media/Automatically\ Add\ to\ Music.localized"`);
|
||||
}
|
||||
|
||||
console.log(chalk.green(`✅ Successfully wrote ${process.argv[2]}.mp3!\n`));
|
||||
|
||||
process.exit();
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
Loading…
Reference in New Issue
Block a user