Skip to content

Commit

Permalink
Add lowercase fields for database (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
martpie committed Mar 1, 2016
1 parent 56f6cb6 commit 8d747e0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
23 changes: 17 additions & 6 deletions src/js/actions/LibraryActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const dialog = electron.remote.dialog;
export default {

refreshTracks: function() {
app.db.find({}).sort({ 'lArtist': 1, 'year': 1, 'album': 1, 'disk': 1, 'track.no': 1 }).exec(function (err, tracks) {
app.db.find({}).sort({ 'loweredMetas.artist': 1, 'year': 1, 'loweredMetas.album': 1, 'disk.no': 1, 'track.no': 1 }).exec(function (err, tracks) {
if (err) throw err;
else {
AppDispatcher.dispatch({
Expand Down Expand Up @@ -127,19 +127,30 @@ export default {
forloop(i + 1);
if(err) console.warn('An error occured while reading ' + file + ' id3 tags: ' + err);

delete metadata.picture;

fs.realpath(file, (err, realpath) => {

if(err) console.warn(err);

metadata.path = realpath
metadata.lArtist = metadata.artist.length === 0 ? ['unknown artist'] : metadata.artist[0].toLowerCase();
// We don't want it
delete metadata.picture;

// File path
metadata.path = realpath;

// Unknown metas
if(metadata.artist.length === 0) metadata.artist = ['Unknown artist'];
if(metadata.album === null || metadata.album === '') metadata.album = 'Unknown';
if(metadata.title === null || metadata.title === '') metadata.title = path.parse(file).base;
if(metadata.duration == '') metadata.duration = 0;
if(metadata.duration == '') metadata.duration = 0; // .wav problem

// Formated metas for sorting
metadata.loweredMetas = {
artist : metadata.artist.map(meta => meta.toLowerCase()),
album : metadata.album.toLowerCase(),
albumartist : metadata.albumartist.map(meta => meta.toLowerCase()),
title : metadata.title.toLowerCase(),
genre : metadata.genre.map(meta => meta.toLowerCase())
}

app.db.find({ path: metadata.path }, function (err, docs) {
if(err) console.warn(err);
Expand Down
9 changes: 5 additions & 4 deletions src/js/stores/AppStore.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ var AppStore = objectAssign({}, EventEmitter.prototype, {
oldPlaylist : null, // Playlist backup
oldPlaylistCursor : null, // The last cursor backup (to roll stuff back, e.g. unshuffle)
playerStatus : 'stop', // Player status
notifications : [], // The array of notifications
notifications : [], // The array of notifications
refreshingLibrary : false, // If the app is currently refreshing the app
repeat : false, // the current repeat state (one, all, false)
shuffle : false, // If shuffle mode is enabled
refreshProgress : 0, // Progress of the refreshing library
refreshProgress : 0, // Progress of the refreshing library

getStore: function() {
return {
Expand Down Expand Up @@ -70,6 +70,7 @@ var AppStore = objectAssign({}, EventEmitter.prototype, {
export default AppStore;



/*
|--------------------------------------------------------------------------
| Dispatcher Listener
Expand Down Expand Up @@ -149,9 +150,9 @@ AppDispatcher.register(function(payload) {

if(search != '' && search != undefined) {

if(track.lArtist.indexOf(search) === -1
if(track.loweredMetas.artist.join(', ').indexOf(search) === -1
&& track.album.toLowerCase().indexOf(search) === -1
&& track.genre.join(', ').toLowerCase().indexOf(search) === -1
&& track.loweredMetas.genre.join(', ').toLowerCase().indexOf(search) === -1
&& track.title.toLowerCase().indexOf(search) === -1) {

continue;
Expand Down

0 comments on commit 8d747e0

Please sign in to comment.