From 136c681ef3d08192e00f152fb990d6b988c21dd1 Mon Sep 17 00:00:00 2001 From: casey langen Date: Sun, 6 Jan 2019 16:59:49 -0800 Subject: [PATCH] Added the ability to limit indexed files by duration. --- src/core/library/Indexer.cpp | 10 ++++++++++ src/plugins/gmedecoder/Constants.h | 3 +++ src/plugins/gmedecoder/GmeIndexerSource.cpp | 13 +++++++++++-- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/core/library/Indexer.cpp b/src/core/library/Indexer.cpp index 29ab05798..c3405f54e 100644 --- a/src/core/library/Indexer.cpp +++ b/src/core/library/Indexer.cpp @@ -232,6 +232,16 @@ void Indexer::Synchronize(const SyncContext& context, boost::asio::io_service* i auto sourceId = context.sourceId; if (type == SyncType::Rebuild) { LocalLibrary::InvalidateTrackMetadata(this->dbConnection); + + /* for sources with stable ids: just nuke all of the records and allow + a rebuild from scratch; things like playlists will remain intact. + this ensures tracks that should be removed, are */ + for (auto source: sources) { + if (source->HasStableIds()) { + this->RemoveAll(source.get()); + } + } + type = SyncType::All; } diff --git a/src/plugins/gmedecoder/Constants.h b/src/plugins/gmedecoder/Constants.h index 09cdcbba1..db6fc9b53 100644 --- a/src/plugins/gmedecoder/Constants.h +++ b/src/plugins/gmedecoder/Constants.h @@ -65,6 +65,8 @@ static const char* KEY_TRACK_FADE_OUT_LENGTH = "track_fade_out_length_secs"; static const double DEFAULT_FADE_OUT_LENGTH = 3.0; static const char* KEY_ENABLE_M3U = "enable_m3u_support"; static const bool DEFAULT_ENABLE_M3U = false; +static const char* KEY_MINIMUM_TRACK_LENGTH = "minimum_track_length_secs"; +static const double DEFAULT_MINIMUM_TRACK_LENGTH = 0.0; static const std::set FORMATS = { ".vgm", ".gym", ".spc", ".sap", ".nsfe", @@ -99,6 +101,7 @@ static inline musik::core::sdk::ISchema* CreateSchema() { schema->AddBool(KEY_ALWAYS_LOOP_FOREVER, DEFAULT_ALWAYS_LOOP_FOREVER); schema->AddDouble(KEY_DEFAULT_TRACK_LENGTH, DEFAULT_TRACK_LENGTH); schema->AddDouble(KEY_TRACK_FADE_OUT_LENGTH, DEFAULT_FADE_OUT_LENGTH); + schema->AddDouble(KEY_MINIMUM_TRACK_LENGTH, DEFAULT_MINIMUM_TRACK_LENGTH); schema->AddBool(KEY_ENABLE_M3U, DEFAULT_ENABLE_M3U); return schema; } diff --git a/src/plugins/gmedecoder/GmeIndexerSource.cpp b/src/plugins/gmedecoder/GmeIndexerSource.cpp index 5b1944ab0..cb35e96d1 100644 --- a/src/plugins/gmedecoder/GmeIndexerSource.cpp +++ b/src/plugins/gmedecoder/GmeIndexerSource.cpp @@ -143,6 +143,9 @@ void GmeIndexerSource::UpdateMetadata( invalidFiles.insert(fn); } else { + double minTrackLength = prefs->GetDouble( + KEY_MINIMUM_TRACK_LENGTH, DEFAULT_MINIMUM_TRACK_LENGTH); + if (prefs->GetBool(KEY_ENABLE_M3U, DEFAULT_ENABLE_M3U)) { std::string m3u = getM3uFor(fn); if (m3u.size()) { @@ -177,6 +180,13 @@ void GmeIndexerSource::UpdateMetadata( track->SetValue("title", defaultTitle.c_str()); } else if (info) { + /* don't index tracks that are shorter than the specified minimum length. + this allows users to ignore things like sound effects */ + if (minTrackLength > 0.0 && info->length > 0 && info->length / 1000.0 < minTrackLength) { + gme_free_info(info); + continue; + } + std::string duration = (info->length == -1) ? defaultDuration : std::to_string((float) info->play_length / 1000.0f); @@ -187,10 +197,9 @@ void GmeIndexerSource::UpdateMetadata( track->SetValue("duration", duration.c_str()); track->SetValue("artist", strlen(info->author) ? info->author : info->system); track->SetValue("title", strlen(info->song) ? info->song : defaultTitle.c_str()); - - gme_free_info(info); } + gme_free_info(info); indexer->Save(source, track, externalId.c_str()); track->Release(); ++tracksIndexed;