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
|
|
|
|
2018-03-06 23:09:15 +01: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.
|
|
|
|
*/
|
2021-01-30 21:53:06 +01:00
|
|
|
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:
|
2021-01-30 21:53:06 +01:00
|
|
|
return std::string_view();
|
2016-05-26 01:59:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-05-14 00:24:01 +02:00
|
|
|
/*!
|
2018-06-03 20:38:32 +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
|
|
|
*/
|
2021-01-30 21:53:06 +01:00
|
|
|
std::string TagTarget::toString(TagTargetLevel tagTargetLevel) const
|
2015-04-22 19:22:01 +02:00
|
|
|
{
|
2021-01-30 21:53:06 +01:00
|
|
|
auto levelString = std::string();
|
2018-03-07 01:17:50 +01:00
|
|
|
if (level()) {
|
2016-06-06 20:46:30 +02:00
|
|
|
levelString += "level ";
|
|
|
|
levelString += numberToString(level());
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
2021-01-30 21:53:06 +01:00
|
|
|
auto defaultLevelName = std::string_view();
|
|
|
|
if (!levelName().empty() || !(defaultLevelName = tagTargetLevelName(tagTargetLevel)).empty()) {
|
2018-03-07 01:17:50 +01:00
|
|
|
if (!levelString.empty()) {
|
2016-06-06 20:46:30 +02:00
|
|
|
levelString += ' ';
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
2016-06-06 20:46:30 +02:00
|
|
|
levelString += '\'';
|
2018-03-07 01:17:50 +01:00
|
|
|
if (!levelName().empty()) {
|
2016-06-06 20:46:30 +02:00
|
|
|
levelString += levelName();
|
|
|
|
} else {
|
|
|
|
levelString += defaultLevelName;
|
|
|
|
}
|
|
|
|
levelString += '\'';
|
2015-04-22 19:22:01 +02:00
|
|
|
}
|
2016-06-06 20:46:30 +02:00
|
|
|
list<string> parts;
|
2018-03-07 01:17:50 +01:00
|
|
|
if (levelString.empty()) {
|
2016-06-06 20:46:30 +02:00
|
|
|
parts.emplace_back("undefined target");
|
|
|
|
} else {
|
|
|
|
parts.emplace_back(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
|