Fix --tag-pos option

Also add test and show tag pos for MP4 files
This commit is contained in:
Martchus 2016-11-15 22:45:19 +01:00
parent 30fc881a30
commit 015dd6e181
3 changed files with 42 additions and 4 deletions

View File

@ -117,6 +117,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg) :
tagPosValueArg.setValueNames({"front/back/current"});
tagPosValueArg.setPreDefinedCompletionValues("front back current");
tagPosValueArg.setImplicit(true);
tagPosValueArg.setRequired(true);
forceTagPosArg.setCombinable(true);
tagPosArg.setCombinable(true);
tagPosArg.setSubArguments({&tagPosValueArg, &forceTagPosArg});
@ -125,6 +126,7 @@ SetTagInfoArgs::SetTagInfoArgs(Argument &filesArg, Argument &verboseArg) :
indexPosValueArg.setValueNames({"front/back/current"});
indexPosValueArg.setPreDefinedCompletionValues("front back current");
indexPosValueArg.setImplicit(true);
indexPosValueArg.setRequired(true);
indexPosArg.setCombinable(true);
indexPosArg.setSubArguments({&indexPosValueArg, &forceIndexPosArg});
forceRewriteArg.setCombinable(true);

View File

@ -295,10 +295,10 @@ TagTextEncoding parseEncodingDenotation(const Argument &encodingArg, TagTextEnco
return defaultEncoding;
}
ElementPosition parsePositionDenotation(const Argument &posArg, ElementPosition defaultPos)
ElementPosition parsePositionDenotation(const Argument &posArg, const Argument &valueArg, ElementPosition defaultPos)
{
if(posArg.isPresent()) {
const auto &val = posArg.values().front();
const char *val = valueArg.values(0).front();
if(!strcmp(val, "front")) {
return ElementPosition::BeforeData;
} else if(!strcmp(val, "back")) {
@ -812,6 +812,20 @@ void displayFileInfo(const ArgumentOccurrence &, const Argument &filesArg, const
printProperty("Duration", container->duration());
printProperty("Creation time", container->creationTime());
printProperty("Modification time", container->modificationTime());
const char *tagPos;
switch(container->determineTagPosition()) {
case ElementPosition::BeforeData:
tagPos = "before data";
break;
case ElementPosition::AfterData:
tagPos = "after data";
break;
case ElementPosition::Keep:
tagPos = nullptr;
}
if(tagPos) {
printProperty("Tag position", tagPos);
}
}
if(fileInfo.paddingSize()) {
printProperty("Padding", dataSizeToString(fileInfo.paddingSize()));
@ -1094,9 +1108,9 @@ void setTagInfo(const SetTagInfoArgs &args)
fileInfo.setMinPadding(parseUInt64(args.minPaddingArg, 0));
fileInfo.setMaxPadding(parseUInt64(args.maxPaddingArg, 0));
fileInfo.setPreferredPadding(parseUInt64(args.prefPaddingArg, 0));
fileInfo.setTagPosition(parsePositionDenotation(args.tagPosArg, ElementPosition::BeforeData));
fileInfo.setTagPosition(parsePositionDenotation(args.tagPosArg, args.tagPosValueArg, ElementPosition::BeforeData));
fileInfo.setForceTagPosition(args.forceTagPosArg.isPresent());
fileInfo.setIndexPosition(parsePositionDenotation(args.indexPosArg, ElementPosition::BeforeData));
fileInfo.setIndexPosition(parsePositionDenotation(args.indexPosArg, args.indexPosValueArg, ElementPosition::BeforeData));
fileInfo.setForceIndexPosition(args.forceIndexPosArg.isPresent());
fileInfo.setForceRewrite(args.forceRewriteArg.isPresent());
// iterate through all specified files

View File

@ -41,6 +41,7 @@ class CliTests : public TestFixture
CPPUNIT_TEST(testDisplayingInfo);
CPPUNIT_TEST(testExtraction);
CPPUNIT_TEST(testReadingAndWritingDocumentTitle);
CPPUNIT_TEST(testFileLayoutOptions);
#endif
CPPUNIT_TEST_SUITE_END();
@ -59,6 +60,7 @@ public:
void testDisplayingInfo();
void testExtraction();
void testReadingAndWritingDocumentTitle();
void testFileLayoutOptions();
#endif
private:
@ -565,4 +567,24 @@ void CliTests::testReadingAndWritingDocumentTitle()
remove(mkvFile.data());
remove((mkvFile + ".bak").data());
}
/*!
* \brief Tests options for controlling file layout.
*/
void CliTests::testFileLayoutOptions()
{
cout << "\nFile layout options" << endl;
string stdout, stderr;
const string mp4File1(workingCopyPath("mtx-test-data/alac/othertest-itunes.m4a"));
const char *const args1[] = {"tageditor", "set", "title=File layout test", "--tag-pos", "back", "--force", "-f", mp4File1.data(), nullptr};
TESTUTILS_ASSERT_EXEC(args1);
const char *const args2[] = {"tageditor", "info", "-f", mp4File1.data(), nullptr};
TESTUTILS_ASSERT_EXEC(args2);
CPPUNIT_ASSERT(stdout.find("Tag position after data") != string::npos);
remove(mp4File1.data());
remove((mp4File1 + ".bak").data());
}
#endif