mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2025-12-20 17:57:58 +01:00
Move library convenience functions to a library module.
This commit is contained in:
@@ -1392,20 +1392,24 @@ function Completion() //{{{
|
|||||||
|
|
||||||
song: function song(context, args)
|
song: function song(context, args)
|
||||||
{
|
{
|
||||||
|
// TODO: useful descriptions?
|
||||||
|
function map(list) list.map(function (i) [i, ""]);
|
||||||
|
let [artist, album] = [args[0], args[1]];
|
||||||
|
|
||||||
if (args.completeArg == 0)
|
if (args.completeArg == 0)
|
||||||
{
|
{
|
||||||
context.title = ["Artists"];
|
context.title = ["Artists"];
|
||||||
context.completions = player.getArtists();
|
context.completions = map(library.getArtists());
|
||||||
}
|
}
|
||||||
else if (args.completeArg == 1)
|
else if (args.completeArg == 1)
|
||||||
{
|
{
|
||||||
context.title = ["Albums by " + args[0]];
|
context.title = ["Albums by " + artist];
|
||||||
context.completions = player.getAlbums(args[0]);
|
context.completions = map(library.getAlbums(artist));
|
||||||
}
|
}
|
||||||
else if (args.completeArg == 2)
|
else if (args.completeArg == 2)
|
||||||
{
|
{
|
||||||
context.title = ["Tracks from " + args[1] + " by " + args[0]];
|
context.title = ["Tracks from " + album + " by " + artist];
|
||||||
context.completions = player.getTracks(args[0], args[1]);
|
context.completions = map(library.getTracks(artist, album));
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -169,6 +169,7 @@ const config = { //{{{
|
|||||||
"bookmarks.js",
|
"bookmarks.js",
|
||||||
"tabs.js",
|
"tabs.js",
|
||||||
"player.js",
|
"player.js",
|
||||||
|
"library.js"
|
||||||
],
|
],
|
||||||
|
|
||||||
stop: function() {
|
stop: function() {
|
||||||
@@ -180,8 +181,6 @@ const config = { //{{{
|
|||||||
// Adding a mode for Player
|
// Adding a mode for Player
|
||||||
//modes.addMode("PLAYER"); // Player mode for songbird
|
//modes.addMode("PLAYER"); // Player mode for songbird
|
||||||
|
|
||||||
// var artistArray = getArtists();
|
|
||||||
|
|
||||||
// TODO: support 'nrformats'? -> probably not worth it --mst
|
// TODO: support 'nrformats'? -> probably not worth it --mst
|
||||||
function incrementURL(count)
|
function incrementURL(count)
|
||||||
{
|
{
|
||||||
@@ -246,8 +245,8 @@ const config = { //{{{
|
|||||||
liberator.loadModule("marks", Marks);
|
liberator.loadModule("marks", Marks);
|
||||||
liberator.loadModule("quickmarks", QuickMarks);
|
liberator.loadModule("quickmarks", QuickMarks);
|
||||||
liberator.loadModule("hints", Hints);
|
liberator.loadModule("hints", Hints);
|
||||||
// Load the Player module
|
|
||||||
liberator.loadModule("player", Player);
|
liberator.loadModule("player", Player);
|
||||||
|
liberator.loadModule("library", Library);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
////////////////////// STYLES //////////////////////////////////////////////////
|
////////////////////// STYLES //////////////////////////////////////////////////
|
||||||
|
|||||||
72
xulmus/content/library.js
Normal file
72
xulmus/content/library.js
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
function Library() // {{{
|
||||||
|
{
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
////////////////////// PRIVATE SECTION /////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
const MAIN_LIBRARY = LibraryUtils.mainLibrary;
|
||||||
|
|
||||||
|
function toJSArray(enum) ArrayConverter.JSArray(enum)
|
||||||
|
|
||||||
|
function getArtistsArray()
|
||||||
|
{
|
||||||
|
return toJSArray(MAIN_LIBRARY.getDistinctValuesForProperty(SBProperties.artistName));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the artist names before hand.
|
||||||
|
let artists = getArtistsArray();
|
||||||
|
|
||||||
|
/////////////////////////////////////////////////////////////////////////////}}}
|
||||||
|
////////////////////// PUBLIC SECTION //////////////////////////////////////////
|
||||||
|
/////////////////////////////////////////////////////////////////////////////{{{
|
||||||
|
|
||||||
|
// TODO: return some actually useful objects. ;-)
|
||||||
|
return {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns an array of all the artist names in the main library.
|
||||||
|
*
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
getArtists: function getArtists() artists,
|
||||||
|
|
||||||
|
// 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 <b>artist</b> in the
|
||||||
|
* main library.
|
||||||
|
*
|
||||||
|
* @param {param} artist The artist name.
|
||||||
|
* @returns {string[]}
|
||||||
|
*/
|
||||||
|
getAlbums: function getAlbums(artist)
|
||||||
|
{
|
||||||
|
let albums = toJSArray(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 <b>artist</b> and
|
||||||
|
* <b>album</b> 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 toJSArray(MAIN_LIBRARY.getItemsByProperties(properties))
|
||||||
|
.map(function (track) track.getProperty(SBProperties.trackName));
|
||||||
|
}
|
||||||
|
|
||||||
|
};
|
||||||
|
//}}}
|
||||||
|
} // }}}
|
||||||
|
|
||||||
|
// vim: set fdm=marker sw=4 ts=4 et:
|
||||||
@@ -11,47 +11,6 @@ function Player() // {{{
|
|||||||
// Get the focus to the visible playlist first
|
// Get the focus to the visible playlist first
|
||||||
//window._SBShowMainLibrary();
|
//window._SBShowMainLibrary();
|
||||||
|
|
||||||
function getArtistsArray()
|
|
||||||
{
|
|
||||||
var list = LibraryUtils.mainLibrary;
|
|
||||||
|
|
||||||
// Create an enumeration listener to count each item
|
|
||||||
var listener = {
|
|
||||||
count: 0,
|
|
||||||
onEnumerationBegin: function (aMediaList) {
|
|
||||||
this.count = 0;
|
|
||||||
},
|
|
||||||
onEnumeratedItem: function (aMediaList, aMediaItem) {
|
|
||||||
this.count++;
|
|
||||||
},
|
|
||||||
onEnumerationEnd: function (aMediaList, aStatusCode) {}
|
|
||||||
};
|
|
||||||
|
|
||||||
var artistCounts = {};
|
|
||||||
var artists = list.getDistinctValuesForProperty(SBProperties.artistName);
|
|
||||||
var artist;
|
|
||||||
var artistArray = [];
|
|
||||||
var i = 0;
|
|
||||||
// Count the number of media items for each distinct artist
|
|
||||||
while (artists.hasMore())
|
|
||||||
{
|
|
||||||
artist = artists.getNext();
|
|
||||||
artistArray[i] = [artist, artist];
|
|
||||||
list.enumerateItemsByProperty(SBProperties.artistName,
|
|
||||||
artist,
|
|
||||||
listener,
|
|
||||||
Ci.sbIMediaList.ENUMERATIONTYPE_LOCKING);
|
|
||||||
artistCounts[artist] = listener.count;
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
//liberator.dump("Count : "+artistCounts.toSource());
|
|
||||||
return artistArray;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the artist names before hand.
|
|
||||||
let artists = getArtistsArray();
|
|
||||||
|
|
||||||
const pageService = Cc["@songbirdnest.com/Songbird/MediaPageManager;1"].getService(Ci.sbIMediaPageManager);
|
const pageService = Cc["@songbirdnest.com/Songbird/MediaPageManager;1"].getService(Ci.sbIMediaPageManager);
|
||||||
|
|
||||||
// Register Callbacks for searching.
|
// Register Callbacks for searching.
|
||||||
@@ -684,61 +643,6 @@ function Player() // {{{
|
|||||||
{
|
{
|
||||||
if (gMM.sequencer.currentItem)
|
if (gMM.sequencer.currentItem)
|
||||||
gMM.sequencer.currentItem.setProperty(SBProperties.rating, rating);
|
gMM.sequencer.currentItem.setProperty(SBProperties.rating, rating);
|
||||||
},
|
|
||||||
|
|
||||||
getArtists: function getArtists()
|
|
||||||
{
|
|
||||||
return artists;
|
|
||||||
},
|
|
||||||
|
|
||||||
getAlbums: function getAlbums(artist)
|
|
||||||
{
|
|
||||||
var list = LibraryUtils.mainLibrary;
|
|
||||||
var albumArray = [], returnArray = [];
|
|
||||||
var items = list.getItemsByProperty(SBProperties.artistName, artist).enumerate();
|
|
||||||
var i = 0, j = 0;
|
|
||||||
|
|
||||||
while (items.hasMoreElements())
|
|
||||||
{
|
|
||||||
album = items.getNext().getProperty(SBProperties.albumName);
|
|
||||||
albumArray[i] = [album, album];
|
|
||||||
|
|
||||||
if (i == 0)
|
|
||||||
{
|
|
||||||
returnArray[j] = albumArray[i];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
else if (albumArray[i-1].toString() != albumArray[i].toString())
|
|
||||||
{
|
|
||||||
returnArray[i] = albumArray[i];
|
|
||||||
j++;
|
|
||||||
}
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnArray;
|
|
||||||
},
|
|
||||||
|
|
||||||
getTracks: function getTracks(artist, album)
|
|
||||||
{
|
|
||||||
var list = LibraryUtils.mainLibrary;
|
|
||||||
var tracksArray = [];
|
|
||||||
var pa = Cc["@songbirdnest.com/Songbird/Properties/MutablePropertyArray;1"]
|
|
||||||
.createInstance(Ci.sbIMutablePropertyArray);
|
|
||||||
var i = 0;
|
|
||||||
|
|
||||||
pa.appendProperty(SBProperties.artistName, artist.toString());
|
|
||||||
pa.appendProperty(SBProperties.albumName, album.toString());
|
|
||||||
var items = list.getItemsByProperties(pa).enumerate();
|
|
||||||
|
|
||||||
while (items.hasMoreElements())
|
|
||||||
{
|
|
||||||
track = items.getNext().getProperty(SBProperties.trackName);
|
|
||||||
tracksArray[i] = [track, track];
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
return tracksArray;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user