Nightingale Forums

Full Version: reset Play count
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
How do you reset the play count in nightingale 1.12.1 ?
I'm not aware of a direct way to do so in the graphical user interface.

Thus, you can either write an add-on wiping the play count (have a look at RatingFile's source code, it uses the same APIs), use RatingFile to back your ratings and play/skip counts up, then edit the resulting file (it is a regular text file, any editor with a search-replace feature should work), and import it again, or directly modify the sqlite database located in your profile's 'db' folder.

Did that already help you? If not, what OS are you on (windows / linux / mac)?
(10-21-2015, 12:18 AM)rsjtdrjgfuzkfg Wrote: [ -> ]I'm not aware of a direct way to do so in the graphical user interface.

Thus, you can either write an add-on wiping the play count (have a look at RatingFile's source code, it uses the same APIs), use RatingFile to back your ratings and play/skip counts up, then edit the resulting file (it is a regular text file, any editor with a search-replace feature should work), and import it again, or directly modify the sqlite database located in your profile's 'db' folder.

Did that already help you? If not, what OS are you on (windows / linux / mac)?

Hi
I am on Linux

I had a quick look at the db with sql lite but I could not see the field for play counts and the db did not seem to contain enough entries for the amount of files I have

do you know the details of the db ?

cheers
Warning: Long answer. Read till the end (or only the end for that matter) to get a reasonable solution to reset play counts.

(10-21-2015, 05:40 PM)tonyd Wrote: [ -> ]I had a quick look at the db with sql lite but I could not see the field for play counts and the db did not seem to contain enough entries for the amount of files I have

do you know the details of the db ?

First of all, did you open the database of your main library? You are most likely interested in ~/.nightingale/XXXXXXXX.default/db/main@library.songbirdnest.com.db

To get the play counts, first determine the property_id of play counts in your database (through the table properties), then update the play counts themselves in the resource_properties table. In theory, the following should work:
Code:
UPDATE resource_properties SET obj = '0', obj_searchable = '+0000000000000000000', obj_sortable = '+0000000000000000000' WHERE property_id = (SELECT property_id FROM properties WHERE property_name = 'http://songbirdnest.com/data/1.0#playCount');
The issue is, that the sqlite command line interface does not know about Nightingale's collation types, and thus would respond to the above query with "Error: no such collation sequence: library_collate". Sorry, I did not think about that when suggesting performing the change on a db-level.

It would, in theory, be possible to build only the collation type into a library and load it via ".load", but the collation type is dependent on the whole localization code (as it is dependent on Nightingale's current locale, see components/dbengine/src/DatabaseEngine.cpp), and must not be changed without issuing a migration step, so using a quick and dirty fixed-locale collation might break indices for libraries not created in that locale. I think it would be possible to force collation migration to simple c-style comparasions when switching localeCollationEnabled on the DatabaseEngine to false, however I have not verified that, so don't blindly assume that works (and you'd still need to build a collation library for the sqlite cli).

You can, however execute SQL directly through Nightingale. To reset play counts, back your profile up (as you should when messing with the internals of your library), and execute the following in the error console (tools menu, copy-paste in the small text field and hit evaluate) After "Done. Remember to immediately restart Nightingale" is printed, restart Nightingale without doing anything else, as caches might be outdated. After you restarted, your play counts are all resetted:
Code:
var dbq = Components.classes["@songbirdnest.com/Songbird/DatabaseQuery;1"].createInstance(Components.interfaces.sbIDatabaseQuery);
dbq.setDatabaseGUID("main@library.songbirdnest.com");
dbq.addQuery("UPDATE resource_properties SET obj = '0', obj_searchable = '+0000000000000000000', obj_sortable = '+0000000000000000000' WHERE property_id = (SELECT property_id FROM properties WHERE property_name = 'http://songbirdnest.com/data/1.0#playCount');");
dbq.execute();
dbq.waitForCompletion();
"Done. Remember to immediately restart Nightingale!"


So much about the database, but read on for a better alternative I have not thought of before: instead of writing an add-on properly resetting the play counts, you can also do so through the error console: main advantage is that you do not run into caching issues, and this works independently of the structure of the database:
Code:
Components.utils.import("resource://app/jsmodules/sbProperties.jsm");
var sbILibraryManager = Components.classes["@songbirdnest.com/Songbird/library/Manager;1"].getService(Components.interfaces.sbILibraryManager);
var mainLibrary = sbILibraryManager.mainLibrary.QueryInterface(Components.interfaces.sbIMediaList);
for (var i = 0; i < mainLibrary.length; i++) {
  var item = mainLibrary.getItemByIndex(i);
  if (item.getProperty(SBProperties.isReadOnly) || item.getProperty(SBProperties.trackName) === null) {
    continue;
  }
  item.setProperty(SBProperties.playCount, 0);
}
"Done."
This is probably the best way.