From a5bf3af61f86adb4970004aaf22ccb6fd3ddd5f3 Mon Sep 17 00:00:00 2001 From: "Uwe L. Korn" Date: Fri, 7 Nov 2014 19:28:09 +0100 Subject: [PATCH] Add tool to query the stream URL for (artist, track, album) --- tools/getstreamurl.js | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 tools/getstreamurl.js diff --git a/tools/getstreamurl.js b/tools/getstreamurl.js new file mode 100644 index 000000000..7b67e3c46 --- /dev/null +++ b/tools/getstreamurl.js @@ -0,0 +1,50 @@ +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); +