Skip to content

Commit

Permalink
Make setting covers via CLI work with Windows drive letters
Browse files Browse the repository at this point in the history
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 #109
  • Loading branch information
Martchus committed Aug 9, 2023
1 parent 1bb9f4b commit e58f8a1
Showing 1 changed file with 17 additions and 10 deletions.
27 changes: 17 additions & 10 deletions cli/mainfeatures.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -901,8 +901,14 @@ void setTagInfo(const SetTagInfoArgs &args)
continue;
}
// add value from file
const auto parts = splitStringSimple<std::vector<std::string_view>>(relevantDenotedValue->value, ":", 3);
const auto path = parts.empty() ? std::string_view() : parts.front();
const auto denotedValue = relevantDenotedValue->value;
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 dataType = fieldType == KnownField::Cover ? TagDataType::Picture : TagDataType::Text;
try {
Expand All @@ -921,25 +927,26 @@ void setTagInfo(const SetTagInfoArgs &args)
value.setMimeType(coverFileInfo.mimeType());
}
auto description = std::optional<std::string_view>();
if (parts.size() > 2) {
value.setDescription(parts[2], TagTextEncoding::Utf8);
description = parts[2];
if (parts.size() > 2u + firstPartIsDriveLetter) {
description = parts[2 + firstPartIsDriveLetter];
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)) {
const auto coverType = id3v2CoverType(parts[1]);
const auto typeSpec = parts[1 + firstPartIsDriveLetter];
const auto coverType = id3v2CoverType(typeSpec);
if (coverType == invalidCoverType) {
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);
} else {
convertedId3v2CoverValues.emplace_back(std::move(value), coverType, description);
}
} else {
if (parts.size() > 1) {
if (parts.size() > 1u + firstPartIsDriveLetter) {
diag.emplace_back(
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."),
context);
}
Expand Down

0 comments on commit e58f8a1

Please sign in to comment.