mirror of
https://github.com/beetbox/beets.git
synced 2026-02-09 00:41:57 +01:00
add beets Tomahawk resolver to extra/ directory
I'm not sure why this was a separate repository to begin with. It's now versioned with beets.
This commit is contained in:
parent
96de3ee400
commit
afd3a817af
2 changed files with 77 additions and 0 deletions
14
extra/beets-resolver/README.md
Normal file
14
extra/beets-resolver/README.md
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
beets Tomahawk resolver
|
||||
=======================
|
||||
|
||||
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).
|
||||
|
||||
[beets' web plugin]: http://beets.readthedocs.org/en/latest/plugins/web.html
|
||||
[beets music manager]: http://beets.radbox.org/
|
||||
[tomahawk player]: http://tomahawk-player.org/
|
||||
63
extra/beets-resolver/beets.js
Normal file
63
extra/beets-resolver/beets.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
var BEETS_HOST = 'localhost';
|
||||
var BEETS_PORT = 8337;
|
||||
|
||||
var BeetsResolver = Tomahawk.extend(TomahawkResolver,
|
||||
{
|
||||
settings:
|
||||
{
|
||||
name: 'beets',
|
||||
weight: 95,
|
||||
timeout: 5
|
||||
},
|
||||
resolve: function( qid, artist, album, title )
|
||||
{
|
||||
this.beetsQuery(qid,
|
||||
['artist:' + artist, 'album:' + album, 'title:' + title]
|
||||
);
|
||||
},
|
||||
search: function( qid, searchString )
|
||||
{
|
||||
this.beetsQuery(qid, searchString.split(' '));
|
||||
},
|
||||
beetsQuery: function( qid, queryParts )
|
||||
{
|
||||
var url = 'http://' + BEETS_HOST + ':' + BEETS_PORT + '/item/query/';
|
||||
for (var i = 0; i < queryParts.length; ++i) {
|
||||
url += encodeURIComponent(queryParts[i]);
|
||||
url += '/';
|
||||
}
|
||||
url = url.substring(0, url.length - 1); // Remove last /.
|
||||
|
||||
Tomahawk.asyncRequest(url, function(xhr) {
|
||||
var resp = JSON.parse(xhr.responseText);
|
||||
var items = resp['results'];
|
||||
|
||||
var searchResults = [];
|
||||
for (var i = 0; i < items.length; ++i) {
|
||||
item = items[i];
|
||||
searchResults.push({
|
||||
artist: item['artist'],
|
||||
album: item['album'],
|
||||
track: item['title'],
|
||||
albumpos: item['track'],
|
||||
source: "beets",
|
||||
url: "http://" + BEETS_HOST + ':' + BEETS_PORT + '/item/' + item['id'] + '/file',
|
||||
bitrate: Math.floor(item['bitrate'] / 1024),
|
||||
duration: Math.floor(item['length']),
|
||||
size: 83375, //!
|
||||
score: 1.0,
|
||||
extension: "mp3", //!
|
||||
mimetype: "audio/mpeg", //!
|
||||
year: item['year']
|
||||
});
|
||||
}
|
||||
|
||||
Tomahawk.addTrackResults({
|
||||
qid: qid,
|
||||
results: searchResults
|
||||
})
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Tomahawk.resolver.instance = BeetsResolver;
|
||||
Loading…
Reference in a new issue