1 // Copyright (c) 2009 by Prathyush Thota <prathyushthota@gmail.com>
2 // Copyright (c) 2009 by Doug Kearns <dougkearns@gmail.com>
4 // This work is licensed for reuse under an MIT license. Details are
5 // given in the LICENSE.txt file included with this file.
8 // TODO: flesh this out
9 const Library = Module("library", {
11 this.MAIN_LIBRARY = LibraryUtils.mainLibrary;
15 * Converts an XPCOM enumerator to a JavaScript array.
17 * @param {nsISimpleEnumerator|nsIStringEnumerator|nsIArray} enum The enumerator to convert.
20 _toJSArray: function _toJSArray(enum) ArrayConverter.JSArray(enum),
23 * Returns an array of all the artist names in the main library.
27 getArtists: function getArtists() this._toJSArray(this.MAIN_LIBRARY.getDistinctValuesForProperty(SBProperties.artistName)),
29 // FIXME: Prathyush do we really want to remove duplicates? If so, why not tracks too? --djk
31 * Returns an array of all the album names for *artist* in the main
34 * @param {string} artist The artist's name.
37 getAlbums: function getAlbums(artist) {
38 let albums = this._toJSArray(this.MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist))
39 .map(function (track) track.getProperty(SBProperties.albumName));
40 return array.uniq(albums);
44 * Returns an array of all the track names for *artist* and *album* in the
47 * @param {string} artist The artist's name.
48 * @param {string} album The album's name.
51 getTracks: function getTracks(artist, album) {
52 let properties = services.MutablePropertyArray();
54 properties.appendProperty(SBProperties.artistName, artist);
55 properties.appendProperty(SBProperties.albumName, album);
57 return this._toJSArray(this.MAIN_LIBRARY.getItemsByProperties(properties))
58 .map(function (track) track.getProperty(SBProperties.trackName));
64 // vim: set fdm=marker sw=4 ts=4 et: