Use ENCODINGTIME to set the added time, if present, otherwise use the last modified time of the file (only during the first import), fixes #595

This commit is contained in:
emeric
2025-01-18 16:51:31 +01:00
parent 5cfbbeca65
commit c73ff7dc03
11 changed files with 65 additions and 8 deletions
@@ -64,6 +64,7 @@ namespace lms::metadata
{ TagType::DiscNumber, { "TPOS", "DISC", "DISK", "DISCNUMBER", "WM/PARTOFSET" } },
{ TagType::DiscSubtitle, { "TSST", "DISCSUBTITLE", "SETSUBTITLE" } },
{ TagType::EncodedBy, { "ENCODEDBY" } },
{ TagType::EncodingTime, { "ENCODINGTIME", "TDEN" } },
{ TagType::Engineer, { "ENGINEER" } },
{ TagType::GaplessPlayback, { "GAPLESSPLAYBACK" } },
{ TagType::Genre, { "GENRE" } },
+1
View File
@@ -65,6 +65,7 @@ namespace lms::metadata
DiscSubtitle,
EncodedBy,
EncoderSettings,
EncodingTime,
Engineer,
GaplessPlayback,
Genre,
+8
View File
@@ -390,6 +390,14 @@ namespace lms::metadata
}
track.advisory = getAdvisory(tagReader);
if (const auto encodingTime{ getTagValueAs<std::string>(tagReader, TagType::EncodingTime) })
{
if (auto dateTime{ core::stringUtils::fromISO8601String(*encodingTime) }; dateTime.isValid())
track.encodingTime = dateTime;
else if (const Wt::WDate date{ utils::parseDate(*encodingTime) }; date.isValid())
track.encodingTime = Wt::WDateTime{ date };
}
track.lyrics = getLyrics(tagReader); // no custom delimiter on lyrics
track.comments = getTagValuesAs<std::string>(tagReader, TagType::Comment, {} /* no custom delimiter on comments */);
track.copyright = getTagValueAs<std::string>(tagReader, TagType::Copyright).value_or("");
@@ -96,6 +96,7 @@ namespace lms::metadata
{ TagType::DiscSubtitle, { "DISCSUBTITLE", "SETSUBTITLE" } },
{ TagType::EncodedBy, { "ENCODEDBY" } },
{ TagType::Engineer, { "ENGINEER" } },
{ TagType::EncodingTime, { "ENCODINGTIME" } },
{ TagType::GaplessPlayback, { "GAPLESSPLAYBACK" } },
{ TagType::Genre, { "GENRE" } },
{ TagType::Grouping, { "GROUPING", "ALBUMGROUPING" } },
@@ -27,6 +27,7 @@
#include <vector>
#include <Wt/WDate.h>
#include <Wt/WDateTime.h>
#include "core/UUID.hpp"
@@ -124,6 +125,7 @@ namespace lms::metadata
std::optional<int> originalYear{};
Wt::WDate originalDate;
std::optional<Advisory> advisory;
Wt::WDateTime encodingTime;
bool hasCover{};
std::optional<core::UUID> acoustID;
std::string copyright;
+24 -1
View File
@@ -17,11 +17,12 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#include <map>
#include <vector>
#include <gtest/gtest.h>
#include <Wt/WTime.h>
#include "Parser.hpp"
#include "TestTagReader.hpp"
@@ -611,4 +612,26 @@ namespace lms::metadata
doTest("", std::nullopt);
doTest("3", std::nullopt);
}
TEST(Parser, encodingTime)
{
auto doTest = [](std::string_view value, Wt::WDateTime expectedValue) {
const TestTagReader testTags{
{
{ TagType::EncodingTime, { value } },
}
};
Parser parser;
std::unique_ptr<Track> track{ Parser{}.parse(testTags) };
ASSERT_EQ(track->encodingTime, expectedValue) << "Value = '" << value << "'";
};
doTest("", Wt::WDateTime{});
doTest("foo", Wt::WDateTime{});
doTest("2020-01-03T09:08:11.075", Wt::WDateTime{ Wt::WDate{ 2020, 01, 03 }, Wt::WTime{ 9, 8, 11, 75 } });
doTest("2020-01-03", Wt::WDateTime{ Wt::WDate{ 2020, 01, 03 } });
doTest("2020/01/03", Wt::WDateTime{ Wt::WDate{ 2020, 01, 03 } });
}
} // namespace lms::metadata