-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
59 lines (57 loc) · 1.66 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env node
const prog = require('caporal')
const flastm = require('flastm')
prog
.version('1.0.0')
.description('A Polybar module to scrobble & love music in Lastfm')
.argument('<apikey>', 'Lastfm api_key', prog.REPEATABLE)
.argument('<apisecret>', 'Lastfm api_secret', prog.REPEATABLE)
.argument('<username>', 'Lastfm username', prog.REPEATABLE)
.argument('<password>', 'Lastfm password', prog.REPEATABLE)
.argument('<action>', '"scrobble" or "love"', prog.REPEATABLE)
.argument('<artist>', 'Artist name', prog.REPEATABLE)
.argument('<name>', 'Music name', prog.REPEATABLE)
.action(async function(args, options, logger) {
try {
const action = args['action']
const artist = args['artist']
const name = args['name']
const config = {
api_key: args['apikey'],
secret: args['apisecret'],
username: args['username'],
password: args['password']
}
const lastfm = flastm(config)
if (artist != '' && name != '') {
lastfm.auth.getMobileSession()
.then(session => {
const sk = session.session.key
if (action == 'love') {
lastfm.track.love(
artist,
name,
sk
)
logger.info(`${artist} - ${name} Scrobbling now and Loved`)
} else {
lastfm.track.scrobble(
artist,
name,
new Date().getTime()/1000,
sk
)
logger.info(`${artist} - ${name} Scrobbling now`)
}
})
.catch(() => logger.info(`${artist} - ${name} (Lastfm Offline)`))
} else {
logger.info(`${artist} - ${name}`)
}
} catch (e) {
const artist = args['artist']
const name = args['name']
logger.info(`${artist} - ${name}`)
}
});
prog.parse(process.argv)