我写了一个函数,除了APIC标签之外,它应该从MPEG文件中删除所有标签,但是我得到了混合和不可预测的结果。有时,所有标签除了"年"被正确删除(这种情况大多数时间都会发生),有时候,一个或多个其他标签会额外留在"年"标签
我当然做错了什么。这是我的功能:
void stripTags(const char* path) {
MPEG::File m(path);
m.strip(MPEG::File::ID3v1 | MPEG::File::APE, true); //I added this because otherwise, all tags would stay the first time I executed stripTags(). The second time I would execute it then the tags would be mostly gone (except for "year" as mentioned)
ByteVector handle = "APIC";
ID3v2::Tag *t = m.ID3v2Tag();
if (t) {
for (ID3v2::FrameList::ConstIterator it = t->frameList().begin(); it != t->frameList().end(); it++) {
if ((*it)->frameID() != handle) {
t->removeFrames((*it)->frameID());
it = t->frameList().begin(); //since the doc says that removeFrames invalidates the pointer returned by frameList, I update this pointer after each removal
}
}
m.save();
}
m.strip(MPEG::File::ID3v1 | MPEG::File::APE, true);
}
感谢您的帮助
答案 0 :(得分:1)
在循环中,删除标记后,重置迭代器。然而,循环继续,它做的第一件事是import enchant
,这意味着你的循环将跳过一个条目。
你可以修改你的循环,例如。
ImportError: The 'enchant' C library was not found. Please install it via your OS package manager, or use a pre-built binary wheel from PyPI.