-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
33 lines (29 loc) · 918 Bytes
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
const Task = require('data.task')
const { chain, last } = require('ramda')
const { List } = require('immutable-ext')
const Table = require('cli-table')
const { callSpotify } = require('./spotify')
const { callYouTube } = require('./youtube')
// parseArgs :: [a] -> [a]
const parseArgs = args =>
args.map(arg => {
const xs = arg.split(':')
return xs.length > 2 ? last(xs) : arg
})
// getArgs :: () -> Task [String]
const getArgs = () =>
new Task((reject, resolve) =>
resolve(List.of(...process.argv.slice(2))))
// unsafeDisplayLinks :: [Either URL String] -> ()
const unsafeDisplayLinks = xs => {
const table = new Table({head: ['YouTube Links'], colWidths: [60]})
xs.forEach(x => {
table.push([x.fold(x => x, y => y)])
})
console.log(table.toString())
}
getArgs()
.map(parseArgs)
.chain(callSpotify)
.chain(callYouTube)
.fork(_ => console.log('Video not found.'), unsafeDisplayLinks)