mirror of
https://github.com/beetbox/beets.git
synced 2026-01-11 10:26:36 +01:00
add configuration UI to Tomahawk resolver
This commit is contained in:
parent
afd3a817af
commit
7aa88a762c
3 changed files with 125 additions and 9 deletions
|
|
@ -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/
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
76
extra/beets-resolver/config.ui
Normal file
76
extra/beets-resolver/config.ui
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>Form</class>
|
||||
<widget class="QWidget" name="Form">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>0</x>
|
||||
<y>0</y>
|
||||
<width>300</width>
|
||||
<height>80</height>
|
||||
</rect>
|
||||
</property>
|
||||
<property name="minimumSize">
|
||||
<size>
|
||||
<width>300</width>
|
||||
<height>80</height>
|
||||
</size>
|
||||
</property>
|
||||
<property name="windowTitle">
|
||||
<string>Form</string>
|
||||
</property>
|
||||
<widget class="QWidget" name="layoutWidget">
|
||||
<property name="geometry">
|
||||
<rect>
|
||||
<x>10</x>
|
||||
<y>20</y>
|
||||
<width>281</width>
|
||||
<height>61</height>
|
||||
</rect>
|
||||
</property>
|
||||
<layout class="QFormLayout" name="formLayout">
|
||||
<property name="fieldGrowthPolicy">
|
||||
<enum>QFormLayout::FieldsStayAtSizeHint</enum>
|
||||
</property>
|
||||
<item row="0" column="0">
|
||||
<widget class="QLabel" name="label">
|
||||
<property name="text">
|
||||
<string>Host</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<widget class="QLineEdit" name="hostField">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>localhost</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="0">
|
||||
<widget class="QLabel" name="label_2">
|
||||
<property name="text">
|
||||
<string>Port</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item row="1" column="1">
|
||||
<widget class="QLineEdit" name="portField">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="placeholderText">
|
||||
<string>8337</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<zorder>layoutWidget</zorder>
|
||||
<zorder>portField</zorder>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
||||
Loading…
Reference in a new issue