More work done

This commit is contained in:
corner 2019-11-26 07:30:26 +01:00
parent 19bf649ff4
commit e5fcabdd37
3 changed files with 60 additions and 15 deletions

10
main.js
View File

@ -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
View 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();
})
})
})
})

10
test.js
View File

@ -1,10 +0,0 @@
const ytdl = require("ytdl-core");
ytdl.getInfo(process.argv[2], (err, info) => {
//let stream = ytdl(process.argv[2], {
// quality: "highestaudio"
//filter: 'audioonly',
//});
console.log(info);
});