Sort by release date, not just release year, fixes #128

This commit is contained in:
emeric
2021-09-23 13:18:43 +02:00
parent 7c649c82ce
commit 2ebc4280a0
21 changed files with 701 additions and 349 deletions
+3 -3
View File
@@ -25,7 +25,7 @@
#include "av/IAudioFile.hpp"
#include "utils/Logger.hpp"
#include "utils/String.hpp"
#include "Utils.hpp"
namespace MetaData
{
@@ -186,12 +186,12 @@ AvFormatParser::parse(const std::filesystem::path& p, bool debug)
|| tag == "YEAR"
|| tag == "WM/Year")
{
track.year = StringUtils::readAs<int>(value);
track.date = Utils::parseDate(value);
}
else if (tag == "TDOR" // Original release time (ID3v2 2.4)
|| tag == "TORY") // Original release year
{
track.originalYear = StringUtils::readAs<int>(value);
track.originalDate = Utils::parseDate(value);
}
else if (tag == "ACOUSTID ID")
{
+19 -11
View File
@@ -35,7 +35,7 @@
#include "utils/Logger.hpp"
#include "utils/String.hpp"
#include "Utils.hpp"
namespace MetaData
{
@@ -214,18 +214,26 @@ TagLibParser::processTag(Track& track, const std::string& tag, const TagLib::Str
}
}
else if (tag == "DATE")
track.year = StringUtils::readAs<int>(value);
else if (tag == "ORIGINALDATE" && !track.originalYear)
{
// Lower priority than ORIGINALYEAR
track.originalYear = StringUtils::readAs<int>(value);
// Higher priority than YEAR
if (const Wt::WDate date {Utils::parseDate(value)}; date.isValid())
track.date = date;
}
else if (tag == "ORIGINALYEAR")
else if (tag == "YEAR" && !track.date.isValid())
{
// Higher priority than ORIGINALDATE
auto originalYear = StringUtils::readAs<int>(value);
if (originalYear)
track.originalYear = originalYear;
// lower priority than DATE
track.date = Utils::parseDate(value);
}
else if (tag == "ORIGINALDATE")
{
// Higher priority than ORIGINALYEAR
if (const Wt::WDate date {Utils::parseDate(value)}; date.isValid())
track.originalDate = date;
}
else if (tag == "ORIGINALYEAR" && !track.originalDate.isValid())
{
// Lower priority than ORIGINALDATE
track.originalDate = Utils::parseDate(value);
}
else if (tag == "METADATA_BLOCK_PICTURE")
track.hasCover = true;
@@ -260,7 +268,7 @@ TagLibParser::parse(const std::filesystem::path& p, bool debug)
{
TagLib::FileRef f {p.string().c_str(),
true, // read audio properties
TagLib::AudioProperties::Fast};
TagLib::AudioProperties::Fast}; // TODO parametrize this
if (f.isNull())
{
+60
View File
@@ -0,0 +1,60 @@
/*
* Copyright (C) 2021 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 <http://www.gnu.org/licenses/>.
*/
#include "Utils.hpp"
#include <ctime>
#include <string_view>
#include <iomanip>
#include <sstream>
namespace MetaData::Utils
{
Wt::WDate
parseDate(const std::string& dateStr)
{
static constexpr const char* formats[]
{
"%Y-%m-%d",
"%Y/%m/%d",
};
for (const char* format : formats)
{
std::tm tm = {};
std::stringstream ss {dateStr};
ss >> std::get_time(&tm, format);
if (ss.fail())
continue;
const Wt::WDate res
{
tm.tm_year + 1900, // years since 1900
tm.tm_mon + 1, // months since January [0, 11]
tm.tm_mday ? tm.tm_mday : 1 // day of the month [1, 31]
};
if (!res.isValid())
continue;
return res;
}
return {};
}
}
+27
View File
@@ -0,0 +1,27 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#include <Wt/WDate.h>
namespace MetaData::Utils
{
Wt::WDate parseDate(const std::string& dateStr);
}