Ejemplo n.º 1
0
/* GET ALBUM COVER
 */
const char * tag_data_get_cover (TagDatac * data, uint * len)
{
    TagLib::ID3v2::AttachedPictureFrame * pic = NULL;
    if (!(reinterpret_cast<TagData *>(data))->id3v2 || (reinterpret_cast<TagData *>(data))->id3v2->frameListMap()["APIC"].isEmpty())
    {
        *len = 0;
        return NULL;
    }

    TagLib::ID3v2::FrameList::ConstIterator it;
    TagLib::ID3v2::FrameList l = (reinterpret_cast<TagData *>(data))->id3v2->frameListMap()["APIC"];
    for(it=l.begin(); it!=l.end(); ++it)
    {
        TagLib::ID3v2::AttachedPictureFrame * t = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
        if (pic == NULL)
            pic = t;
        if (t->type () == TagLib::ID3v2::AttachedPictureFrame::FrontCover)
        {
            pic = t;
            break;
        }
    }
    if (pic == NULL)
    {
        *len = 0;
        return NULL;
    }
    *len = pic->picture ().size ();
	const char * out = (const char *) malloc (*len);
    memcpy ((void *) out, pic->picture ().data(), *len);
    return out;
}
Ejemplo n.º 2
0
int FileHelper::ratingForID3v2(TagLib::ID3v2::Tag *tag) const
{
	int r = -1;
	TagLib::ID3v2::FrameList l = tag->frameListMap()["POPM"];
	if (l.isEmpty()) {
		return r;
	}
	if (TagLib::ID3v2::PopularimeterFrame *pf = static_cast<TagLib::ID3v2::PopularimeterFrame*>(l.front())) {
		switch (pf->rating()) {
		case 1:
			r = 1;
			break;
		case 64:
			r = 2;
			break;
		case 128:
			r = 3;
			break;
		case 196:
			r = 4;
			break;
		case 255:
			r = 5;
			break;
		}
	}
	return r;
}
QImage
ID3v2TagHelper::embeddedCover() const
{
    TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[fieldName( Meta::valHasCover ).toCString()];
    TagLib::ID3v2::AttachedPictureFrame *cover = NULL;
    TagLib::ID3v2::AttachedPictureFrame *otherCover = NULL;

    for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
    {
        TagLib::ID3v2::AttachedPictureFrame *currFrame =
                dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );

        if( currFrame->picture().size() < MIN_COVER_SIZE )
            continue;

        if( currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::FrontCover )
        {
            cover = currFrame;
        }
        else if( currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::Other )
        {
            otherCover = currFrame;
        }
    }

    if( !cover && otherCover )
        cover = otherCover;

    if( !cover )
        return QImage();

    return QImage::fromData( ( uchar * )( cover->picture().data() ), cover->picture().size() );
}
Ejemplo n.º 4
0
bool CTagBase::exportImage(const wchar_t* s)
{
	if (!s)	return false;
	if (_tagFile)
	{
		//get picture
		TagLib::MPEG::File *f = (TagLib::MPEG::File *)_tagFile.get();
		if (!f->hasID3v2Tag() || f->ID3v2Tag()->isEmpty())
			return false;
		/*
		TagLib::ID3v2::FrameList::ConstIterator it = f->ID3v2Tag()->frameList().begin();
		for (; it != f->ID3v2Tag()->frameList().end(); it++)
		{
			if ((*it)->frameID().operator == (TagLib::ByteVector("APIC")))
			{
				HANDLE hFile = CreateFile(s, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
				if (INVALID_HANDLE_VALUE == hFile)
					return false;
				int nWriteBytes = 0;
				size_t size = (*it)->size();
				::WriteFile(hFile, (*it)->render().data(), (*it)->size(), (LPDWORD)&nWriteBytes, NULL);
				::CloseHandle(hFile);
				if (nWriteBytes != size)
					return false;
				return true;
			}
		}*/
		if (f->ID3v2Tag()->frameListMap().size() == 0)
			return false;
		if (f->ID3v2Tag()->frameListMap().find("APIC") == f->ID3v2Tag()->frameListMap().end())
			return false;

		TagLib::ID3v2::FrameList Flist = f->ID3v2Tag()->frameListMap()["APIC"];
		if (Flist.isEmpty())
			return false;
		TagLib::ID3v2::AttachedPictureFrame *p = static_cast<TagLib::ID3v2::AttachedPictureFrame *>(Flist.front());
		size_t size = p->picture().size();
		CString strPicType = p->mimeType().toCString(true);
		int nPos = strPicType.Find('/');
		CString strTemp = strPicType.Right(strPicType.GetLength() - nPos - 1);
		//CString strPicPath   = s;

		//if (strTemp == _T("png"))
		//	strPicPath.Append(_T(".png"));
		//else
		//	strPicPath.Append(_T(".jpg"));

		HANDLE hFile = CreateFile(s, GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
		if (INVALID_HANDLE_VALUE == hFile)
			return false;
		int nWriteBytes = 0;
		::WriteFile(hFile, p->picture().data(), size, (LPDWORD)&nWriteBytes, NULL);
		::CloseHandle(hFile);
		if (nWriteBytes != size)
			return false;

		return true;
	}
	return false;
}
Ejemplo n.º 5
0
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());
			}
		}
	}
}
Ejemplo n.º 6
0
ID3v2Tag::ID3v2Tag( TagLib::Tag *tag, TagLib::ID3v2::Tag *id3v2Tag )
    : Tag( tag )
    , m_id3v2Tag( id3v2Tag )
{
    TagLib::ID3v2::FrameList fList = m_id3v2Tag->frameList();
    for( TagLib::ID3v2::FrameList::ConstIterator it = fList.begin();
         it != fList.end(); ++it )
    {
        TagLib::String frameId = TagLib::String( (*it)->frameID() );
        TagLib::ID3v2::TextIdentificationFrame *frame =
                dynamic_cast< TagLib::ID3v2::TextIdentificationFrame * >( *it );
        if( frame )
        {
            QString val = TStringToQString( frame->fieldList().toString( '\n' ) );

            if( frameId == TagLib::String( "TPE2" ) ) //album artist
            {
                m_albumArtist = val;
            }
            else if( frameId == TagLib::String( "TCOM" ) ) //composer
            {
                m_composer = val;
            }
            else if( frameId == TagLib::String( "TPOS" ) ) //disc number
            {
                m_discNumber = processDiscNumber( val );
            }
        }
    }
}
Ejemplo n.º 7
0
void FileHelper::setRatingForID3v2(int rating, TagLib::ID3v2::Tag *tag)
{
	TagLib::ID3v2::FrameList l = tag->frameListMap()["POPM"];
	// If one wants to remove the existing rating
	if (rating == 0 && !l.isEmpty()) {
		tag->removeFrame(l.front());
	} else {
		TagLib::ID3v2::PopularimeterFrame *pf = nullptr;
		if (l.isEmpty()) {
			pf = new TagLib::ID3v2::PopularimeterFrame();
			tag->addFrame(pf);
		} else {
			pf = static_cast<TagLib::ID3v2::PopularimeterFrame*>(l.front());
		}
		switch (rating) {
		case 1:
			pf->setRating(1);
			break;
		case 2:
			pf->setRating(64);
			break;
		case 3:
			pf->setRating(128);
			break;
		case 4:
			pf->setRating(196);
			break;
		case 5:
			pf->setRating(255);
			break;
		}
	}
}
Ejemplo n.º 8
0
bool MetaDSF::exportPictures(const char *prefix) const
{
  std::map<std::string, unsigned int> counter;
  TagLib::ID3v2::FrameList l = _i->_file.ID3v2Tag()->frameList("APIC");
  TagLib::ID3v2::FrameList::ConstIterator it;
  for (it = l.begin(); it != l.end(); ++it) {
    TagLib::ID3v2::AttachedPictureFrame *f =
      static_cast<TagLib::ID3v2::AttachedPictureFrame *>(*it);
    std::string fname = prefix;
    std::string tname = picTypeDesc[f->type()].toCString();
    std::string ext = MIMETypeToExtMap[f->mimeType()].toCString();
    if (counter.find(tname) == counter.end())
      counter[tname] = 1;
    else
      counter[tname] += 1;
    fname += "_";
    fname += tname;
    fname += "_";
    fname += std::to_string(counter[tname]);
    fname += ".";
    fname += ext;
    //std::cout << "fname = " << fname << std::endl;
    writeFileFromVector(fname.c_str(), f->picture());
  }
  return true;
}
Ejemplo n.º 9
0
/* GET REPLAY GAIN
 */
 float tag_data_get_gain (TagDatac * data)
{

    if ((reinterpret_cast<TagData *>(data))->xiph && !(reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["REPLAYGAIN_ALBUM_GAIN"].isEmpty())
        return atof((reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["REPLAYGAIN_ALBUM_GAIN"].front().toCString(1));
    if ((reinterpret_cast<TagData *>(data))->xiph && !(reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["REPLAYGAIN_TRACK_GAIN"].isEmpty())
        return atof((reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["REPLAYGAIN_TRACK_GAIN"].front().toCString(1));
    if ((reinterpret_cast<TagData *>(data))->xiph && !(reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["RG_AUDIOPHILE"].isEmpty())
        return atof((reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["RG_AUDIOPHILE"].front().toCString(1));
    if ((reinterpret_cast<TagData *>(data))->xiph && !(reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["RG_RADIO"].isEmpty())
        return atof((reinterpret_cast<TagData *>(data))->xiph->fieldListMap()["RG_RADIO"].front().toCString(1));


    if ((reinterpret_cast<TagData *>(data))->id3v2 && !(reinterpret_cast<TagData *>(data))->id3v2->frameListMap()["RVA2"].isEmpty())
    {
        TagLib::ID3v2::FrameList::ConstIterator it;
        TagLib::ID3v2::FrameList l = (reinterpret_cast<TagData *>(data))->id3v2->frameListMap()["RVA2"];
        for(it=l.begin(); it!=l.end(); ++it)
        {
            TagLib::ID3v2::RelativeVolumeFrame * rva = dynamic_cast<TagLib::ID3v2::RelativeVolumeFrame*>(*it);
            if (rva->channelType () == TagLib::ID3v2::RelativeVolumeFrame::MasterVolume)
                return rva->volumeAdjustment ();
        }
    }
    return 0.0;
}
Ejemplo n.º 10
0
QString FileHelper::extractFlacFeature(const QString &featureToExtract) const
{
	QString feature;
	if (TagLib::FLAC::File *flacFile = static_cast<TagLib::FLAC::File*>(_file)) {
		if (flacFile->ID3v2Tag()) {

			QString key = this->convertKeyToID3v2Key(featureToExtract);
			TagLib::ID3v2::FrameList l = flacFile->ID3v2Tag()->frameListMap()[key.toStdString().data()];
			// Fallback to the generic map in case we didn't find the matching key
			if (l.isEmpty()) {

				TagLib::StringList list = flacFile->properties()[featureToExtract.toStdString()];
				if (!list.isEmpty()) {
					feature = list.front().toCString(true);
				}

			} else {
				feature = QString(l.front()->toString().toCString(true));
			}
		} else if (flacFile->ID3v1Tag()) {
			qDebug() << Q_FUNC_INFO << "Not yet implemented for ID3v1Tag FLAC file";
		} else if (flacFile->xiphComment()) {
			const TagLib::Ogg::FieldListMap map = flacFile->xiphComment()->fieldListMap();
			if (!map[featureToExtract.toStdString().data()].isEmpty()) {
				feature = QString(map[featureToExtract.toStdString().data()].front().toCString(true));
			}
		}
	}
	return feature;
}
Ejemplo n.º 11
0
/*!
 * \brief Read the albumart image from the file
 *
 * \param filename The filename for which we want to find the length.
 * \param type The type of image we want - front/back etc
 * \returns A pointer to a QImage owned by the caller or NULL if not found.
 */
QImage* MetaIOID3::getAlbumArt(QString filename, ImageType type)
{
    QImage *picture = new QImage();

    AttachedPictureFrame::Type apicType
        = AttachedPictureFrame::FrontCover;

    switch (type)
    {
        case IT_UNKNOWN :
            apicType = AttachedPictureFrame::Other;
            break;
        case IT_FRONTCOVER :
            apicType = AttachedPictureFrame::FrontCover;
            break;
        case IT_BACKCOVER :
            apicType = AttachedPictureFrame::BackCover;
            break;
        case IT_CD :
            apicType = AttachedPictureFrame::Media;
            break;
        case IT_INLAY :
            apicType = AttachedPictureFrame::LeafletPage;
            break;
        default:
            return picture;
    }

    QByteArray fname = filename.toLocal8Bit();
    TagLib::MPEG::File *mpegfile = new TagLib::MPEG::File(fname.constData());

    if (mpegfile)
    {
        if (mpegfile->isOpen()
            && !mpegfile->ID3v2Tag()->frameListMap()["APIC"].isEmpty())
        {
            TagLib::ID3v2::FrameList apicframes =
                                    mpegfile->ID3v2Tag()->frameListMap()["APIC"];

            for(TagLib::ID3v2::FrameList::Iterator it = apicframes.begin();
                it != apicframes.end(); ++it)
            {
                AttachedPictureFrame *frame =
                                    static_cast<AttachedPictureFrame *>(*it);
                if (frame && frame->type() == apicType)
                {
                    picture->loadFromData((const uchar *)frame->picture().data(),
                                          frame->picture().size());
                    return picture;
                }
            }
        }

        delete mpegfile;
    }

    delete picture;

    return NULL;
}
Ejemplo n.º 12
0
bool is_framelist_empty(const TagLib::ID3v2::FrameList &list)
{
	for (auto it = list.begin(); it != list.end(); ++it)
		if ((*it)->toString() != TagLib::String::null)
			return false;
	return true;
}
Ejemplo n.º 13
0
Tag::Tag(const QString &filename)
    : m_filename(filename)
{
    TagLib::MPEG::File mpegfile(filename.toLocal8Bit().constData());
    TagLib::ID3v2::Tag* id3v2 = mpegfile.ID3v2Tag();
    if (id3v2 && !id3v2->isEmpty()) {
        readRegularTag(id3v2, m_data);

        int picnum = 0;

        TagLib::ID3v2::FrameList frames = id3v2->frameListMap()["APIC"]; // attached picture
        TagLib::ID3v2::FrameList::ConstIterator it = frames.begin();
        while (it != frames.end()) {
            TagLib::ID3v2::AttachedPictureFrame* apic = static_cast<TagLib::ID3v2::AttachedPictureFrame*>(*it);
            TagLib::ByteVector bytes = apic->picture();
            QImage img = QImage::fromData(reinterpret_cast<const uchar*>(bytes.data()), bytes.size());
            if (!img.isNull()) {
                m_data[QLatin1String("picture") + QString::number(picnum++)] = QVariant(img);
            }
            ++it;
        }

    } else {
        TagLib::FileRef fileref(filename.toLocal8Bit().constData());
        if (fileref.isNull())
            return;
        TagLib::Tag* tag = fileref.tag();
        if (!tag || tag->isEmpty())
            return;

        readRegularTag(tag, m_data);
    }
}
Ejemplo n.º 14
0
void loadCover(Tune *tune, TagLib::File *file)
{
	if (!searchLocalCover(tune)) {
		auto mpeg = dynamic_cast<TagLib::MPEG::File*>(file);

		if(mpeg) {
			TagLib::ID3v2::Tag* tag2 = mpeg->ID3v2Tag();
			if(tag2) {
				TagLib::ID3v2::FrameList frameList = tag2->frameList("APIC");
				if(!frameList.isEmpty()) {
					for(unsigned int i = 0; i < frameList.size(); ++i) {
						auto *coverImg = dynamic_cast<TagLib::ID3v2::AttachedPictureFrame *>(frameList[i]);
						if(coverImg) {
							QImage cover;
							if(cover.loadFromData(reinterpret_cast<const uchar*>(coverImg->picture().data()),
									      coverImg->picture().size()))
							{
								tune->setCover(cover);
								break;
							}
						}
					}
				}
			}
		}
	}
}
Ejemplo n.º 15
0
//// Private ////
void MetaDSF::MetaDSFImpl::deleteFrames(const TagLib::ID3v2::FrameList &l)
{
  TagLib::ID3v2::FrameList::ConstIterator it;

  for (it = l.begin(); it != l.end(); it++) {
    _file.ID3v2Tag()->removeFrame(*it);
  }
}
Ejemplo n.º 16
0
// Too bad can't use STL copy alogirthm....
// copy(src.begin(), src.end(), back_inserter(dest));
void MetaDSF::MetaDSFImpl::dupFrameList(const TagLib::ID3v2::FrameList &src, 
					TagLib::ID3v2::FrameList &dest) 
{
  TagLib::ID3v2::FrameList::ConstIterator it;

  for (it = src.begin(); it != src.end(); it++) {
    dest.append(*it);
  }
}
Ejemplo n.º 17
0
/*!
 * \brief Read the albumart image from the file
 *
 * \param filename The filename for which we want to find the albumart.
 * \param type The type of image we want - front/back etc
 * \returns A pointer to a QImage owned by the caller or nullptr if not found.
 */
QImage* MetaIOID3::getAlbumArt(const QString &filename, ImageType type)
{
    QImage *picture = new QImage();

    AttachedPictureFrame::Type apicType
        = AttachedPictureFrame::FrontCover;

    switch (type)
    {
        case IT_UNKNOWN :
            apicType = AttachedPictureFrame::Other;
            break;
        case IT_FRONTCOVER :
            apicType = AttachedPictureFrame::FrontCover;
            break;
        case IT_BACKCOVER :
            apicType = AttachedPictureFrame::BackCover;
            break;
        case IT_CD :
            apicType = AttachedPictureFrame::Media;
            break;
        case IT_INLAY :
            apicType = AttachedPictureFrame::LeafletPage;
            break;
        case IT_ARTIST :
            apicType = AttachedPictureFrame::Artist;
            break;
        default:
            return picture;
    }

    if (OpenFile(filename))
    {
        TagLib::ID3v2::Tag *tag = GetID3v2Tag();
        if (tag && !tag->frameListMap()["APIC"].isEmpty())
        {
            TagLib::ID3v2::FrameList apicframes = tag->frameListMap()["APIC"];

            for(TagLib::ID3v2::FrameList::Iterator it = apicframes.begin();
                it != apicframes.end(); ++it)
            {
                AttachedPictureFrame *frame =
                                    static_cast<AttachedPictureFrame *>(*it);
                if (frame && frame->type() == apicType)
                {
                    picture->loadFromData((const uchar *)frame->picture().data(),
                                         frame->picture().size());
                    return picture;
                }
            }
        }
    }

    delete picture;

    return nullptr;
}
Ejemplo n.º 18
0
/*!
 * \brief Find the POPM tag associated with MythTV
 *
 * \param tag Pointer to TagLib::ID3v2::Tag object
 * \param email Email address associated with this POPM frame
 * \returns Pointer to frame
 */
PopularimeterFrame* MetaIOID3::findPOPM(TagLib::ID3v2::Tag *tag,
                                        const String &_email)
{
  TagLib::ID3v2::FrameList l = tag->frameList("POPM");
  for(TagLib::ID3v2::FrameList::Iterator it = l.begin(); it != l.end(); ++it)
  {
    PopularimeterFrame *f = static_cast<PopularimeterFrame *>(*it);
    if (f && f->email() == _email)
      return f;
  }
  return nullptr;
}
Ejemplo n.º 19
0
QString FileHelper::extractMpegFeature(const QString &featureToExtract) const
{
	QString feature;
	if (TagLib::MPEG::File *mpegFile = static_cast<TagLib::MPEG::File*>(_file)) {
		if (mpegFile->hasID3v2Tag()) {
			TagLib::ID3v2::FrameList l = mpegFile->ID3v2Tag()->frameListMap()[featureToExtract.toStdString().data()];
			if (!l.isEmpty()) {
				feature = QString(l.front()->toString().toCString(true));
			}
		}
	}
	return feature;
}
Ejemplo n.º 20
0
/*!
 * \brief Find the a custom comment tag by description.
 *        This is a copy of the same function in the
 *        TagLib::ID3v2::UserTextIdentificationFrame Class with a static
 *        instead of dynamic cast.
 *
 * \param tag Pointer to TagLib::ID3v2::Tag object
 * \param description Description of tag to search for
 * \returns Pointer to frame
 */
UserTextIdentificationFrame* MetaIOID3::find(TagLib::ID3v2::Tag *tag,
                                                const String &description)
{
  TagLib::ID3v2::FrameList l = tag->frameList("TXXX");
  for(TagLib::ID3v2::FrameList::Iterator it = l.begin(); it != l.end(); ++it)
  {
    UserTextIdentificationFrame *f =
                                static_cast<UserTextIdentificationFrame *>(*it);
    if (f && f->description() == description)
      return f;
  }
  return nullptr;
}
Ejemplo n.º 21
0
/*!
 * \brief Find an APIC tag by type and optionally description
 *
 * \param tag Pointer to TagLib::ID3v2::Tag object
 * \param type Type of picture to search for
 * \param description Description of picture to search for (optional)
 * \returns Pointer to frame
 */
AttachedPictureFrame* MetaIOID3::findAPIC(TagLib::ID3v2::Tag *tag,
                                        const AttachedPictureFrame::Type &type,
                                        const String &description)
{
  TagLib::ID3v2::FrameList l = tag->frameList("APIC");
  for(TagLib::ID3v2::FrameList::Iterator it = l.begin(); it != l.end(); ++it)
  {
    AttachedPictureFrame *f = static_cast<AttachedPictureFrame *>(*it);
    if (f && f->type() == type &&
        (description.isNull() || f->description() == description))
      return f;
  }
  return nullptr;
}
Ejemplo n.º 22
0
void MetaDSF::printTags(const char *prefix) const 
{
  if (_i->_file.ID3v2Tag()->isEmpty()) {
    return;
  }

  TagLib::ID3v2::FrameList l = _i->_file.ID3v2Tag()->frameList();
  TagLib::ID3v2::FrameList::ConstIterator it;
  
  for (it = l.begin(); it != l.end(); it++) {
    std::cout << prefix;
    std::cout << (*it)->frameID() << "=" << (*it)->toString() << std::endl;
  }
}
Ejemplo n.º 23
0
int MetaDSF::MetaDSFImpl::deleteTags(const TagLib::String &key) {
  TagLib::ID3v2::FrameList l;
  if (key == "") {
    l = _file.ID3v2Tag()->frameList();
  } else {
    l = _file.ID3v2Tag()->frameList(key.toCString());
  }
  TagLib::ID3v2::FrameList ll;

  dupFrameList(l, ll);
  deleteFrames(ll);
  _changed = true;
  return ll.size();
}
Ejemplo n.º 24
0
TagLib::Tag *mttFile::getTag( bool create )
{
    if ( tag == NULL ) {
		fileref = new TagLib::FileRef( QFile::encodeName( fname ).constData() );

        if ( fileref ) {
            if ( ismpeg ) {
                TagLib::MPEG::File *f = dynamic_cast<TagLib::MPEG::File *>(fileref->file());
                tag = new TagLib::ID3v2::Tag();
                if ( f->ID3v2Tag( create ) != NULL ) {
                    TagLib::Tag::duplicate( dynamic_cast<TagLib::Tag *>( f->ID3v2Tag( create ) ), tag, true );

                    // Read extra mp3 tags
                    int i;
                    for ( i = 0; i < EF_NUM; i++ ) {
                        TagLib::ID3v2::FrameList l = f->ID3v2Tag()->frameListMap()[extraFrames[i][0]];

                        if ( !l.isEmpty() ) {
                            mp3eframes += extraFrames[i][0];
                            mp3eframes += TStringToQString( l.front()->toString() );
                        }
                    }
                }


                delete fileref;
                fileref = NULL;
                return tag;
            }
            else { // If the file is ogg or flac
                tag = new TagLib::Ogg::XiphComment();
                if ( fileref->tag() ) // If a tag already exists
                    TagLib::Tag::duplicate( fileref->tag(), tag, true );
                delete fileref;
                fileref = NULL;
                return tag;
            }
        }
        else {
            //qDebug( "fileref = NULL" );
            return NULL;
        }

        delete fileref;
        fileref = NULL;
    }
    else
        return tag;
}
Ejemplo n.º 25
0
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;
	}
}
Ejemplo n.º 26
0
QString extractMBIDFromFile(TagLib::MPEG::File *file)
{
	TagLib::ID3v2::Tag *tag = file->ID3v2Tag();
	TagLib::ID3v2::FrameList ufid = tag->frameListMap()["UFID"];
	if (!ufid.isEmpty()) {
		for (TagLib::ID3v2::FrameList::Iterator i = ufid.begin(); i != ufid.end(); i++) {
			TagLib::ID3v2::UniqueFileIdentifierFrame *frame = dynamic_cast<TagLib::ID3v2::UniqueFileIdentifierFrame *>(*i);
			if (frame && frame->owner() == "http://musicbrainz.org") {
				TagLib::ByteVector id = frame->identifier();
				return QString::fromAscii(id.data(), id.size());
			}
		}
	}
	return QString();
}
Ejemplo n.º 27
0
bool CoverUtils::coverFromMPEGTags(TagLib::ID3v2::Tag *tag, Album *album) {

    if (!tag) return false;

    TagLib::ID3v2::FrameList list = tag->frameList("APIC");
    if (list.isEmpty()) return false;

    TagLib::ID3v2::AttachedPictureFrame *frame =
            static_cast<TagLib::ID3v2::AttachedPictureFrame *>(list.front());
    if (!frame) return false;
    const int frameSize = frame->picture().size();
    if (frameSize <= 0) return false;

    QImage image;
    image.loadFromData((const uchar *) frame->picture().data(), frame->picture().size());
    if (!isAcceptableImage(image)) return false;

    return saveImage(image, album);
}
bool
ID3v2TagHelper::hasEmbeddedCover() const
{
    TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[fieldName( Meta::valHasCover ).toCString()];

    for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
    {
        TagLib::ID3v2::AttachedPictureFrame *currFrame =
                dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );

        if( currFrame->picture().size() < MIN_COVER_SIZE )
            continue;

        if( currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::FrontCover ||
            currFrame->type() == TagLib::ID3v2::AttachedPictureFrame::Other )
            return true;
    }

    return false;
}
Ejemplo n.º 29
0
void ReplayGainReader::readID3v2(TagLib::ID3v2::Tag *tag)
{
    TagLib::ID3v2::UserTextIdentificationFrame* frame = 0;
    TagLib::ID3v2::FrameList frames = tag->frameList("TXXX");
    for(TagLib::ID3v2::FrameList::Iterator it = frames.begin(); it != frames.end(); ++it)
    {
        frame = dynamic_cast<TagLib::ID3v2::UserTextIdentificationFrame*>(*it);
        if(frame && frame->fieldList().size() >= 2)
        {
            TagLib::String desc = frame->description().upper();
            if (desc == "REPLAYGAIN_TRACK_GAIN")
                setValue(Qmmp::REPLAYGAIN_TRACK_GAIN, TStringToQString(frame->fieldList()[1]));
            else if (desc == "REPLAYGAIN_TRACK_PEAK")
                setValue(Qmmp::REPLAYGAIN_TRACK_PEAK, TStringToQString(frame->fieldList()[1]));
            else if (desc == "REPLAYGAIN_ALBUM_GAIN")
                setValue(Qmmp::REPLAYGAIN_ALBUM_GAIN, TStringToQString(frame->fieldList()[1]));
            else if (desc == "REPLAYGAIN_ALBUM_PEAK")
                setValue(Qmmp::REPLAYGAIN_ALBUM_PEAK, TStringToQString(frame->fieldList()[1]));
        }
    }
}
bool
ID3v2TagHelper::setEmbeddedCover( const QImage &cover )
{
    QByteArray bytes;
    QBuffer buffer( &bytes );

    buffer.open( QIODevice::WriteOnly );

    if( !cover.save( &buffer, "JPEG" ) )
    {
        buffer.close();
        return false;
    }

    buffer.close();

    TagLib::ByteVector field = fieldName( Meta::valHasCover ).toCString();
    TagLib::ID3v2::FrameList apicList = m_tag->frameListMap()[field];
    TagLib::ID3v2::AttachedPictureFrame *frontCover = NULL;

    // remove covers
    TagLib::List<TagLib::ID3v2::AttachedPictureFrame*> backedUpPictures;
    for( TagLib::ID3v2::FrameList::ConstIterator it = apicList.begin(); it != apicList.end(); ++it )
    {
        TagLib::ID3v2::AttachedPictureFrame *currFrame =
                dynamic_cast< TagLib::ID3v2::AttachedPictureFrame * >( *it );

        m_tag->removeFrame( currFrame, false );
    }

    // add new cover
    frontCover = new TagLib::ID3v2::AttachedPictureFrame( field );
    frontCover->setMimeType( "image/jpeg" );
    frontCover->setPicture( TagLib::ByteVector( bytes.data(), bytes.count() ) );
    frontCover->setType( TagLib::ID3v2::AttachedPictureFrame::FrontCover );
    m_tag->addFrame( frontCover );

    return true;
}