/
getstreamurl.js
50 lines (42 loc) · 1.41 KB
/
getstreamurl.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
var argv = require('minimist')(process.argv.slice(2));
var utils = require('../test/utils.js');
if (argv._.length < 1) {
console.error("Please specify a single resolver");
process.exit(1);
}
if (argv._.length < 3) {
console.error("You need to specify at least an artist and a track for resolving.");
process.exit(1);
}
// We use the string argument as the path to the resolver.
var resolverPath = argv._[0];
var artist = argv._[1];
var track = argv._[2];
var album = "";
if (argv._.length > 3) {
album = argv._[3];
}
// All -/-- arguments will be added to the config.
// If --config is specified, we will instead load them from the config file.
var resolverConfig = argv;
if (argv.hasOwnProperty("config")) {
// FIXME: Add support for absolute paths
resolverConfig = require("../" + argv.config);
} else {
delete resolverConfig._;
}
var resolver = {};
utils.loadAxe(resolverPath, resolver, function () {
// Use once instead of on here to only handle the first result.
resolver.context.once('track-result', function (qid, result) {
if (resolver.context.Tomahawk.hasCustomUrlHandler) {
resolver.context.getStreamUrl(2, result.url);
} else {
console.log(result.url);
}
});
resolver.context.once('stream-url', function (qid, url) {
console.log(url);
});
resolver.instance.resolve("qid", artist, album, track);
}, resolverConfig);