Subsonic API: added bitDepth, samplingRate and channelCount, see https://github.com/opensubsonic/open-subsonic-api/pull/83
This commit is contained in:
@@ -34,7 +34,7 @@ namespace lms::db
|
||||
{
|
||||
namespace
|
||||
{
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 55 };
|
||||
static constexpr Version LMS_DATABASE_VERSION{ 56 };
|
||||
}
|
||||
|
||||
VersionInfo::VersionInfo()
|
||||
@@ -441,6 +441,16 @@ SELECT
|
||||
session.getDboSession()->execute("UPDATE scan_settings SET scan_version = scan_version + 1");
|
||||
}
|
||||
|
||||
void migrateFromV55(Session& session)
|
||||
{
|
||||
// Add bitsPerSample, channelCount and sampleRate
|
||||
session.getDboSession()->execute("ALTER TABLE track ADD bits_per_sample INTEGER NOT NULL DEFAULT(0)");
|
||||
session.getDboSession()->execute("ALTER TABLE track ADD channel_count INTEGER NOT NULL DEFAULT(0)");
|
||||
session.getDboSession()->execute("ALTER TABLE track ADD sample_rate INTEGER NOT NULL DEFAULT(0)");
|
||||
|
||||
// Just increment the scan version of the settings to make the next scheduled scan rescan everything
|
||||
session.getDboSession()->execute("UPDATE scan_settings SET scan_version = scan_version + 1");
|
||||
}
|
||||
|
||||
void doDbMigration(Session& session)
|
||||
{
|
||||
@@ -474,6 +484,7 @@ SELECT
|
||||
{52, migrateFromV52},
|
||||
{53, migrateFromV53},
|
||||
{54, migrateFromV54},
|
||||
{55, migrateFromV55},
|
||||
};
|
||||
|
||||
{
|
||||
|
||||
@@ -133,10 +133,13 @@ namespace lms::db
|
||||
void setAbsoluteFilePath(const std::filesystem::path& filePath);
|
||||
void setRelativeFilePath(const std::filesystem::path& filePath);
|
||||
void setFileSize(std::size_t fileSize) { _fileSize = fileSize; }
|
||||
void setDuration(std::chrono::milliseconds duration) { _duration = duration; }
|
||||
void setBitrate(std::size_t bitrate) { _bitrate = bitrate; }
|
||||
void setLastWriteTime(Wt::WDateTime time) { _fileLastWrite = time; }
|
||||
void setAddedTime(Wt::WDateTime time) { _fileAdded = time; }
|
||||
void setBitrate(std::size_t bitrate) { _bitrate = bitrate; }
|
||||
void setBitsPerSample(std::size_t bitsPerSample) { _bitsPerSample = bitsPerSample; }
|
||||
void setDuration(std::chrono::milliseconds duration) { _duration = duration; }
|
||||
void setChannelCount(std::size_t channelCount) { _channelCount = channelCount; }
|
||||
void setSampleRate(std::size_t channelCount) { _sampleRate = channelCount; }
|
||||
void setDate(const Wt::WDate& date) { _date = date; }
|
||||
void setYear(std::optional<int> year) { _year = year; }
|
||||
void setOriginalDate(const Wt::WDate& date) { _originalDate = date; }
|
||||
@@ -164,8 +167,11 @@ namespace lms::db
|
||||
const std::filesystem::path& getAbsoluteFilePath() const { return _absoluteFilePath; }
|
||||
const std::filesystem::path& getRelativeFilePath() const { return _relativeFilePath; }
|
||||
long long getFileSize() const { return _fileSize; }
|
||||
std::chrono::milliseconds getDuration() const { return _duration; }
|
||||
std::size_t getBitrate() const { return _bitrate; }
|
||||
std::size_t getBitsPerSample() const { return _bitsPerSample; }
|
||||
std::size_t getChannelCount() const { return _channelCount; }
|
||||
std::chrono::milliseconds getDuration() const { return _duration; }
|
||||
std::size_t getSampleRate() const { return _sampleRate; }
|
||||
const Wt::WDateTime& getLastWritten() const { return _fileLastWrite; }
|
||||
const Wt::WDate& getDate() const { return _date; }
|
||||
std::optional<int> getYear() const { return _year; }
|
||||
@@ -203,6 +209,9 @@ namespace lms::db
|
||||
Wt::Dbo::field(a, _name, "name");
|
||||
Wt::Dbo::field(a, _duration, "duration");
|
||||
Wt::Dbo::field(a, _bitrate, "bitrate");
|
||||
Wt::Dbo::field(a, _bitsPerSample, "bits_per_sample");
|
||||
Wt::Dbo::field(a, _channelCount, "channel_count");
|
||||
Wt::Dbo::field(a, _sampleRate, "sample_rate");
|
||||
Wt::Dbo::field(a, _date, "date");
|
||||
Wt::Dbo::field(a, _year, "year");
|
||||
Wt::Dbo::field(a, _originalDate, "original_date");
|
||||
@@ -240,8 +249,11 @@ namespace lms::db
|
||||
std::optional<int> _totalTrack{};
|
||||
std::string _discSubtitle;
|
||||
std::string _name;
|
||||
std::chrono::duration<int, std::milli> _duration{};
|
||||
int _bitrate{}; // in bps
|
||||
int _bitsPerSample{};
|
||||
int _channelCount{};
|
||||
std::chrono::duration<int, std::milli> _duration{};
|
||||
int _sampleRate{};
|
||||
Wt::WDate _date;
|
||||
std::optional<int> _year;
|
||||
Wt::WDate _originalDate;
|
||||
|
||||
@@ -342,4 +342,28 @@ namespace lms::db::tests
|
||||
EXPECT_EQ(track->getRelativeFilePath(), "foo/file.path");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST_F(DatabaseFixture, Track_audioProperties)
|
||||
{
|
||||
ScopedTrack track{ session };
|
||||
|
||||
{
|
||||
auto transaction{ session.createWriteTransaction() };
|
||||
track.get().modify()->setBitrate(128000);
|
||||
track.get().modify()->setBitsPerSample(16);
|
||||
track.get().modify()->setDuration(std::chrono::minutes{ 3 });
|
||||
track.get().modify()->setChannelCount(2);
|
||||
track.get().modify()->setSampleRate(44100);
|
||||
}
|
||||
|
||||
{
|
||||
auto transaction{ session.createReadTransaction() };
|
||||
EXPECT_EQ(track->getBitrate(), 128000);
|
||||
EXPECT_EQ(track->getBitsPerSample(), 16);
|
||||
EXPECT_EQ(track->getDuration(), std::chrono::minutes{ 3 });
|
||||
EXPECT_EQ(track->getChannelCount(), 2);
|
||||
EXPECT_EQ(track->getSampleRate(), 44100);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user