Added the ability to limit indexed files by duration.

This commit is contained in:
casey langen 2019-01-06 16:59:49 -08:00
parent df9bc32621
commit 136c681ef3
3 changed files with 24 additions and 2 deletions

View File

@ -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;
}

View File

@ -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<std::string> 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;
}

View File

@ -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;