2021-05-30 15:31:27 +00:00
|
|
|
#!/usr/bin/env node
|
|
|
|
import ytdl from 'ytdl-core';
|
|
|
|
import getArtistTitle from 'get-artist-title'
|
|
|
|
import {parse} from './src/parser.js'
|
|
|
|
import {generate} from './src/cue.js'
|
2021-06-09 18:51:23 +00:00
|
|
|
import minimist from 'minimist'
|
2021-05-30 15:31:27 +00:00
|
|
|
|
2021-06-09 18:51:23 +00:00
|
|
|
let argv = minimist(process.argv.slice(2), {
|
|
|
|
string: 'audio-file'
|
|
|
|
});
|
|
|
|
|
|
|
|
if (argv._.length <2 || argv.help ){
|
|
|
|
console.log(`Usage
|
2021-05-30 15:31:27 +00:00
|
|
|
$ youtube-cue --audio-file <youtube_url> <output.cue>
|
|
|
|
|
|
|
|
Options
|
|
|
|
--help, Show help
|
|
|
|
--audio-file, Input Audio File
|
|
|
|
|
|
|
|
Examples
|
|
|
|
$ youtube-cue "https://www.youtube.com/watch?v=THzUassmQwE" output.cue
|
2021-06-09 18:51:23 +00:00
|
|
|
output.cue saved`)
|
|
|
|
} else {
|
|
|
|
let url = argv._[0]
|
|
|
|
let output_file = argv._[1]
|
2021-05-30 15:31:27 +00:00
|
|
|
|
|
|
|
ytdl.getInfo(url).then(info=>{
|
2021-06-09 18:51:23 +00:00
|
|
|
let audioFile = argv['audio-file']? argv['audio-file'] : `${info.videoDetails.title}.m4a`
|
2021-05-30 15:31:27 +00:00
|
|
|
let res = getArtistTitle(info.videoDetails.title,{
|
|
|
|
defaultArtist: "Unknown Artist",
|
|
|
|
defaultTitle: info.videoDetails.title
|
|
|
|
});
|
|
|
|
let [artist, album] = res
|
|
|
|
artist = (info.videoDetails.media ? info.videoDetails.media.artist : artist)
|
|
|
|
let tracks = parse(info.videoDetails.description, {artist})
|
2021-06-09 18:51:23 +00:00
|
|
|
generate({tracks, artist, audioFile, album}, output_file)
|
2021-05-30 15:31:27 +00:00
|
|
|
})
|
|
|
|
}
|