switch to minimist arg parser
This commit is contained in:
parent
c730a8f823
commit
c06841f57d
33
index.js
33
index.js
|
@ -1,36 +1,31 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import meow from 'meow';
|
|
||||||
import ytdl from 'ytdl-core';
|
import ytdl from 'ytdl-core';
|
||||||
import getArtistTitle from 'get-artist-title'
|
import getArtistTitle from 'get-artist-title'
|
||||||
import {parse} from './src/parser.js'
|
import {parse} from './src/parser.js'
|
||||||
import {generate} from './src/cue.js'
|
import {generate} from './src/cue.js'
|
||||||
|
import minimist from 'minimist'
|
||||||
|
|
||||||
const cli = meow(`
|
let argv = minimist(process.argv.slice(2), {
|
||||||
Usage
|
string: 'audio-file'
|
||||||
|
});
|
||||||
|
|
||||||
|
if (argv._.length <2 || argv.help ){
|
||||||
|
console.log(`Usage
|
||||||
$ youtube-cue --audio-file <youtube_url> <output.cue>
|
$ youtube-cue --audio-file <youtube_url> <output.cue>
|
||||||
|
|
||||||
Options
|
Options
|
||||||
--help, Show help
|
--help, Show help
|
||||||
--version, Show version
|
|
||||||
--audio-file, Input Audio File
|
--audio-file, Input Audio File
|
||||||
|
|
||||||
Examples
|
Examples
|
||||||
$ youtube-cue "https://www.youtube.com/watch?v=THzUassmQwE" output.cue
|
$ youtube-cue "https://www.youtube.com/watch?v=THzUassmQwE" output.cue
|
||||||
output.cue saved
|
output.cue saved`)
|
||||||
`, {
|
} else {
|
||||||
importMeta: import.meta,
|
let url = argv._[0]
|
||||||
flags: {
|
let output_file = argv._[1]
|
||||||
audioFile: {type: 'string'}
|
|
||||||
},
|
|
||||||
allowUnknownFlags: false
|
|
||||||
});
|
|
||||||
|
|
||||||
if(cli.input.length==2) {
|
|
||||||
let url = cli.input[0]
|
|
||||||
let output_file = cli.input[1]
|
|
||||||
|
|
||||||
ytdl.getInfo(url).then(info=>{
|
ytdl.getInfo(url).then(info=>{
|
||||||
let audioFile = cli.flags.audioFile? cli.flags.audioFile : `${info.videoDetails.title}.m4a`
|
let audioFile = argv['audio-file']? argv['audio-file'] : `${info.videoDetails.title}.m4a`
|
||||||
let res = getArtistTitle(info.videoDetails.title,{
|
let res = getArtistTitle(info.videoDetails.title,{
|
||||||
defaultArtist: "Unknown Artist",
|
defaultArtist: "Unknown Artist",
|
||||||
defaultTitle: info.videoDetails.title
|
defaultTitle: info.videoDetails.title
|
||||||
|
@ -38,8 +33,6 @@ if(cli.input.length==2) {
|
||||||
let [artist, album] = res
|
let [artist, album] = res
|
||||||
artist = (info.videoDetails.media ? info.videoDetails.media.artist : artist)
|
artist = (info.videoDetails.media ? info.videoDetails.media.artist : artist)
|
||||||
let tracks = parse(info.videoDetails.description, {artist})
|
let tracks = parse(info.videoDetails.description, {artist})
|
||||||
generate({tracks, artist, audioFile, album}, cli.input[1])
|
generate({tracks, artist, audioFile, album}, output_file)
|
||||||
})
|
})
|
||||||
} else {
|
|
||||||
cli.showHelp()
|
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -15,7 +15,7 @@
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"console-log-level": "^1.4.1",
|
"console-log-level": "^1.4.1",
|
||||||
"get-artist-title": "^1.3.1",
|
"get-artist-title": "^1.3.1",
|
||||||
"meow": "^10.0.0",
|
"minimist": "^1.2.5",
|
||||||
"ytdl-core": "^4.8.2"
|
"ytdl-core": "^4.8.2"
|
||||||
},
|
},
|
||||||
"repository": {
|
"repository": {
|
||||||
|
|
Loading…
Reference in New Issue