void FileHelper::setFlacAttribute(const std::string &attribute, const QString &value) { if (TagLib::FLAC::File *flacFile = static_cast<TagLib::FLAC::File*>(_file)) { if (flacFile->hasID3v2Tag()) { TagLib::ID3v2::Tag *tag = flacFile->ID3v2Tag(); QString key = this->convertKeyToID3v2Key(attribute.data()); TagLib::ID3v2::FrameList l = tag->frameListMap()[key.toStdString().data()]; if (!l.isEmpty()) { tag->removeFrame(l.front()); } TagLib::ID3v2::TextIdentificationFrame *tif = new TagLib::ID3v2::TextIdentificationFrame(TagLib::ByteVector("ARTISTALBUM")); tif->setText(value.toStdString().data()); tag->addFrame(tif); } else if (flacFile->hasID3v1Tag()) { qDebug() << Q_FUNC_INFO << "Not implemented (FLAC ID3v1)"; } else if (flacFile->hasXiphComment()) { TagLib::Ogg::XiphComment *xiph = flacFile->xiphComment(); if (value.isEmpty()) { xiph->removeField(attribute.data()); } else { xiph->addField(attribute.data(), value.toStdString().data()); } } } }
void FileHelper::setArtistAlbum(const QString &artistAlbum) { switch (_fileType) { case EXT_FLAC: { this->setFlacAttribute("ALBUMARTIST", artistAlbum); break; } case EXT_MP4:{ TagLib::StringList l; l.append(artistAlbum.toStdString().data()); TagLib::MP4::Item item(l); this->setMp4Attribute("aART", item); break; } case EXT_MPC: //mpcFile = static_cast<MPC::File*>(f); qDebug() << Q_FUNC_INFO << "Not implemented for MPC"; break; case EXT_MP3:{ TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file); if (mpegFile->hasID3v2Tag()) { TagLib::ID3v2::Tag *tag = mpegFile->ID3v2Tag(); QString convertedKey = this->convertKeyToID3v2Key("ARTISTALBUM"); TagLib::ID3v2::FrameList l = tag->frameListMap()[convertedKey.toStdString().data()]; if (!l.isEmpty()) { tag->removeFrame(l.front()); } TagLib::ID3v2::TextIdentificationFrame *tif = new TagLib::ID3v2::TextIdentificationFrame(TagLib::ByteVector(convertedKey.toStdString().data())); tif->setText(artistAlbum.toStdString().data()); tag->addFrame(tif); } else if (mpegFile->hasID3v1Tag()) { qDebug() << Q_FUNC_INFO << "Not implemented for ID3v1Tag"; } break; } case EXT_OGG: { TagLib::Ogg::XiphComment *xiphComment = static_cast<TagLib::Ogg::XiphComment*>(_file->tag()); if (xiphComment) { xiphComment->addField("ALBUMARTIST", artistAlbum.toStdString().data()); } else { qDebug() << Q_FUNC_INFO << "Not implemented for this OGG file"; } break; } default: qDebug() << Q_FUNC_INFO << "Not implemented for this type of file"; break; } }
bool CTagBase::addImage(wchar_t* s) { if (!_tagFile) return false; TagLib::MPEG::File *pAudioFile = (TagLib::MPEG::File *)_tagFile.get(); CString strFileName = s; ImageFile imageFile((CW2A)strFileName.GetBuffer()); if (!pAudioFile->isValid() || !imageFile.isValid()) return false; TagLib::ID3v2::Tag *tag = pAudioFile->ID3v2Tag(true); TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame; frame->setMimeType(imageFile.mimeType()); frame->setPicture(imageFile.data()); tag->addFrame(frame); return pAudioFile->save(); }
bool mttFile::saveTag( void ) { fileref = new TagLib::FileRef( QFile::encodeName( fname ).constData() ); if ( ismpeg ) { TagLib::MPEG::File *f = dynamic_cast<TagLib::MPEG::File *>(fileref->file()); // Remove id3v1 tag. Help put that hack into eternal rest :-) f->strip( TagLib::MPEG::File::ID3v1, true ); //qDebug("ID3v1 tag stripped!"); TagLib::Tag::duplicate( tag, dynamic_cast<TagLib::Tag *>( f->ID3v2Tag( true ) ), true ); // Save extra mp3 tags TagLib::ID3v2::TextIdentificationFrame *myframe; TagLib::ID3v2::Tag *mytag; mytag = f->ID3v2Tag( false ); for ( QStringList::Iterator it = mp3eframes.begin(); it != mp3eframes.end(); ++it ) { myframe = new TagLib::ID3v2::TextIdentificationFrame( (*it).toAscii().constData(), TagLib::String::UTF8 ); mytag->removeFrames( (*it).toAscii().constData() ); ++it; myframe->setText( Q4StringToTString( (*it) ) ); mytag->addFrame( myframe ); } delete fileref; fileref = NULL; return f->save( TagLib::MPEG::File::ID3v2, true ); } else { TagLib::Tag::duplicate( tag, fileref->tag(), true ); delete fileref; fileref = NULL; return fileref->save(); } }
/*! * \brief Write the albumart image to the file * * \param filename The music file to add the albumart * \param albumart The Album Art image to write * \returns True if successful * * \note We always save the image in JPEG format */ bool MetaIOID3::writeAlbumArt(const QString &filename, const AlbumArtImage *albumart) { if (filename.isEmpty() || !albumart) return false; // load the image into a QByteArray QImage image(albumart->m_filename); QByteArray imageData; QBuffer buffer(&imageData); buffer.open(QIODevice::WriteOnly); image.save(&buffer, "JPEG"); AttachedPictureFrame::Type type = AttachedPictureFrame::Other; switch (albumart->m_imageType) { case IT_FRONTCOVER: type = AttachedPictureFrame::FrontCover; break; case IT_BACKCOVER: type = AttachedPictureFrame::BackCover; break; case IT_CD: type = AttachedPictureFrame::Media; break; case IT_INLAY: type = AttachedPictureFrame::LeafletPage; break; case IT_ARTIST: type = AttachedPictureFrame::Artist; break; default: type = AttachedPictureFrame::Other; break; } if (!OpenFile(filename, true)) return false; TagLib::ID3v2::Tag *tag = GetID3v2Tag(); if (!tag) return false; AttachedPictureFrame *apic = findAPIC(tag, type, QStringToTString(albumart->m_description)); if (!apic) { apic = new AttachedPictureFrame(); tag->addFrame(apic); apic->setType(type); } QString mimetype = "image/jpeg"; TagLib::ByteVector bytevector; bytevector.setData(imageData.data(), imageData.size()); apic->setMimeType(QStringToTString(mimetype)); apic->setPicture(bytevector); apic->setDescription(QStringToTString(albumart->m_description)); if (!SaveFile()) return false; return true; }
/*! * \copydoc MetaIO::write() */ bool MetaIOID3::write(const QString &filename, MusicMetadata* mdata) { if (filename.isEmpty()) return false; if (!OpenFile(filename, true)) return false; TagLib::ID3v2::Tag *tag = GetID3v2Tag(); if (!tag) return false; WriteGenericMetadata(tag, mdata); // MythTV rating and playcount, stored in POPM frame writeRating(tag, mdata->Rating()); writePlayCount(tag, mdata->PlayCount()); writeLastPlay(tag, mdata->LastPlay()); // MusicBrainz ID UserTextIdentificationFrame *musicbrainz = nullptr; musicbrainz = find(tag, "MusicBrainz Album Artist Id"); if (mdata->Compilation()) { if (!musicbrainz) { musicbrainz = new UserTextIdentificationFrame(TagLib::String::UTF8); tag->addFrame(musicbrainz); musicbrainz->setDescription("MusicBrainz Album Artist Id"); } musicbrainz->setText(MYTH_MUSICBRAINZ_ALBUMARTIST_UUID); } else if (musicbrainz) tag->removeFrame(musicbrainz); // Compilation Artist Frame (TPE4/2) if (!mdata->CompilationArtist().isEmpty()) { TextIdentificationFrame *tpe4frame = nullptr; TagLib::ID3v2::FrameList tpelist = tag->frameListMap()["TPE4"]; if (!tpelist.isEmpty()) tpe4frame = (TextIdentificationFrame *)tpelist.front(); if (!tpe4frame) { tpe4frame = new TextIdentificationFrame(TagLib::ByteVector("TPE4"), TagLib::String::UTF8); tag->addFrame(tpe4frame); } tpe4frame->setText(QStringToTString(mdata->CompilationArtist())); TextIdentificationFrame *tpe2frame = nullptr; tpelist = tag->frameListMap()["TPE2"]; if (!tpelist.isEmpty()) tpe2frame = (TextIdentificationFrame *)tpelist.front(); if (!tpe2frame) { tpe2frame = new TextIdentificationFrame(TagLib::ByteVector("TPE2"), TagLib::String::UTF8); tag->addFrame(tpe2frame); } tpe2frame->setText(QStringToTString(mdata->CompilationArtist())); } if (!SaveFile()) return false; return true; }
/*! * \copydoc MetaIO::write() */ bool MetaIOID3::write(Metadata* mdata) { TagLib::MPEG::File *mpegfile = OpenFile(mdata->Filename()); if (!mpegfile) return false; TagLib::ID3v2::Tag *tag = mpegfile->ID3v2Tag(); if (!tag) { delete mpegfile; return false; } WriteGenericMetadata(tag, mdata); // MythTV rating and playcount, stored in POPM frame writeRating(tag, mdata->Rating()); writePlayCount(tag, mdata->PlayCount()); // MusicBrainz ID UserTextIdentificationFrame *musicbrainz = NULL; musicbrainz = find(tag, "MusicBrainz Album Artist Id"); if (mdata->Compilation()) { if (!musicbrainz) { musicbrainz = new UserTextIdentificationFrame(TagLib::String::UTF8); tag->addFrame(musicbrainz); musicbrainz->setDescription("MusicBrainz Album Artist Id"); } musicbrainz->setText(MYTH_MUSICBRAINZ_ALBUMARTIST_UUID); } else if (musicbrainz) tag->removeFrame(musicbrainz); // Compilation Artist Frame (TPE4/2) if (!mdata->CompilationArtist().isEmpty()) { TextIdentificationFrame *tpe4frame = NULL; TagLib::ID3v2::FrameList tpelist = tag->frameListMap()["TPE4"]; if (!tpelist.isEmpty()) tpe4frame = (TextIdentificationFrame *)tpelist.front(); if (!tpe4frame) { tpe4frame = new TextIdentificationFrame(TagLib::ByteVector("TPE4"), TagLib::String::UTF8); tag->addFrame(tpe4frame); } tpe4frame->setText(QStringToTString(mdata->CompilationArtist())); TextIdentificationFrame *tpe2frame = NULL; tpelist = tag->frameListMap()["TPE2"]; if (!tpelist.isEmpty()) tpe2frame = (TextIdentificationFrame *)tpelist.front(); if (!tpe2frame) { tpe2frame = new TextIdentificationFrame(TagLib::ByteVector("TPE2"), TagLib::String::UTF8); tag->addFrame(tpe2frame); } tpe2frame->setText(QStringToTString(mdata->CompilationArtist())); } bool result = mpegfile->save(); delete mpegfile; return result; }
void saveFile(string stdPath, DataEditors* editors) { const char* charPath = stdPath.c_str(); ifstream fileCheck(charPath); if(!fileCheck.good()) { QWidget *w = new QWidget(); QLabel *l = new QLabel("Invalid file!", w); QPushButton *b = new QPushButton("OK", w); QVBoxLayout *lay = new QVBoxLayout(); lay->addWidget(l); lay->addWidget(b); w->setLayout(lay); QWidget::connect(b, SIGNAL(clicked()), w, SLOT(close())); w->show(); return; } TagLib::FileName name = charPath; TagLib::FileRef file(name); if(editors->artist->isEnabled()) file.tag()->setArtist(editors->artist->text().toStdString()); if(editors->album->isEnabled()) file.tag()->setAlbum(editors->album->text().toStdString()); if(editors->track->isEnabled()) file.tag()->setTrack(editors->track->text().toInt()); if(editors->title->isEnabled()) file.tag()->setTitle(editors->title->text().toStdString()); if(editors->year->isEnabled()) file.tag()->setYear(editors->year->text().toInt()); if(editors->genre->isEnabled()) file.tag()->setGenre(editors->genre->currentText().toStdString()); if(editors->comment->isEnabled()) file.tag()->setComment(editors->comment->toPlainText().toStdString()); file.save(); if(editors->picture->isEnabled()) { TagLib::MPEG::File mpegFile(name); TagLib::ID3v2::Tag *tag = mpegFile.ID3v2Tag(true); TagLib::ID3v2::AttachedPictureFrame *frame = new TagLib::ID3v2::AttachedPictureFrame; QString picture = editors->picture->text(); if(picture == "<Attached picture>") { TagLib::ID3v2::AttachedPictureFrame *f = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(editors->mpegFile->ID3v2Tag(true)->frameList("APIC").front()); frame->setMimeType(f->mimeType()); frame->setPicture(f->picture()); tag->removeFrames("APIC"); tag->addFrame(frame); mpegFile.save(); } else if(picture == "") { tag->removeFrames("APIC"); mpegFile.save(); } else { frame->setMimeType("image/jpeg"); string stdPic = picture.toStdString(); const char* charPicture = stdPic.c_str(); ifstream fileCheck(charPicture); if(!fileCheck.good()) { QWidget *w = new QWidget(); QLabel *l = new QLabel("Invalid picture!", w); QPushButton *b = new QPushButton("OK", w); QVBoxLayout *lay = new QVBoxLayout(); lay->addWidget(l); lay->addWidget(b); w->setLayout(lay); QWidget::connect(b, SIGNAL(clicked()), w, SLOT(close())); w->show(); delete w; return; } ImageFile imageTagLibFile(charPicture); frame->setPicture(imageTagLibFile.data()); tag->removeFrames("APIC"); tag->addFrame(frame); mpegFile.save(); } } }