tagparser/tagtarget.cpp

102 lines
2.9 KiB
C++
Raw Normal View History

2015-09-06 19:57:33 +02:00
#include "./tagtarget.h"
2015-04-22 19:22:01 +02:00
2015-09-06 19:57:33 +02:00
#include "./matroska/matroskatagid.h"
2015-04-22 19:22:01 +02:00
#include <c++utilities/conversion/stringconversion.h>
#include <list>
using namespace std;
2019-06-10 22:49:11 +02:00
using namespace CppUtilities;
2015-04-22 19:22:01 +02:00
namespace TagParser {
2015-04-22 19:22:01 +02:00
2016-05-26 01:59:22 +02:00
/*!
* \brief Returns a string representation for the specified \a tagTargetLevel.
*/
std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
2016-05-26 01:59:22 +02:00
{
2018-03-07 01:17:50 +01:00
switch (tagTargetLevel) {
2016-05-26 01:59:22 +02:00
case TagTargetLevel::Shot:
return "shot";
case TagTargetLevel::Subtrack:
return "subtrack, part, movement, scene";
case TagTargetLevel::Track:
return "track, song, chapter";
case TagTargetLevel::Part:
return "part, session";
case TagTargetLevel::Album:
return "album, opera, concert, movie, episode";
case TagTargetLevel::Edition:
return "edition, issue, volume, opus, season, sequel";
case TagTargetLevel::Collection:
return "collection";
default:
return std::string_view();
2016-05-26 01:59:22 +02:00
}
}
2016-05-14 00:24:01 +02:00
/*!
* \class TagParser::TagTarget
2016-05-14 00:24:01 +02:00
* \brief The TagTarget class specifies the target of a tag.
*
* Tags might only target a specific track, chapter, ...
*
* Specifying a target is currently only fully supported by Matroska.
*
* Since Ogg saves tags at stream level, the stream can be specified
* by passing a TagTarget instance to OggContainer::createTag().
* However, only the first track in the tracks() array is considered
* and any other values are just ignored.
*
* In any other tag formats, the specified target is (currently)
* completely ignored.
*/
2015-04-22 19:22:01 +02:00
/*!
* \brief Returns the string representation of the current instance.
2016-05-26 01:59:22 +02:00
* \remarks Uses the specified \a tagTargetLevel if no levelName() is assigned.
2015-04-22 19:22:01 +02:00
*/
std::string TagTarget::toString(TagTargetLevel tagTargetLevel) const
2015-04-22 19:22:01 +02:00
{
auto levelString = std::string();
2018-03-07 01:17:50 +01:00
if (level()) {
levelString += "level ";
levelString += numberToString(level());
2015-04-22 19:22:01 +02:00
}
auto defaultLevelName = std::string_view();
if (!levelName().empty() || !(defaultLevelName = tagTargetLevelName(tagTargetLevel)).empty()) {
2018-03-07 01:17:50 +01:00
if (!levelString.empty()) {
levelString += ' ';
2015-04-22 19:22:01 +02:00
}
levelString += '\'';
2018-03-07 01:17:50 +01:00
if (!levelName().empty()) {
levelString += levelName();
} else {
levelString += defaultLevelName;
}
levelString += '\'';
2015-04-22 19:22:01 +02:00
}
list<string> parts;
2018-03-07 01:17:50 +01:00
if (levelString.empty()) {
parts.emplace_back("undefined target");
} else {
2023-02-20 19:54:42 +01:00
parts.emplace_back(std::move(levelString));
2015-04-22 19:22:01 +02:00
}
2018-03-07 01:17:50 +01:00
for (auto v : tracks()) {
2015-04-22 19:22:01 +02:00
parts.emplace_back("track " + numberToString(v));
}
2018-03-07 01:17:50 +01:00
for (auto v : chapters()) {
2015-04-22 19:22:01 +02:00
parts.emplace_back("chapter " + numberToString(v));
}
2018-03-07 01:17:50 +01:00
for (auto v : editions()) {
2015-04-22 19:22:01 +02:00
parts.emplace_back("edition " + numberToString(v));
}
2018-03-07 01:17:50 +01:00
for (auto v : attachments()) {
2015-04-22 19:22:01 +02:00
parts.emplace_back("attachment " + numberToString(v));
}
return joinStrings(parts, ", ");
}
2018-03-07 01:17:50 +01:00
} // namespace TagParser