1 /* 2 * Copyright (C) 2018 Emeric Poupon 3 * 4 * This file is part of LMS. 5 * 6 * LMS is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * LMS is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with LMS. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #pragma once 21 22 #include <unordered_set> 23 24 #include <Wt/Dbo/Dbo.h> 25 #include <Wt/WTime.h> 26 27 #include "utils/Path.hpp" 28 29 namespace Database { 30 31 class ClusterType; 32 class Session; 33 34 class ScanSettings : public Wt::Dbo::Dbo<ScanSettings> 35 { 36 public: 37 using pointer = Wt::Dbo::ptr<ScanSettings>; 38 39 // Do not modify values (just add) 40 enum class UpdatePeriod { 41 Never = 0, 42 Daily, 43 Weekly, 44 Monthly, 45 Hourly, 46 }; 47 48 // Do not modify values (just add) 49 enum class RecommendationEngineType 50 { 51 Clusters = 0, 52 Features, 53 }; 54 55 static void init(Session& session); 56 57 static pointer get(Session& session); 58 59 // Getters getScanVersion() const60 std::size_t getScanVersion() const { return _scanVersion; } getMediaDirectory() const61 std::filesystem::path getMediaDirectory() const { return _mediaDirectory; } getUpdateStartTime() const62 Wt::WTime getUpdateStartTime() const { return _startTime; } getUpdatePeriod() const63 UpdatePeriod getUpdatePeriod() const { return _updatePeriod; } 64 std::vector<Wt::Dbo::ptr<ClusterType>> getClusterTypes() const; 65 std::unordered_set<std::filesystem::path> getAudioFileExtensions() const; getRecommendationEngineType() const66 RecommendationEngineType getRecommendationEngineType() const { return _recommendationEngineType; } 67 68 // Setters 69 void addAudioFileExtension(const std::filesystem::path& ext); 70 void setMediaDirectory(const std::filesystem::path& p); setUpdateStartTime(Wt::WTime t)71 void setUpdateStartTime(Wt::WTime t) { _startTime = t; } setUpdatePeriod(UpdatePeriod p)72 void setUpdatePeriod(UpdatePeriod p) { _updatePeriod = p; } 73 void setClusterTypes(Session& session, const std::set<std::string>& clusterTypeNames); setRecommendationEngineType(RecommendationEngineType type)74 void setRecommendationEngineType(RecommendationEngineType type) { _recommendationEngineType = type; } 75 void incScanVersion(); 76 77 template<class Action> persist(Action & a)78 void persist(Action& a) 79 { 80 Wt::Dbo::field(a, _scanVersion, "scan_version"); 81 Wt::Dbo::field(a, _mediaDirectory, "media_directory"); 82 Wt::Dbo::field(a, _startTime, "start_time"); 83 Wt::Dbo::field(a, _updatePeriod, "update_period"); 84 Wt::Dbo::field(a, _audioFileExtensions, "audio_file_extensions"); 85 Wt::Dbo::field(a, _recommendationEngineType,"similarity_engine_type"); 86 Wt::Dbo::hasMany(a, _clusterTypes, Wt::Dbo::ManyToOne, "scan_settings"); 87 } 88 89 private: 90 91 int _scanVersion {}; 92 std::string _mediaDirectory; 93 Wt::WTime _startTime = Wt::WTime {0,0,0}; 94 UpdatePeriod _updatePeriod {UpdatePeriod::Never}; 95 RecommendationEngineType _recommendationEngineType {RecommendationEngineType::Clusters}; 96 std::string _audioFileExtensions {".alac .mp3 .ogg .oga .aac .m4a .m4b .flac .wav .wma .aif .aiff .ape .mpc .shn .opus"}; 97 Wt::Dbo::collection<Wt::Dbo::ptr<ClusterType>> _clusterTypes; 98 }; 99 100 101 } // namespace Database 102 103