33 Components.utils.import(
"resource://app/jsmodules/sbProperties.jsm");
51 var
file = Components.classes[
"@mozilla.org/file/local;1"]
52 .createInstance(Components.interfaces.nsILocalFile);
53 file.initWithPath(
"/builds/songbird/trunk/big.txt");
56 var fstream =
Cc[
"@mozilla.org/network/file-input-stream;1"]
57 .createInstance(
Ci.nsIFileInputStream);
58 var sstream =
Cc[
"@mozilla.org/scriptableinputstream;1"]
59 .createInstance(
Ci.nsIScriptableInputStream);
60 fstream.init(file, -1, 0, 0);
61 sstream.init(fstream);
63 var
str = sstream.read(4096);
64 while (str.length > 0) {
66 str = sstream.read(4096);
72 var
uris =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(
Ci.nsIMutableArray);
73 var properties =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(
Ci.nsIMutableArray);
75 var a = data.split(
"\n");
76 for (var
i = 0;
i < a.length &&
i < aLength;
i++) {
78 var pa = SBProperties.createArray();
79 var b = a[
i].split(
"\t");
82 if (artist && artist.length) {
83 pa.appendProperty(SBProperties.artistName, artist);
86 var album = (b[3] ==
"" ?
"" : b[3] +
" ") + b[2];
87 if (album && album.length) {
88 pa.appendProperty(SBProperties.albumName, album);
92 if (genre && genre.length) {
93 pa.appendProperty(SBProperties.genre, genre);
96 var
year = b[5].length > 3 ? parseInt(b[5].substr(0, 4)) :
null;
97 if (year && !isNaN(year)) {
99 pa.appendProperty(SBProperties.year, year);
106 var track = (b[8] ==
"" ?
"" : b[8] +
" ") + b[6];
108 pa.appendProperty(SBProperties.trackName, track);
111 var trackNumber = parseInt(b[7]);
112 if (!isNaN(trackNumber)) {
113 pa.appendProperty(SBProperties.trackNumber, trackNumber);
117 var c = b[9].split(
":");
119 length = (c[0] * 60) + c[1];
120 pa.appendProperty(SBProperties.duration, length);
123 var
uri =
newURI(
"file:///foo/" + escape(artist) +
"-" +
124 escape(album) +
"-" + escape(track) +
".mp3");
125 uris.appendElement(uri,
false);
126 properties.appendElement(pa,
false);
137 if (
i > 0 && (
i + 1) % 1000 == 0) {
138 library.batchCreateMediaItems(uris, properties,
true);
139 dump(
"loading " +
i +
" a.length " + a.length +
" length + " + aLength +
"\n");
140 var uris =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(
Ci.nsIMutableArray);
141 var properties =
Cc[
"@songbirdnest.com/moz/xpcom/threadsafe-array;1"].createInstance(
Ci.nsIMutableArray);
154 if (databaseLocation) {
155 directory = databaseLocation.QueryInterface(
Ci.nsIFileURL).file;
158 directory =
Cc[
"@mozilla.org/file/directory_service;1"].
160 get(
"ProfD",
Ci.nsIFile);
161 directory.append(
"db");
164 var
file = directory.clone();
165 file.append(databaseGuid +
".db");
168 Cc[
"@songbirdnest.com/Songbird/Library/LocalDatabase/LibraryFactory;1"]
169 .getService(
Ci.sbILibraryFactory);
170 var hashBag =
Cc[
"@mozilla.org/hash-property-bag;1"].
172 hashBag.setPropertyAsInterface(
"databaseFile", file);
173 var library = libraryFactory.createLibrary(hashBag);
function makeLibrary(aLength)
function runTest()
Hack script to load a songbird library from a preformatted text file.
getService(Ci.sbIFaceplateManager)
var getService(Components.interfaces.nsIWindowMediator).getMostRecentWindow('Songbird SBProperties artist
function createLibrary(databaseGuid, databaseLocation)
function newURI(aURLString)
_getSelectedPageStyle s i