OpenSubsonic: changed the originalReleaseDate field format, fixes #400
This commit is contained in:
@@ -333,26 +333,22 @@ namespace MetaData
|
||||
}
|
||||
else if (tag == "DATE")
|
||||
{
|
||||
// Higher priority than YEAR
|
||||
if (const Wt::WDate date{ Utils::parseDate(value) }; date.isValid())
|
||||
track.date = date;
|
||||
else if (!track.year)
|
||||
track.year = StringUtils::readAs<int>(value);
|
||||
}
|
||||
else if (tag == "YEAR" && !track.date.isValid())
|
||||
{
|
||||
// lower priority than DATE
|
||||
track.date = Utils::parseDate(value);
|
||||
}
|
||||
else if (tag == "YEAR")
|
||||
track.year = StringUtils::readAs<int>(value);
|
||||
else if (tag == "ORIGINALDATE")
|
||||
{
|
||||
// Higher priority than ORIGINALYEAR
|
||||
if (const Wt::WDate date{ Utils::parseDate(value) }; date.isValid())
|
||||
track.originalDate = date;
|
||||
else if (!track.originalYear)
|
||||
track.originalYear = StringUtils::readAs<int>(value);
|
||||
}
|
||||
else if (tag == "ORIGINALYEAR" && !track.originalDate.isValid())
|
||||
{
|
||||
// Lower priority than ORIGINALDATE
|
||||
track.originalDate = Utils::parseDate(value);
|
||||
}
|
||||
else if (tag == "ORIGINALYEAR")
|
||||
track.originalYear = StringUtils::readAs<int>(value);
|
||||
else if (tag == "METADATA_BLOCK_PICTURE")
|
||||
track.hasCover = true;
|
||||
else if (tag == "COPYRIGHT")
|
||||
@@ -510,6 +506,14 @@ namespace MetaData
|
||||
for (const auto& [tag, values] : tags)
|
||||
processTag(track, tag, values, debug);
|
||||
|
||||
// If a file has date but no year, set it
|
||||
if (!track.year && track.date.isValid())
|
||||
track.year = track.date.year();
|
||||
|
||||
// If a file has originalDate but no originalYear, set it
|
||||
if (!track.originalYear && track.originalDate.isValid())
|
||||
track.originalYear = track.originalDate.year();
|
||||
|
||||
return track;
|
||||
}
|
||||
|
||||
|
||||
@@ -37,17 +37,23 @@ namespace MetaData::Utils
|
||||
|
||||
for (const char* format : formats)
|
||||
{
|
||||
std::tm tm = {};
|
||||
std::tm tm{};
|
||||
tm.tm_mon = -1;
|
||||
tm.tm_mday = -1;
|
||||
|
||||
std::istringstream ss{ std::string {dateStr} }; // TODO, remove extra copy here
|
||||
ss >> std::get_time(&tm, format);
|
||||
if (ss.fail())
|
||||
continue;
|
||||
|
||||
if (tm.tm_mday <= 0 || tm.tm_mon < 0)
|
||||
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]
|
||||
tm.tm_year + 1900, // tm.tm_year: years since 1900
|
||||
tm.tm_mon + 1, // tm.tm_mon: months since January – [00, 11]
|
||||
tm.tm_mday // tm.tm_mday: day of the month – [1, 31]
|
||||
};
|
||||
if (!res.isValid())
|
||||
continue;
|
||||
|
||||
Reference in New Issue
Block a user