Split the utils file
This commit is contained in:
+20
-16
@@ -19,10 +19,14 @@
|
||||
|
||||
#include "AvFormat.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <iostream>
|
||||
|
||||
#include "av/AvInfo.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
#include "utils/String.hpp"
|
||||
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
@@ -37,7 +41,7 @@ findFirstValueOfAs(const MetadataMap& metadataMap, std::initializer_list<std::st
|
||||
if (it == std::cend(metadataMap))
|
||||
return std::nullopt;
|
||||
|
||||
return readAs<T>(stringTrim(it->second));
|
||||
return StringUtils::readAs<T>(StringUtils::stringTrim(it->second));
|
||||
}
|
||||
|
||||
template <>
|
||||
@@ -48,12 +52,12 @@ findFirstValueOfAs(const MetadataMap& metadataMap, std::initializer_list<std::st
|
||||
if (!str)
|
||||
return std::nullopt;
|
||||
|
||||
std::vector<std::string> strUuids = splitString(*str, "/");
|
||||
std::vector<std::string> strUuids = StringUtils::splitString(*str, "/");
|
||||
std::vector<UUID> res;
|
||||
|
||||
for (const std::string strUuid : strUuids)
|
||||
{
|
||||
std::optional<UUID> uuid {readAs<UUID>(strUuid)};
|
||||
std::optional<UUID> uuid {UUID::fromString(strUuid)};
|
||||
if (!uuid)
|
||||
return std::nullopt;
|
||||
|
||||
@@ -103,7 +107,7 @@ getArtists(const MetadataMap& metadataMap)
|
||||
std::vector<std::string> artistNames;
|
||||
if (metadataMap.find("ARTISTS") != metadataMap.end())
|
||||
{
|
||||
artistNames = splitString(metadataMap.find("ARTISTS")->second, "/;");
|
||||
artistNames = StringUtils::splitString(metadataMap.find("ARTISTS")->second, "/;");
|
||||
}
|
||||
else if (metadataMap.find("ARTIST") != metadataMap.end())
|
||||
{
|
||||
@@ -163,54 +167,54 @@ AvFormat::parse(const std::filesystem::path& p, bool debug)
|
||||
else if (tag == "TRACK")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
std::vector<std::string> strings {splitString(value, "/") };
|
||||
std::vector<std::string> strings {StringUtils::splitString(value, "/") };
|
||||
|
||||
if (strings.size() > 0)
|
||||
{
|
||||
track.trackNumber = readAs<std::size_t>(strings[0]);
|
||||
track.trackNumber = StringUtils::readAs<std::size_t>(strings[0]);
|
||||
|
||||
if (strings.size() > 1)
|
||||
track.totalTrack = readAs<std::size_t>(strings[1]);
|
||||
track.totalTrack = StringUtils::readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DISC")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
std::vector<std::string> strings {splitString(value, "/")};
|
||||
std::vector<std::string> strings {StringUtils::splitString(value, "/")};
|
||||
|
||||
if (strings.size() > 0)
|
||||
{
|
||||
track.discNumber = readAs<std::size_t>(strings[0]);
|
||||
track.discNumber = StringUtils::readAs<std::size_t>(strings[0]);
|
||||
|
||||
if (strings.size() > 1)
|
||||
track.totalDisc = readAs<std::size_t>(strings[1]);
|
||||
track.totalDisc = StringUtils::readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DATE"
|
||||
|| tag == "YEAR"
|
||||
|| tag == "WM/Year")
|
||||
{
|
||||
track.year = readAs<int>(value);
|
||||
track.year = StringUtils::readAs<int>(value);
|
||||
}
|
||||
else if (tag == "TDOR" // Original release time (ID3v2 2.4)
|
||||
|| tag == "TORY") // Original release year
|
||||
{
|
||||
track.originalYear = readAs<int>(value);
|
||||
track.originalYear = StringUtils::readAs<int>(value);
|
||||
}
|
||||
else if (tag == "ACOUSTID ID")
|
||||
{
|
||||
track.acoustID = readAs<UUID>(value);
|
||||
track.acoustID = UUID::fromString(value);
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ RELEASE TRACK ID"
|
||||
|| tag == "MUSICBRAINZ_RELEASETRACKID"
|
||||
|| tag == "MUSICBRAINZ_TRACKID"
|
||||
|| tag == "MUSICBRAINZ/TRACK ID")
|
||||
{
|
||||
track.musicBrainzTrackID = readAs<UUID>(value);
|
||||
track.musicBrainzTrackID = UUID::fromString(value);
|
||||
}
|
||||
else if (_clusterTypeNames.find(tag) != _clusterTypeNames.end())
|
||||
{
|
||||
std::vector<std::string> clusterNames {splitString(value, "/,;")};
|
||||
std::vector<std::string> clusterNames {StringUtils::splitString(value, "/,;")};
|
||||
|
||||
if (!clusterNames.empty())
|
||||
track.clusters[tag] = std::set<std::string>{clusterNames.begin(), clusterNames.end()};
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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 "MetaData.hpp"
|
||||
|
||||
#include "utils/Utils.hpp"
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
#include <set>
|
||||
#include <vector>
|
||||
|
||||
#include "utils/Utils.hpp"
|
||||
//#include "utils/Utils.hpp"
|
||||
#include "utils/UUID.hpp"
|
||||
|
||||
namespace MetaData
|
||||
|
||||
@@ -28,7 +28,8 @@
|
||||
#include <taglib/tpropertymap.h>
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
#include "utils/Utils.hpp"
|
||||
#include "utils/String.hpp"
|
||||
|
||||
|
||||
namespace MetaData
|
||||
{
|
||||
@@ -49,7 +50,7 @@ getPropertyValuesFirstMatchAs(const TagLib::PropertyMap& properties, const std::
|
||||
|
||||
for (const auto& value : values)
|
||||
{
|
||||
auto val {readAs<T>(stringTrim(value.to8Bit(true)))};
|
||||
auto val {StringUtils::readAs<T>(StringUtils::stringTrim(value.to8Bit(true)))};
|
||||
if (!val)
|
||||
continue;
|
||||
|
||||
@@ -75,9 +76,9 @@ splitAndTrimString(const std::string& str, const std::string& delimiters)
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
|
||||
std::vector<std::string> strings {splitString(str, delimiters)};
|
||||
std::vector<std::string> strings {StringUtils::splitString(str, delimiters)};
|
||||
for (const std::string& s : strings)
|
||||
res.emplace_back(stringTrim(s));
|
||||
res.emplace_back(StringUtils::stringTrim(s));
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -224,29 +225,29 @@ TagLibParser::parse(const std::filesystem::path& p, bool debug)
|
||||
std::vector<std::string> strs;
|
||||
std::transform(values.begin(), values.end(), std::back_inserter(strs), [](const auto& value) { return value.to8Bit(true); });
|
||||
|
||||
std::cout << "[" << tag << "] = " << joinStrings(strs, "*SEP*") << std::endl;
|
||||
std::cout << "[" << tag << "] = " << StringUtils::joinStrings(strs, "*SEP*") << std::endl;
|
||||
}
|
||||
|
||||
if (tag.empty() || values.isEmpty() || values.front().isEmpty())
|
||||
continue;
|
||||
|
||||
std::string value {stringTrim(values.front().to8Bit(true))};
|
||||
std::string value {StringUtils::stringTrim(values.front().to8Bit(true))};
|
||||
|
||||
if (tag == "TITLE")
|
||||
track.title = value;
|
||||
else if (tag == "MUSICBRAINZ_RELEASETRACKID"
|
||||
|| tag == "MUSICBRAINZ RELEASE TRACK ID")
|
||||
{
|
||||
track.musicBrainzTrackID = readAs<UUID>(value);
|
||||
track.musicBrainzTrackID = UUID::fromString(value);
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ_TRACKID"
|
||||
|| tag == "MUSICBRAINZ TRACK ID")
|
||||
track.musicBrainzRecordID = readAs<UUID>(value);
|
||||
track.musicBrainzRecordID = UUID::fromString(value);
|
||||
else if (tag == "ACOUSTID_ID")
|
||||
track.acoustID = readAs<UUID>(value);
|
||||
track.acoustID = UUID::fromString(value);
|
||||
else if (tag == "TRACKTOTAL")
|
||||
{
|
||||
auto totalTrack = readAs<std::size_t>(value);
|
||||
auto totalTrack = StringUtils::readAs<std::size_t>(value);
|
||||
if (totalTrack)
|
||||
track.totalTrack = totalTrack;
|
||||
}
|
||||
@@ -257,44 +258,44 @@ TagLibParser::parse(const std::filesystem::path& p, bool debug)
|
||||
|
||||
if (!strings.empty())
|
||||
{
|
||||
track.trackNumber = readAs<std::size_t>(strings[0]);
|
||||
track.trackNumber = StringUtils::readAs<std::size_t>(strings[0]);
|
||||
|
||||
// Lower priority than TRACKTOTAL
|
||||
if (strings.size() > 1 && !track.totalTrack)
|
||||
track.totalTrack = readAs<std::size_t>(strings[1]);
|
||||
track.totalTrack = StringUtils::readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DISCTOTAL")
|
||||
{
|
||||
auto totalDisc = readAs<std::size_t>(value);
|
||||
auto totalDisc = StringUtils::readAs<std::size_t>(value);
|
||||
if (totalDisc)
|
||||
track.totalDisc = totalDisc;
|
||||
}
|
||||
else if (tag == "DISCNUMBER")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
std::vector<std::string> strings {splitString(value, "/")};
|
||||
std::vector<std::string> strings {StringUtils::splitString(value, "/")};
|
||||
|
||||
if (!strings.empty())
|
||||
{
|
||||
track.discNumber = readAs<std::size_t>(strings[0]);
|
||||
track.discNumber = StringUtils::readAs<std::size_t>(strings[0]);
|
||||
|
||||
// Lower priority than DISCTOTAL
|
||||
if (strings.size() > 1 && !track.totalDisc)
|
||||
track.totalDisc = readAs<std::size_t>(strings[1]);
|
||||
track.totalDisc = StringUtils::readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DATE")
|
||||
track.year = readAs<int>(value);
|
||||
track.year = StringUtils::readAs<int>(value);
|
||||
else if (tag == "ORIGINALDATE" && !track.originalYear)
|
||||
{
|
||||
// Lower priority than ORIGINALYEAR
|
||||
track.originalYear = readAs<int>(value);
|
||||
track.originalYear = StringUtils::readAs<int>(value);
|
||||
}
|
||||
else if (tag == "ORIGINALYEAR")
|
||||
{
|
||||
// Higher priority than ORIGINALDATE
|
||||
auto originalYear = readAs<int>(value);
|
||||
auto originalYear = StringUtils::readAs<int>(value);
|
||||
if (originalYear)
|
||||
track.originalYear = originalYear;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user