Make setting covers via CLI work with Windows drive letters
Interpret a single letter plus colon as drive specification followed by the actual path instead of splitting it and considering the path the cover type. See https://github.com/Martchus/tageditor/issues/109
This commit is contained in:
parent
1bb9f4b76e
commit
e58f8a14a5
|
@ -901,8 +901,14 @@ void setTagInfo(const SetTagInfoArgs &args)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// add value from file
|
// add value from file
|
||||||
const auto parts = splitStringSimple<std::vector<std::string_view>>(relevantDenotedValue->value, ":", 3);
|
const auto denotedValue = relevantDenotedValue->value;
|
||||||
const auto path = parts.empty() ? std::string_view() : parts.front();
|
const auto firstPartIsDriveLetter = denotedValue.size() >= 2 && denotedValue[1] == ':' ? 1u : 0u;
|
||||||
|
const auto maxParts = std::size_t(3u + firstPartIsDriveLetter);
|
||||||
|
const auto parts = splitStringSimple<std::vector<std::string_view>>(denotedValue, ":", static_cast<int>(maxParts));
|
||||||
|
const auto path = parts.empty()
|
||||||
|
? std::string_view()
|
||||||
|
: (firstPartIsDriveLetter ? std::string_view(denotedValue.data(), parts[0].size() + parts[1].size() + 1)
|
||||||
|
: parts.front());
|
||||||
const auto fieldType = denotedScope.field.knownFieldForTag(tag, tagType);
|
const auto fieldType = denotedScope.field.knownFieldForTag(tag, tagType);
|
||||||
const auto dataType = fieldType == KnownField::Cover ? TagDataType::Picture : TagDataType::Text;
|
const auto dataType = fieldType == KnownField::Cover ? TagDataType::Picture : TagDataType::Text;
|
||||||
try {
|
try {
|
||||||
|
@ -921,25 +927,26 @@ void setTagInfo(const SetTagInfoArgs &args)
|
||||||
value.setMimeType(coverFileInfo.mimeType());
|
value.setMimeType(coverFileInfo.mimeType());
|
||||||
}
|
}
|
||||||
auto description = std::optional<std::string_view>();
|
auto description = std::optional<std::string_view>();
|
||||||
if (parts.size() > 2) {
|
if (parts.size() > 2u + firstPartIsDriveLetter) {
|
||||||
value.setDescription(parts[2], TagTextEncoding::Utf8);
|
description = parts[2 + firstPartIsDriveLetter];
|
||||||
description = parts[2];
|
value.setDescription(description.value(), TagTextEncoding::Utf8);
|
||||||
}
|
}
|
||||||
if (parts.size() > 1 && fieldType == KnownField::Cover
|
if (parts.size() > 1u + firstPartIsDriveLetter && fieldType == KnownField::Cover
|
||||||
&& (tagType == TagType::Id3v2Tag || tagType == TagType::VorbisComment)) {
|
&& (tagType == TagType::Id3v2Tag || tagType == TagType::VorbisComment)) {
|
||||||
const auto coverType = id3v2CoverType(parts[1]);
|
const auto typeSpec = parts[1 + firstPartIsDriveLetter];
|
||||||
|
const auto coverType = id3v2CoverType(typeSpec);
|
||||||
if (coverType == invalidCoverType) {
|
if (coverType == invalidCoverType) {
|
||||||
diag.emplace_back(DiagLevel::Warning,
|
diag.emplace_back(DiagLevel::Warning,
|
||||||
argsToString("Specified cover type \"", parts[1], "\" is invalid. Ignoring the specified field/value."),
|
argsToString("Specified cover type \"", typeSpec, "\" is invalid. Ignoring the specified field/value."),
|
||||||
context);
|
context);
|
||||||
} else {
|
} else {
|
||||||
convertedId3v2CoverValues.emplace_back(std::move(value), coverType, description);
|
convertedId3v2CoverValues.emplace_back(std::move(value), coverType, description);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (parts.size() > 1) {
|
if (parts.size() > 1u + firstPartIsDriveLetter) {
|
||||||
diag.emplace_back(
|
diag.emplace_back(
|
||||||
tag->type() == TagType::Id3v1Tag && fileInfo.hasId3v2Tag() ? DiagLevel::Information : DiagLevel::Warning,
|
tag->type() == TagType::Id3v1Tag && fileInfo.hasId3v2Tag() ? DiagLevel::Information : DiagLevel::Warning,
|
||||||
argsToString("Ignoring cover type \"", parts[1], "\" for ", tag->typeName(),
|
argsToString("Ignoring cover type \"", parts[1 + firstPartIsDriveLetter], "\" for ", tag->typeName(),
|
||||||
". It is only supported by the cover field and the tag formats ID3v2 and Vorbis Comment."),
|
". It is only supported by the cover field and the tag formats ID3v2 and Vorbis Comment."),
|
||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue