diff --git a/extra/beets-resolver/README.md b/extra/beets-resolver/README.md index 4683bd2b9..e0b36f237 100644 --- a/extra/beets-resolver/README.md +++ b/extra/beets-resolver/README.md @@ -5,9 +5,10 @@ This is a script resolver for [Tomahawk][tomahawk player] that hooks into [beets][beets music manager]. It uses [beets' web plugin][] to access your beets library remotely. -To use it, just start ``beet web``, load this resolver, and start playing -music. Change the hostname and port at the top of the file if the server isn't -running on localhost (I'll make a real UI for this eventually). +To use it, just start ``beet web`` on the machine with your music and load this +resolver on the machine running Tomahawk. Use the configuration button on the +resolver to set the hostname and port of the beets server (these default to +localhost:8337). You should be able to start playing music immediately. [beets' web plugin]: http://beets.readthedocs.org/en/latest/plugins/web.html [beets music manager]: http://beets.radbox.org/ diff --git a/extra/beets-resolver/beets.js b/extra/beets-resolver/beets.js index c188158b5..a66474316 100644 --- a/extra/beets-resolver/beets.js +++ b/extra/beets-resolver/beets.js @@ -1,14 +1,14 @@ -var BEETS_HOST = 'localhost'; -var BEETS_PORT = 8337; - var BeetsResolver = Tomahawk.extend(TomahawkResolver, { + // Basic setup. settings: { name: 'beets', weight: 95, timeout: 5 }, + + // Resolution. resolve: function( qid, artist, album, title ) { this.beetsQuery(qid, @@ -19,9 +19,13 @@ var BeetsResolver = Tomahawk.extend(TomahawkResolver, { this.beetsQuery(qid, searchString.split(' ')); }, + baseUrl: function() { + return 'http://' + this.host + ':' + this.port; + }, beetsQuery: function( qid, queryParts ) { - var url = 'http://' + BEETS_HOST + ':' + BEETS_PORT + '/item/query/'; + var baseUrl = this.baseUrl(); + var url = baseUrl + '/item/query/'; for (var i = 0; i < queryParts.length; ++i) { url += encodeURIComponent(queryParts[i]); url += '/'; @@ -41,7 +45,7 @@ var BeetsResolver = Tomahawk.extend(TomahawkResolver, track: item['title'], albumpos: item['track'], source: "beets", - url: "http://" + BEETS_HOST + ':' + BEETS_PORT + '/item/' + item['id'] + '/file', + url: baseUrl + '/item/' + item['id'] + '/file', bitrate: Math.floor(item['bitrate'] / 1024), duration: Math.floor(item['length']), size: 83375, //! @@ -57,7 +61,42 @@ var BeetsResolver = Tomahawk.extend(TomahawkResolver, results: searchResults }) }); - } + }, + + // Configuration. + getConfigUi: function () { + var uiData = Tomahawk.readBase64("config.ui"); + return { + "widget": uiData, + "fields": [{ + name: "host", + widget: "hostField", + property: "text" + }, { + name: "port", + widget: "portField", + property: "text" + }] + }; + }, + newConfigSaved: function () { + var userConfig = this.getUserConfig(); + + this.host = userConfig.host || 'localhost'; + + var port = userConfig.port; + port = parseInt(port); + if (isNaN(port) || !port) { + port = 8337; + } + userConfig.port = port; + + this.port = port; + }, + + // Defaults. + host: 'localhost', + port: 8337 }); Tomahawk.resolver.instance = BeetsResolver; diff --git a/extra/beets-resolver/config.ui b/extra/beets-resolver/config.ui new file mode 100644 index 000000000..e7f079720 --- /dev/null +++ b/extra/beets-resolver/config.ui @@ -0,0 +1,76 @@ + + + Form + + + + 0 + 0 + 300 + 80 + + + + + 300 + 80 + + + + Form + + + + + 10 + 20 + 281 + 61 + + + + + QFormLayout::FieldsStayAtSizeHint + + + + + Host + + + + + + + + + + localhost + + + + + + + Port + + + + + + + + + + 8337 + + + + + + layoutWidget + portField + + + +