Added multi artists support
This commit is contained in:
+124
-94
@@ -19,8 +19,6 @@
|
||||
|
||||
#include "AvFormat.hpp"
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#include "av/AvInfo.hpp"
|
||||
|
||||
#include "utils/Logger.hpp"
|
||||
@@ -29,167 +27,199 @@
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
boost::optional<Items>
|
||||
using MetadataMap = std::map<std::string, std::string>;
|
||||
|
||||
boost::optional<std::string>
|
||||
findFirstValueOf(const MetadataMap& metadataMap, std::initializer_list<std::string> tags)
|
||||
{
|
||||
auto it = std::find_first_of(std::cbegin(metadataMap), std::cend(metadataMap), std::cbegin(tags), std::cend(tags), [](const auto& it, const auto& str) { return it.first == str; });
|
||||
if (it == std::cend(metadataMap))
|
||||
return boost::none;
|
||||
|
||||
return stringTrim(it->second);
|
||||
}
|
||||
|
||||
static
|
||||
boost::optional<Album>
|
||||
getAlbum(const MetadataMap& metadataMap)
|
||||
{
|
||||
boost::optional<Album> res;
|
||||
|
||||
auto album {findFirstValueOf(metadataMap, {"ALBUM"})};
|
||||
if (!album)
|
||||
return res;
|
||||
|
||||
res = Album{*album, ""};
|
||||
|
||||
auto albumMBID {findFirstValueOf(metadataMap, {"MUSICBRAINZ ALBUM ID", "MUSICBRAINZ_ALBUMID"})};
|
||||
if (!albumMBID)
|
||||
return res;
|
||||
|
||||
res->musicBrainzAlbumID = *albumMBID;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static
|
||||
boost::optional<Artist>
|
||||
getAlbumArtist(const MetadataMap& metadataMap)
|
||||
{
|
||||
boost::optional<Artist> res;
|
||||
|
||||
auto artist {findFirstValueOf(metadataMap, {"ALBUM_ARTIST"})};
|
||||
if (!artist)
|
||||
return res;
|
||||
|
||||
res = Artist{*artist, ""};
|
||||
|
||||
auto artistMBID {findFirstValueOf(metadataMap, {"MUSICBRAINZ ALBUM ARTIST ID"})};
|
||||
if (!artistMBID)
|
||||
return res;
|
||||
|
||||
res->musicBrainzArtistID = *artistMBID;
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<Artist>
|
||||
getArtists(const MetadataMap& metadataMap)
|
||||
{
|
||||
std::vector<Artist> artists;
|
||||
|
||||
std::vector<std::string> artistNames;
|
||||
if (metadataMap.find("ARTISTS") != metadataMap.end())
|
||||
{
|
||||
artistNames = splitString(metadataMap.find("ARTISTS")->second, "/;");
|
||||
}
|
||||
else if (metadataMap.find("ARTIST") != metadataMap.end())
|
||||
{
|
||||
artistNames = {metadataMap.find("ARTISTS")->second};
|
||||
}
|
||||
|
||||
std::vector<std::string> artistMBIDs;
|
||||
{
|
||||
auto mbids {findFirstValueOf(metadataMap, {"MUSICBRAINZ ARTIST ID", "MUSICBRAINZ_ARTISTID"})};
|
||||
if (mbids)
|
||||
artistMBIDs = splitString(*mbids, "/");
|
||||
}
|
||||
|
||||
for (std::size_t i {}; i < artistNames.size(); ++i)
|
||||
{
|
||||
Artist artist{std::move(artistNames[i]), ""};
|
||||
|
||||
if (artistNames.size() == artistMBIDs.size())
|
||||
artist.musicBrainzArtistID = std::move(artistMBIDs[i]);
|
||||
|
||||
artists.emplace_back(std::move(artist));
|
||||
}
|
||||
|
||||
return artists;
|
||||
}
|
||||
|
||||
boost::optional<Track>
|
||||
AvFormat::parse(const boost::filesystem::path& p, bool debug)
|
||||
{
|
||||
Items items;
|
||||
Track track;
|
||||
|
||||
try
|
||||
{
|
||||
Av::MediaFile mediaFile(p);
|
||||
Av::MediaFile mediaFile {p};
|
||||
|
||||
// Stream info
|
||||
{
|
||||
std::vector<AudioStream> audioStreams;
|
||||
|
||||
auto streams = mediaFile.getStreamInfo();
|
||||
|
||||
for (auto stream : streams)
|
||||
audioStreams.push_back( {.bitRate = stream.bitrate } );
|
||||
|
||||
if (!audioStreams.empty())
|
||||
items.insert( std::make_pair(MetaData::Type::AudioStreams, audioStreams));
|
||||
for (auto stream : mediaFile.getStreamInfo())
|
||||
{
|
||||
MetaData::AudioStream audioStream {.bitRate = static_cast<unsigned>(stream.bitrate)};
|
||||
track.audioStreams.emplace_back(audioStream);
|
||||
}
|
||||
}
|
||||
|
||||
// Duration
|
||||
items.insert( std::make_pair(MetaData::Type::Duration, mediaFile.getDuration() ));
|
||||
|
||||
// Cover
|
||||
items.insert( std::make_pair(MetaData::Type::HasCover, mediaFile.hasAttachedPictures()));
|
||||
|
||||
// Embedded MetaData
|
||||
// Make sure to convert strings into UTF-8
|
||||
track.duration = mediaFile.getDuration();
|
||||
track.hasCover = mediaFile.hasAttachedPictures();
|
||||
|
||||
MetaData::Clusters clusters;
|
||||
|
||||
std::map<std::string, std::string> metadataMap = mediaFile.getMetaData();
|
||||
for (auto metadata : metadataMap)
|
||||
const std::map<std::string, std::string> metadataMap {mediaFile.getMetaData()};
|
||||
track.artists = getArtists(metadataMap);
|
||||
track.album = getAlbum(metadataMap);
|
||||
track.albumArtist = getAlbumArtist(metadataMap);
|
||||
|
||||
for (const auto& metadata : metadataMap)
|
||||
{
|
||||
const std::string tag = boost::to_upper_copy<std::string>(metadata.first);
|
||||
const std::string value = metadata.second;
|
||||
const std::string& tag {metadata.first};
|
||||
const std::string& value {metadata.second};
|
||||
|
||||
if (debug)
|
||||
std::cout << "TAG = " << tag << ", VAL = " << value << std::endl;
|
||||
|
||||
if (tag == "ARTIST")
|
||||
{
|
||||
if (items.find(MetaData::Type::Artists) == items.end())
|
||||
items[MetaData::Type::Artists] = std::set<std::string>{ stringTrim( value) };
|
||||
}
|
||||
else if (tag == "ARTISTS")
|
||||
{
|
||||
std::vector<std::string> strings {splitString(value, "/;")}; // Picard separator is '/'
|
||||
|
||||
std::set<std::string> artists;
|
||||
for (const std::string& string : strings)
|
||||
artists.insert(stringTrim(string));
|
||||
|
||||
items[MetaData::Type::Artists] = std::move(artists);
|
||||
}
|
||||
else if (tag == "ALBUM")
|
||||
items.insert( std::make_pair(MetaData::Type::Album, stringTrim( value) ));
|
||||
else if (tag == "TITLE")
|
||||
items.insert( std::make_pair(MetaData::Type::Title, stringTrim( value) ));
|
||||
if (tag == "TITLE")
|
||||
track.title = value;
|
||||
else if (tag == "TRACK")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
auto strings = splitString(value, "/");
|
||||
std::vector<std::string> strings {splitString(value, "/") };
|
||||
|
||||
if (strings.size() > 0)
|
||||
{
|
||||
auto number = readAs<std::size_t>(strings[0]);
|
||||
if (number)
|
||||
items.insert( std::make_pair(MetaData::Type::TrackNumber, *number ));
|
||||
track.trackNumber = readAs<std::size_t>(strings[0]);
|
||||
|
||||
if (strings.size() > 1)
|
||||
{
|
||||
auto totalNumber = readAs<std::size_t>(strings[1]);
|
||||
if (totalNumber)
|
||||
items.insert( std::make_pair(MetaData::Type::TotalTrack, *totalNumber ));
|
||||
}
|
||||
track.totalTrack = readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DISC")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
auto strings = splitString(value, "/");
|
||||
std::vector<std::string> strings {splitString(value, "/")};
|
||||
|
||||
if (strings.size() > 0)
|
||||
{
|
||||
auto number = readAs<std::size_t>(strings[0]);
|
||||
if (number)
|
||||
items.insert( std::make_pair(MetaData::Type::DiscNumber, *number ));
|
||||
track.discNumber = readAs<std::size_t>(strings[0]);
|
||||
|
||||
if (strings.size() > 1)
|
||||
{
|
||||
auto totalNumber = readAs<std::size_t>(strings[1]);
|
||||
if (totalNumber)
|
||||
items.insert( std::make_pair(MetaData::Type::TotalDisc, *totalNumber ));
|
||||
}
|
||||
track.totalDisc = readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DATE"
|
||||
|| tag == "YEAR"
|
||||
|| tag == "WM/Year")
|
||||
{
|
||||
auto date = readAs<int>(value);
|
||||
if (date)
|
||||
items.insert(std::make_pair(MetaData::Type::Year, *date));
|
||||
track.year = readAs<int>(value);
|
||||
}
|
||||
else if (tag == "TDOR" // Original release time (ID3v2 2.4)
|
||||
|| tag == "TORY") // Original release year
|
||||
{
|
||||
auto date = readAs<int>(value);
|
||||
if (date)
|
||||
items.insert(std::make_pair(MetaData::Type::OriginalYear, *date));
|
||||
track.originalYear = readAs<int>(value);
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ ARTIST ID"
|
||||
|| tag == "MUSICBRAINZ_ARTISTID")
|
||||
else if (tag == "ACOUSTID ID")
|
||||
{
|
||||
std::vector<std::string> strings {splitString(value, "/")};
|
||||
|
||||
std::set<std::string> mbids;
|
||||
for (const std::string& string : strings)
|
||||
mbids.insert(stringTrim(string));
|
||||
|
||||
items[MetaData::Type::MusicBrainzArtistID] = std::move(mbids);
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ ALBUM ID"
|
||||
|| tag == "MUSICBRAINZ_ALBUMID")
|
||||
{
|
||||
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, stringTrim(value)) );
|
||||
track.acoustID = value;
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ RELEASE TRACK ID"
|
||||
|| tag == "MUSICBRAINZ_RELEASETRACKID"
|
||||
|| tag == "MUSICBRAINZ_TRACKID")
|
||||
{
|
||||
items.insert( std::make_pair(MetaData::Type::MusicBrainzTrackID, stringTrim(value)) );
|
||||
}
|
||||
else if (tag == "ACOUSTID ID")
|
||||
{
|
||||
items.insert( std::make_pair(MetaData::Type::AcoustID, stringTrim(value)) );
|
||||
track.musicBrainzTrackID = value;
|
||||
}
|
||||
else if (_clusterTypeNames.find(tag) != _clusterTypeNames.end())
|
||||
{
|
||||
std::vector<std::string> clusterNames = splitString(value, "/,;");
|
||||
std::vector<std::string> clusterNames {splitString(value, "/,;")};
|
||||
|
||||
if (!clusterNames.empty())
|
||||
{
|
||||
clusters[tag] = std::set<std::string>(clusterNames.begin(), clusterNames.end());
|
||||
}
|
||||
track.clusters[tag] = std::set<std::string>{clusterNames.begin(), clusterNames.end()};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (!clusters.empty())
|
||||
items.insert( std::make_pair(MetaData::Type::Clusters, clusters) );
|
||||
}
|
||||
catch(Av::MediaFileException& e)
|
||||
{
|
||||
return boost::none;
|
||||
}
|
||||
|
||||
return items;
|
||||
return track;
|
||||
}
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace MetaData
|
||||
class AvFormat : public Parser
|
||||
{
|
||||
public:
|
||||
boost::optional<Items> parse(const boost::filesystem::path& p, bool debug = false) override;
|
||||
boost::optional<Track> parse(const boost::filesystem::path& p, bool debug = false) override;
|
||||
};
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <chrono>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
@@ -39,7 +40,7 @@ namespace MetaData
|
||||
{
|
||||
std::string name;
|
||||
std::string musicBrainzAlbumID;
|
||||
}
|
||||
};
|
||||
|
||||
struct AudioStream
|
||||
{
|
||||
@@ -64,7 +65,7 @@ namespace MetaData
|
||||
boost::optional<int> originalYear;
|
||||
bool hasCover {false};
|
||||
std::vector<AudioStream> audioStreams;
|
||||
std::string acoustId;
|
||||
std::string acoustID;
|
||||
std::string copyright;
|
||||
std::string copyrightURL;
|
||||
};
|
||||
|
||||
+134
-106
@@ -31,7 +31,95 @@
|
||||
namespace MetaData
|
||||
{
|
||||
|
||||
boost::optional<Items>
|
||||
static
|
||||
std::vector<std::string>
|
||||
splitAndTrimString(const std::string& str, const std::string& delimiters)
|
||||
{
|
||||
std::vector<std::string> res;
|
||||
|
||||
std::vector<std::string> strings {splitString(str, delimiters)};
|
||||
for (const std::string& s : strings)
|
||||
res.emplace_back(stringTrim(s));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<std::string>
|
||||
getMusicBrainzArtistID(const TagLib::PropertyMap& properties)
|
||||
{
|
||||
if (!properties.contains("MUSICBRAINZ_ARTISTID"))
|
||||
return {};
|
||||
|
||||
const auto& values {properties["MUSICBRAINZ_ARTISTID"]};
|
||||
|
||||
return splitAndTrimString(values.front().to8Bit(true), "/"); // Picard separator is '/'
|
||||
}
|
||||
|
||||
static
|
||||
std::vector<Artist>
|
||||
getArtists(const TagLib::PropertyMap& properties)
|
||||
{
|
||||
std::vector<Artist> res;
|
||||
|
||||
if (properties.contains("ARTISTS"))
|
||||
{
|
||||
const TagLib::StringList& values {properties["ARTISTS"]};
|
||||
|
||||
std::vector<std::string> artists {splitAndTrimString(values.front().to8Bit(true), "/;")}; // Picard separator is '/'
|
||||
std::vector<std::string> artistsMBID {getMusicBrainzArtistID(properties)};
|
||||
|
||||
for (std::size_t i {}; i < artists.size(); ++i)
|
||||
res.emplace_back(Artist{artists[i], artistsMBID.size() == artists.size() ? artistsMBID[i] : ""});
|
||||
|
||||
return res;
|
||||
}
|
||||
else if (properties.contains("ARTIST"))
|
||||
{
|
||||
const auto& value {properties["ARTIST"]};
|
||||
|
||||
res.emplace_back(Artist{value.front().to8Bit(true), ""});
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
static
|
||||
boost::optional<Artist>
|
||||
getAlbumArtist(const TagLib::PropertyMap& properties)
|
||||
{
|
||||
boost::optional<Artist> res;
|
||||
|
||||
if (!properties.contains("ALBUMARTIST"))
|
||||
return res;
|
||||
|
||||
res = Artist{stringTrim(properties["ALBUMARTIST"].front().to8Bit(true)), ""};
|
||||
|
||||
if (properties.contains("MUSICBRAINZ_ALBUMARTISTID"))
|
||||
res->musicBrainzArtistID = stringTrim(properties["MUSICBRAINZ_ALBUMARTISTID"].front().to8Bit(true));
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
boost::optional<Album>
|
||||
getAlbum(const TagLib::PropertyMap& properties)
|
||||
{
|
||||
boost::optional<Album> res;
|
||||
|
||||
if (!properties.contains("ALBUM"))
|
||||
return res;
|
||||
|
||||
res = Album{stringTrim(properties["ALBUM"].front().to8Bit(true)), ""};
|
||||
|
||||
if (properties.contains("MUSICBRAINZ_ALBUMID"))
|
||||
res->musicBrainzAlbumID = properties["MUSICBRAINZ_ALBUMID"].front().to8Bit(true);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
boost::optional<Track>
|
||||
TagLibParser::parse(const boost::filesystem::path& p, bool debug)
|
||||
{
|
||||
TagLib::FileRef f {p.string().c_str(),
|
||||
@@ -44,26 +132,26 @@ TagLibParser::parse(const boost::filesystem::path& p, bool debug)
|
||||
if (!f.audioProperties())
|
||||
return boost::none;
|
||||
|
||||
Items items;
|
||||
Track track;
|
||||
|
||||
{
|
||||
const TagLib::AudioProperties *properties {f.audioProperties() };
|
||||
|
||||
items[MetaData::Type::Duration] = std::chrono::milliseconds {properties->length() * 1000};
|
||||
track.duration = std::chrono::milliseconds {properties->length() * 1000};
|
||||
|
||||
MetaData::AudioStream audioStream {.bitRate = static_cast<std::size_t>(properties->bitrate() * 1000)};
|
||||
items[MetaData::Type::AudioStreams] = std::vector<MetaData::AudioStream> {audioStream};
|
||||
MetaData::AudioStream audioStream {.bitRate = static_cast<unsigned>(properties->bitrate() * 1000)};
|
||||
track.audioStreams = {std::move(audioStream)};
|
||||
}
|
||||
|
||||
// Not that good embedded pictures handling
|
||||
|
||||
// MP3
|
||||
if (TagLib::MPEG::File *mp3File = dynamic_cast<TagLib::MPEG::File*>(f.file()))
|
||||
if (TagLib::MPEG::File *mp3File {dynamic_cast<TagLib::MPEG::File*>(f.file())})
|
||||
{
|
||||
if (mp3File->ID3v2Tag())
|
||||
{
|
||||
if (!mp3File->ID3v2Tag()->frameListMap()["APIC"].isEmpty())
|
||||
items.insert( std::make_pair(MetaData::Type::HasCover, true));
|
||||
track.hasCover = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,6 +160,10 @@ TagLibParser::parse(const boost::filesystem::path& p, bool debug)
|
||||
MetaData::Clusters clusters;
|
||||
const TagLib::PropertyMap& properties {f.file()->properties()};
|
||||
|
||||
track.artists = getArtists(properties);
|
||||
track.albumArtist = getAlbumArtist(properties);
|
||||
track.album = getAlbum(properties);
|
||||
|
||||
for(auto property : properties)
|
||||
{
|
||||
const std::string tag = property.first.upper().to8Bit(true);
|
||||
@@ -80,172 +172,108 @@ TagLibParser::parse(const boost::filesystem::path& p, bool debug)
|
||||
if (tag.empty() || values.isEmpty() || values.front().isEmpty())
|
||||
continue;
|
||||
|
||||
std::string value {stringTrim(values.front().to8Bit(true))};
|
||||
|
||||
// TODO validate MBID format
|
||||
|
||||
if (debug)
|
||||
{
|
||||
std::vector<std::string> strs;
|
||||
for (auto value : values)
|
||||
strs.push_back(values.front().to8Bit(true));
|
||||
std::transform(values.begin(), values.end(), std::back_inserter(strs), [](const auto& value) { return value.to8Bit(true); });
|
||||
|
||||
std::cout << "[" << tag << "] = " << joinStrings(strs, ",") << std::endl;
|
||||
}
|
||||
|
||||
if (tag == "ARTIST")
|
||||
{
|
||||
// Lower priority than ARTISTS
|
||||
if (items.find(MetaData::Type::Artists) == items.end())
|
||||
items[MetaData::Type::Artists] = std::vector<std::string>{ stringTrim( values.front().to8Bit(true)) };
|
||||
}
|
||||
else if (tag == "ARTISTS")
|
||||
{
|
||||
// Higher priority than ARTISTS
|
||||
std::vector<std::string> strings {splitString(values.front().to8Bit(), "/;")}; // Picard separator is '/'
|
||||
|
||||
std::vector<std::string> artists;
|
||||
for (const std::string& string : strings)
|
||||
artists.emplace_back(stringTrim(string));
|
||||
|
||||
items[MetaData::Type::Artists] = std::move(artists);
|
||||
}
|
||||
|
||||
else if (tag == "ALBUM")
|
||||
items.insert( std::make_pair(MetaData::Type::Album, stringTrim( values.front().to8Bit(true))));
|
||||
else if (tag == "TITLE")
|
||||
items.insert( std::make_pair(MetaData::Type::Title, stringTrim( values.front().to8Bit(true))));
|
||||
if (tag == "TITLE")
|
||||
track.title = value;
|
||||
else if (tag == "MUSICBRAINZ_RELEASETRACKID"
|
||||
|| tag == "MUSICBRAINZ RELEASE TRACK ID")
|
||||
{
|
||||
items.insert( std::make_pair(MetaData::Type::MusicBrainzTrackID, stringTrim( values.front().to8Bit(true))));
|
||||
track.musicBrainzTrackID = value;
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ_ARTISTID")
|
||||
{
|
||||
std::vector<std::string> strings {splitString(values.front().to8Bit(), "/")}; // Picard separator is '/'
|
||||
|
||||
std::vector<std::string> mbids;
|
||||
for (const std::string& string : strings)
|
||||
mbids.emplace_back(stringTrim(string));
|
||||
|
||||
items[MetaData::Type::MusicBrainzArtistID] = std::move(mbids);
|
||||
}
|
||||
else if (tag == "MUSICBRAINZ_ALBUMID")
|
||||
items.insert( std::make_pair(MetaData::Type::MusicBrainzAlbumID, stringTrim( values.front().to8Bit(true))));
|
||||
else if (tag == "MUSICBRAINZ_TRACKID")
|
||||
items.insert( std::make_pair(MetaData::Type::MusicBrainzRecordingID, stringTrim( values.front().to8Bit(true))));
|
||||
track.musicBrainzRecordID = value;
|
||||
else if (tag == "ACOUSTID_ID")
|
||||
items.insert( std::make_pair(MetaData::Type::AcoustID, stringTrim( values.front().to8Bit(true))));
|
||||
track.acoustID = value;
|
||||
else if (tag == "TRACKTOTAL")
|
||||
{
|
||||
auto totalTrack {readAs<std::size_t>(values.front().to8Bit(true)) };
|
||||
auto totalTrack = readAs<std::size_t>(value);
|
||||
if (totalTrack)
|
||||
items[MetaData::Type::TotalTrack] = *totalTrack;
|
||||
track.totalTrack = totalTrack;
|
||||
}
|
||||
else if (tag == "TRACKNUMBER")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
std::vector<std::string> strings {splitString(values.front().to8Bit(), "/")};
|
||||
std::vector<std::string> strings {splitAndTrimString(value, "/")};
|
||||
|
||||
if (!strings.empty())
|
||||
{
|
||||
auto number {readAs<std::size_t>(strings[0])};
|
||||
if (number)
|
||||
items.insert( std::make_pair(MetaData::Type::TrackNumber, *number ));
|
||||
track.trackNumber = readAs<std::size_t>(strings[0]);
|
||||
|
||||
// Lower priority than TRACKTOTAL
|
||||
if (strings.size() > 1 && items.find(MetaData::Type::TotalTrack) == items.end())
|
||||
{
|
||||
auto totalTrack {readAs<std::size_t>(strings[1])};
|
||||
if (totalTrack)
|
||||
items[MetaData::Type::TotalTrack] = *totalTrack;
|
||||
}
|
||||
if (strings.size() > 1 && !track.totalTrack)
|
||||
track.totalTrack = readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DISCTOTAL")
|
||||
{
|
||||
auto totalDisc = readAs<std::size_t>(values.front().to8Bit(true));
|
||||
auto totalDisc = readAs<std::size_t>(value);
|
||||
if (totalDisc)
|
||||
items[MetaData::Type::TotalDisc] = *totalDisc;
|
||||
track.totalDisc = totalDisc;
|
||||
}
|
||||
else if (tag == "DISCNUMBER")
|
||||
{
|
||||
// Expecting 'Number/Total'
|
||||
auto strings = splitString(values.front().to8Bit(), "/");
|
||||
std::vector<std::string> strings {splitString(value, "/")};
|
||||
|
||||
if (!strings.empty())
|
||||
{
|
||||
auto number = readAs<std::size_t>(strings[0]);
|
||||
if (number)
|
||||
items.insert( std::make_pair(MetaData::Type::DiscNumber, *number));
|
||||
track.discNumber = readAs<std::size_t>(strings[0]);
|
||||
|
||||
// Lower priority than DISCTOTAL
|
||||
if (strings.size() > 1 && items.find(MetaData::Type::TotalDisc) == items.end())
|
||||
{
|
||||
auto totalDisc = readAs<std::size_t>(strings[1]);
|
||||
if (totalDisc)
|
||||
items[MetaData::Type::TotalDisc] = *totalDisc;
|
||||
}
|
||||
if (strings.size() > 1 && !track.totalDisc)
|
||||
track.totalDisc = readAs<std::size_t>(strings[1]);
|
||||
}
|
||||
}
|
||||
else if (tag == "DATE")
|
||||
track.year = readAs<int>(value);
|
||||
else if (tag == "ORIGINALDATE" && !track.originalYear)
|
||||
{
|
||||
auto timePoint = readAs<int>(values.front().to8Bit());
|
||||
if (timePoint)
|
||||
items.insert( std::make_pair(MetaData::Type::Year, *timePoint));
|
||||
}
|
||||
else if (tag == "ORIGINALDATE")
|
||||
{
|
||||
// Lower priority than original year
|
||||
if (items.find(MetaData::Type::OriginalYear) == items.end())
|
||||
{
|
||||
auto timePoint = readAs<int>(values.front().to8Bit());
|
||||
if (timePoint)
|
||||
items[MetaData::Type::OriginalYear] = *timePoint;
|
||||
}
|
||||
// Lower priority than ORIGINALYEAR
|
||||
track.originalYear = readAs<int>(value);
|
||||
}
|
||||
else if (tag == "ORIGINALYEAR")
|
||||
{
|
||||
auto timePoint = readAs<int>(values.front().to8Bit());
|
||||
if (timePoint)
|
||||
{
|
||||
// Take priority on original year
|
||||
items[MetaData::Type::OriginalYear] = *timePoint;
|
||||
}
|
||||
// Higher priority than ORIGINALDATE
|
||||
auto originalYear = readAs<int>(value);
|
||||
if (originalYear)
|
||||
track.originalYear = originalYear;
|
||||
}
|
||||
else if (tag == "METADATA_BLOCK_PICTURE")
|
||||
{
|
||||
// Only add once
|
||||
if (items.find(MetaData::Type::HasCover) == items.end())
|
||||
items.insert( std::make_pair(MetaData::Type::HasCover, true));
|
||||
}
|
||||
track.hasCover = true;
|
||||
else if (tag == "COPYRIGHT")
|
||||
{
|
||||
items.insert(std::make_pair(MetaData::Type::Copyright, values.front().to8Bit()));
|
||||
}
|
||||
track.copyright = value;
|
||||
else if (tag == "COPYRIGHTURL")
|
||||
{
|
||||
items.insert(std::make_pair(MetaData::Type::CopyrightURL, values.front().to8Bit()));
|
||||
}
|
||||
track.copyrightURL = value;
|
||||
else if (_clusterTypeNames.find(tag) != _clusterTypeNames.end())
|
||||
{
|
||||
std::set<std::string> clusterNames;
|
||||
for (const auto& valueList : values)
|
||||
{
|
||||
auto values = splitString(valueList.to8Bit(), "/,;");
|
||||
auto values = splitAndTrimString(valueList.to8Bit(true), "/,;");
|
||||
|
||||
for (auto value : values)
|
||||
for (const auto& value : values)
|
||||
clusterNames.insert(value);
|
||||
}
|
||||
|
||||
if (!clusterNames.empty())
|
||||
clusters[tag] = clusterNames;
|
||||
track.clusters[tag] = clusterNames;
|
||||
}
|
||||
}
|
||||
|
||||
if (!clusters.empty())
|
||||
items.insert( std::make_pair(MetaData::Type::Clusters, clusters) );
|
||||
}
|
||||
|
||||
return items;
|
||||
return track;
|
||||
}
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace MetaData
|
||||
class TagLibParser : public Parser
|
||||
{
|
||||
public:
|
||||
boost::optional<Items> parse(const boost::filesystem::path& p, bool debug = false) override;
|
||||
boost::optional<Track> parse(const boost::filesystem::path& p, bool debug = false) override;
|
||||
};
|
||||
|
||||
} // namespace MetaData
|
||||
|
||||
Reference in New Issue
Block a user