// Copyright (c) 2009 by Prathyush Thota // // This work is licensed for reuse under an MIT license. Details are // given in the LICENSE.txt file included with this file. const Library = Module("library", { init: function () { this.MAIN_LIBRARY = LibraryUtils.mainLibrary; }, _toJSArray: function (enum) ArrayConverter.JSArray(enum), // TODO: return some actually useful objects. ;-) /** * Returns an array of all the artist names in the main library. * * @returns {string[]} */ getArtists: function getArtists() this._toJSArray(this.MAIN_LIBRARY.getDistinctValuesForProperty(SBProperties.artistName)), // FIXME: ken do we really want to remove duplicates? If so, why not tracks too? --djk /** * Returns an array of all the album names for artist in the * main library. * * @param {param} artist The artist name. * @returns {string[]} */ getAlbums: function getAlbums(artist) { let albums = this._toJSArray(this.MAIN_LIBRARY.getItemsByProperty(SBProperties.artistName, artist)) .map(function (track) track.getProperty(SBProperties.albumName)); return util.Array.uniq(albums); }, /** * Returns an array of all the track names for artist and * album in the main library. * * @param {param} artist The artist name. * @param {param} album The album name. * @returns {string[]} */ getTracks: function getTracks(artist, album) { const properties = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"] .createInstance(Ci.sbIMutablePropertyArray); properties.appendProperty(SBProperties.artistName, artist); properties.appendProperty(SBProperties.albumName, album); return this._toJSArray(this.MAIN_LIBRARY.getItemsByProperties(properties)) .map(function (track) track.getProperty(SBProperties.trackName)); } }, { }, { }); // vim: set fdm=marker sw=4 ts=4 et: