diff --git a/src/database/updater/DatabaseFeatureExtractor.cpp b/src/database/updater/DatabaseFeatureExtractor.cpp deleted file mode 100644 index 1052c6cc..00000000 --- a/src/database/updater/DatabaseFeatureExtractor.cpp +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (C) 2016 Emeric Poupon - * - * This file is part of LMS. - * - * LMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LMS. If not, see . - */ - -#include "database/Setting.hpp" - -#include "feature/FeatureExtractor.hpp" -#include "feature/FeatureStore.hpp" - -#include "utils/Logger.hpp" - -#include "DatabaseFeatureExtractor.hpp" - -namespace Database { - -static std::string getMBID(Track::id_type trackId) -{ - Wt::Dbo::Transaction transaction(UpdaterDboSession()); - Track::pointer track = Track::getById(UpdaterDboSession(), trackId); - return track->getMBID(); -} - -void -FeatureExtractor::handleFilesUpdated(void) -{ - bool fetchHighLevel = Setting::getBool(UpdaterDboSession(), "tags_highlevel_acousticbrainz"); - bool fetchLowLevel = Setting::getBool(UpdaterDboSession(), "tags_similarity_acousticbrainz"); - - if (!fetchHighLevel && !fetchLowLevel) - { - LMS_LOG(DBUPDATER, INFO) << "No need to extract features"; - return; - } - - LMS_LOG(DBUPDATER, INFO) << "Processing tracks in order to extract features..."; - std::vector trackIds = Track::getAllIds(UpdaterDboSession()); - for (auto trackId : trackIds) - { - if (UpdaterQuitRequested()) - return; - - std::string mbid = getMBID(trackId); - if (mbid.empty()) - { - LMS_LOG(DBUPDATER, DEBUG) << "No MBID for track " << trackId << ", skipping"; - continue; - } - - if (fetchLowLevel && !Feature::Store::instance().exists(UpdaterDboSession(), trackId, "low_level")) - { - boost::property_tree::ptree feature; - if (::Feature::Extractor::getLowLevel(feature, mbid)) - Feature::Store::instance().set(UpdaterDboSession(), trackId, "low_level", feature); - } - - if (fetchHighLevel && !Feature::Store::instance().exists(UpdaterDboSession(), trackId, "high_level")) - { - boost::property_tree::ptree feature; - if (::Feature::Extractor::getHighLevel(feature, mbid)) - Feature::Store::instance().set(UpdaterDboSession(), trackId, "high_level", feature); - } - } - - LMS_LOG(DBUPDATER, INFO) << "Features have been extracted"; -} - -} // namespace Database - diff --git a/src/database/updater/DatabaseFeatureExtractor.hpp b/src/database/updater/DatabaseFeatureExtractor.hpp deleted file mode 100644 index c0ff092a..00000000 --- a/src/database/updater/DatabaseFeatureExtractor.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2016 Emeric Poupon - * - * This file is part of LMS. - * - * LMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LMS. If not, see . - */ - -#pragma once - -#include "DatabaseUpdater.hpp" - -namespace Database { - -class FeatureExtractor : public UpdaterEventHandler -{ - public: - void handleFilesUpdated(void); - -}; - -} // namespace Database diff --git a/src/database/updater/DatabaseHighLevelCluster.cpp b/src/database/updater/DatabaseHighLevelCluster.cpp deleted file mode 100644 index 5cc37607..00000000 --- a/src/database/updater/DatabaseHighLevelCluster.cpp +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Copyright (C) 2016 Emeric Poupon - * - * This file is part of LMS. - * - * LMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LMS. If not, see . - */ - -#include "database/Setting.hpp" -#include "feature/FeatureStore.hpp" - -#include "utils/Logger.hpp" - -#include "DatabaseHighLevelCluster.hpp" - -namespace Database { - -static Cluster::pointer getCluster(std::string type, std::string name) -{ - ClusterType::pointer clusterType = ClusterType::getByName(UpdaterDboSession(), type); - if (!clusterType) - clusterType = ClusterType::create(UpdaterDboSession(), type); - - auto cluster = clusterType->getCluster(name); - if (!cluster) - cluster = Cluster::create(UpdaterDboSession(), clusterType, name); - - return cluster; -} - -static std::list getClustersFromFeature(boost::property_tree::ptree& feature, double minProb) -{ - struct HighLevelNodeDesc - { - std::string node; - std::map valueMapping; - }; - - static const std::vector nodes = - { - { - "highlevel.danceability", - { - {"not_danceable", "Not danceable"}, - {"danceable", "Danceable"}, - }, - }, - { - "highlevel.gender", - { - {"male", "Male"}, - {"female", "Female"}, - }, - }, - { - "highlevel.mood_acoustic", - { - {"not_acoustic", "Not acoustic"}, - {"acoustic", "Acoustic"}, - }, - }, - { - "highlevel.mood_happy", - { - {"not_happy", "Not happy"}, - {"happy", "Happy"}, - }, - }, - { - "highlevel.mood_aggressive", - { - {"not_aggressive", "Not aggressive"}, - {"aggressive", "Aggressive"}, - }, - }, - { - "highlevel.mood_electronic", - { - {"not_electronic", "Not electronic"}, - {"electronic", "Electronic"}, - }, - }, - { - "highlevel.mood_party", - { - {"not_party", "Not party"}, - {"party", "Party"}, - }, - }, - { - "highlevel.mood_relaxed", - { - {"not_relaxed", "Not relaxed"}, - {"relaxed", "Relaxed"}, - }, - }, - { - "highlevel.mood_sad", - { - {"not_sad", "Not sad"}, - {"sad", "Sad"}, - }, - }, - { - "highlevel.timbre", - { - {"bright", "Bright"}, - {"dark", "Dark"}, - }, - }, - { - "highlevel.tonal_atonal", - { - {"atonal", "Atonal"}, - {"tonal", "Tonal"}, - }, - }, - { - "highlevel.voice_instrumental", - { - {"instrumental", "Instrumental"}, - {"voice", "Voice"}, - }, - }, - }; - - - // Extract info and build clusters - std::list newClusterNames; - - for (auto node : nodes) - { - auto value = feature.get_child_optional(node.node + ".value"); - auto probability = feature.get_child_optional(node.node + ".probability"); - - if (!probability || !value) - { - LMS_LOG(DBUPDATER, ERROR) << "Missing " << node.node; - continue; - } - - if (std::stod(probability->data()) < minProb) - continue; - - if (node.valueMapping[value->data()] == "") - { - LMS_LOG(DBUPDATER, ERROR) << "Unknown value '" << value->data() << "'"; - continue; - } - - newClusterNames.push_back(node.valueMapping[value->data()]); - } - - return newClusterNames; -} - -void -HighLevelCluster::handleFilesUpdated(void) -{ - bool createTags = Setting::getBool(UpdaterDboSession(), "tags_highlevel_acousticbrainz", false); - double minProb = Setting::getInt(UpdaterDboSession(), "tags_highlevel_acousticbrainz_min_probability", false) / 100.; - - LMS_LOG(DBUPDATER, INFO) << "Creating high level based clusters..."; - - std::vector trackIds = Track::getAllIds(UpdaterDboSession()); - - LMS_LOG(DBUPDATER, DEBUG) << "Got " << trackIds.size() << " tracks"; - for (auto trackId : trackIds) - { - if (UpdaterQuitRequested()) - return; - - // Get current cluster names - std::list newClusterNames; - if (createTags) - { - boost::property_tree::ptree feature; - if (!Feature::Store::instance().get(UpdaterDboSession(), trackId, "high_level", feature)) - continue; - - newClusterNames = getClustersFromFeature(feature, minProb); - } - - Wt::Dbo::Transaction transaction(UpdaterDboSession()); - - auto track = Track::getById(UpdaterDboSession(), trackId); - - auto clusters = track->getClusters(); - for (auto cluster : clusters) - { - // Check if removed - if (cluster->getType()->getName() != "high_level") - continue; - - auto it = std::find(newClusterNames.begin(), newClusterNames.end(), cluster->getName()); - if (it == newClusterNames.end()) - cluster.remove(); - else - newClusterNames.erase(it); - - } - - // Add previsouly missing clusters - for (auto newName : newClusterNames) - { - auto cluster = getCluster("high_level", newName); - cluster.modify()->addTrack(track); - } - } - - LMS_LOG(DBUPDATER, INFO) << "High level based clusters processed"; -} - - -} // namespace Database diff --git a/src/database/updater/DatabaseHighLevelCluster.hpp b/src/database/updater/DatabaseHighLevelCluster.hpp deleted file mode 100644 index 20adb3a8..00000000 --- a/src/database/updater/DatabaseHighLevelCluster.hpp +++ /dev/null @@ -1,33 +0,0 @@ -/* - * Copyright (C) 2016 Emeric Poupon - * - * This file is part of LMS. - * - * LMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LMS. If not, see . - */ - -#pragma once - -#include "DatabaseUpdater.hpp" - -namespace Database { - -class HighLevelCluster : public UpdaterEventHandler -{ - public: - void handleFilesUpdated(void); - -}; - -} // namespace Database