mirror of
https://github.com/clangen/musikcube.git
synced 2025-01-01 00:19:20 +00:00
Fixed directory browsing with respect to custom indexer source plugins.
This commit is contained in:
parent
e1c44404e4
commit
1e8f14430e
@ -845,7 +845,16 @@ bool IndexerTrack::Save(db::Connection &dbConnection, std::string libraryDirecto
|
||||
}
|
||||
|
||||
ProcessNonStandardMetadata(dbConnection);
|
||||
SaveDirectory(dbConnection, this->GetString("filename"));
|
||||
|
||||
/* sometimes indexer source plugins save the 'filename' field with a custom
|
||||
encoded URI. in these cases the plugin can populate a 'directory' field
|
||||
with the actual directory, if one exists. otherwise, we'll just extract
|
||||
the directory from the 'filename'. */
|
||||
std::string path = this->GetString("directory").size() ?
|
||||
this->GetString("directory") : this->GetString("filename");
|
||||
|
||||
SaveDirectory(dbConnection, path);
|
||||
|
||||
SaveReplayGain(dbConnection);
|
||||
|
||||
return true;
|
||||
|
@ -119,6 +119,21 @@ namespace musik { namespace core { namespace sdk { namespace fs {
|
||||
return "";
|
||||
}
|
||||
|
||||
template <typename String=std::string>
|
||||
static inline std::string getDirectory(const String& filename) {
|
||||
std::string canonicalized = canonicalizePath(filename);
|
||||
#ifdef WIN32
|
||||
size_t pos = canonicalized.find_last_of("\\");
|
||||
#else
|
||||
size_t pos = canonicalized.find_last_of("/");
|
||||
#endif
|
||||
if (pos != std::string::npos) {
|
||||
std::string result = canonicalized.substr(0, pos + 1);
|
||||
return result;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
template <typename String=std::string>
|
||||
void scanDirectory(
|
||||
const std::string& path,
|
||||
|
@ -182,6 +182,8 @@ void GmeIndexerSource::UpdateMetadata(
|
||||
KEY_DEFAULT_TRACK_LENGTH,
|
||||
DEFAULT_TRACK_LENGTH));
|
||||
|
||||
const std::string directory = fs::getDirectory<std::string>(fn);
|
||||
|
||||
for (int i = 0; i < gme_track_count(data); i++) {
|
||||
const std::string externalId = indexer::createExternalId(EXTERNAL_ID_PREFIX, fn, i);
|
||||
const std::string trackNum = std::to_string(i + 1);
|
||||
@ -190,6 +192,7 @@ void GmeIndexerSource::UpdateMetadata(
|
||||
|
||||
auto track = indexer->CreateWriter();
|
||||
track->SetValue("filename", externalId.c_str());
|
||||
track->SetValue("directory", directory.c_str());
|
||||
track->SetValue("filetime", modifiedTimeStr.c_str());
|
||||
track->SetValue("track", trackNum.c_str());
|
||||
|
||||
|
@ -166,6 +166,7 @@ void OpenMptIndexerSource::UpdateMetadata(
|
||||
nullptr, nullptr, nullptr, nullptr, nullptr);
|
||||
|
||||
if (module) {
|
||||
std::string directory = fs::getDirectory(std::string(fn));
|
||||
size_t count = openmpt_module_get_num_subsongs(module);
|
||||
const char* keys = openmpt_module_get_metadata_keys(module);
|
||||
if (count > 0) {
|
||||
@ -179,6 +180,9 @@ void OpenMptIndexerSource::UpdateMetadata(
|
||||
std::string album = readMetadataValue(module, "container_long");
|
||||
if (!album.size()) {
|
||||
album = readMetadataValue(module, "container").c_str();
|
||||
if (!album.size()) {
|
||||
album = "[unknown mod album]";
|
||||
}
|
||||
}
|
||||
|
||||
std::string title = readMetadataValue(module, "title");
|
||||
@ -191,10 +195,12 @@ void OpenMptIndexerSource::UpdateMetadata(
|
||||
artist = "[unknown mod artist]";
|
||||
}
|
||||
|
||||
const std::string duration = std::to_string(openmpt_module_get_duration_seconds(module));
|
||||
const std::string duration = std::to_string(
|
||||
openmpt_module_get_duration_seconds(module));
|
||||
|
||||
auto track = indexer->CreateWriter();
|
||||
track->SetValue("filename", externalId.c_str());
|
||||
track->SetValue("directory", directory.c_str());
|
||||
track->SetValue("filetime", modifiedTimeStr.c_str());
|
||||
track->SetValue("track", trackNum.c_str());
|
||||
track->SetValue("album", album.c_str());
|
||||
|
Loading…
Reference in New Issue
Block a user