Implementation of the JS plugins API from Tomahawk for NodeJS
Implementation of the JS plugins API from Tomahawk as a library for NodeJS and io.js.
It also features an executable
tomahawkjs which can be used to execute resolver functionality from the commandline without the need to write any code.
(This implementation is not fully feature complete compared to the desktop client but hubot-tomahk is an exmple usage of parts of it)
This utility supports calling the typical functionalities of a single resolver. While its main purpose is to support developing resolvers, you can use it also standalone. For example given the soundcloud resolver, you can build your own commandline (headless) soundcloud player with just this single commandline:
tomahawkjs resolve soundcloud.axe <artist> <title> | jq -r .url | xargs cvlc
Resolving a song using a given resolver can either be done with a bundled
.axe or a directory containing all the files as in a developemnt setting.
tomahawkjs resolve <path-to-resolver> <artist> <title> [<album>]
Search works similarily to resolving but you can specify an arbitrary number of commandline arfuments which will be joined together to form a single search query.
tomahawkjs search <path-to-resolver> <query-part1> [<query-part2> [..]]
To load a single resolver, we simply use the following code if we know the path to the .axe file:
As the time of writing, Tomahawk resolvers were all implicitly able to resolve from a combination of Artist and Title (and Albumname) to a stream URL if their feeding service provided this tune. Furthermore there are some other capabilities that can be implemented:
browsable: Resolver exposes a music collection that can be browsed.
playlistsync: Can sync playlists
urllookup: Can resolve from an URL to a combination of Artist+Title/Album/Playlist
Checking for one of these can be done via:
The main functionality of a Tomahawk resolver is to find a stremable URL for a combination of artist and song title and optionally an album. The requests for resolving should be indentified with a unqiue id for each query. Alternatively we can search a given string without specifying explicitly artist or title.
contexton'track-result'console.log'Found a new streamable URL for request ' + qid + ':' + resulturl;;// Search for a streambale URL for song title by artist on album.instanceresolvesomeId1 artist album title;// Search for a streamable URL for a song similar to searchqueryinstancesearchsomeId2 searchquery;
As an inverse for the lookup of (Artist, Title) -> stream-URL, many resolvers have the
urllookup capability to resolve from a URL pointing to a music service to artist/album/playlist/.. that is encoded in the URL.
// Define a handler for found URL mappingscontexton'url-result'if resulttype == 'track'console.log'Found URL for track ' + resultartist + ' - ' + resulttitle;else if resulttype == 'album'console.log'Found URL for album ' + resultartist + ' - ' + resultname;else if resulttype == 'playlist'console.log'Found URL for playlist ' + resulttitle;else if resulttype == 'artist'console.log'Found URL for artist ' + resultname;;// Check if resolver has URLLookup capabilityif contexthasCapability'urllookup'// Can we handle this URL?if instancecanParseUrlurlinstancelookupUrlurl;
Resolver that have the
browsable capability export the whole collection of music material that can be streamed from them.
The browsing of the collection is done by pulling the relevant information on demand.
// Handler for the list of artists (string)contexton'artist-results'console.log'Got a list of ' + artistslength + ' artists';// Query the albums for the first artistinstancealbumsqid + artists0 artists0;;// Handler for a list of albums (string)contexton'album-results'console.log'Got a list of ' + albumslength + ' albums for artist ' + artist;// Query the first album for all its tracksinstancetracksqid + album artist album;;// Handler for a list of tracks for an albumcontenton'albumtrack-results'console.log'Got a list of ' + trackslength + ' songs on ' + album + ' by ' + artist;console.log'The first song is called ' + tracks0track;;if contexthasCapability'browsable'// Get basic information about the collectionvar info = instancecollection;// Not all collections support the retrieval of the total number of tracksif infotrackcount == nullconsole.log'We are browsing the collection ' + infoprettyname + ': ' + infodescription;elseconsole.log'We are browsing the collection (' + infotrackcount + ' tracks) ' + infoprettyname + ': ' + infodescription;// Query for the list of all artistsinstanceartistssomeQid;