bool ASFTagHelper::hasEmbeddedCover() const { TagLib::ASF::AttributeListMap map = m_tag->attributeListMap(); TagLib::String name = fieldName( Meta::valHasCover ); for( TagLib::ASF::AttributeListMap::ConstIterator it = map.begin(); it != map.end(); ++it ) { if( it->first == name ) { TagLib::ASF::AttributeList coverList = it->second; for( TagLib::ASF::AttributeList::ConstIterator cover = coverList.begin(); cover != coverList.end(); ++cover ) { if( cover->type() != TagLib::ASF::Attribute::BytesType ) continue; TagLib::ASF::Picture pict = cover->toPicture(); if( ( pict.type() == TagLib::ASF::Picture::FrontCover || pict.type() == TagLib::ASF::Picture::Other ) && pict.dataSize() > MIN_COVER_SIZE ) { return true; } } } } return false; }
Meta::FieldHash ASFTagHelper::tags() const { Meta::FieldHash data = TagHelper::tags(); TagLib::ASF::AttributeListMap map = m_tag->attributeListMap(); for( TagLib::ASF::AttributeListMap::ConstIterator it = map.begin(); it != map.end(); ++it ) { if( !it->second.size() ) continue; qint64 field; TagLib::ASF::Attribute value = it->second[0]; QString strValue = TStringToQString( value.toString() ); if( ( field = fieldName( it->first ) ) ) { if( field == Meta::valBpm || field == Meta::valPlaycount ) data.insert( field, value.toUInt() ); else if( field == Meta::valRating ) data.insert( field, qRound( strValue.toFloat() * 10.0 ) ); else if( field == Meta::valScore ) data.insert( field, strValue.toFloat() * 100.0 ); else if( field == Meta::valDiscNr ) data.insert( field, value.toUInt() ); else if( field == Meta::valCompilation ) data.insert( field, value.toBool() ); else if( field == Meta::valHasCover ) { for( TagLib::ASF::AttributeList::ConstIterator cover = it->second.begin(); cover != it->second.end(); ++cover ) { if( cover->type() != TagLib::ASF::Attribute::BytesType ) continue; TagLib::ASF::Picture pict = cover->toPicture(); if( ( pict.type() == TagLib::ASF::Picture::FrontCover || pict.type() == TagLib::ASF::Picture::Other ) && pict.dataSize() > MIN_COVER_SIZE ) { data.insert( field, true ); break; } } } else data.insert( field, strValue ); } else if( it->first == uidFieldName( UIDAFT ) && isValidUID( strValue, UIDAFT ) ) data.insert( Meta::valUniqueId, strValue ); else if( it->first == uidFieldName( UIDMusicBrainz ) && isValidUID( strValue, UIDMusicBrainz ) ) { if( !data.contains( Meta::valUniqueId ) ) // we prefere AFT uids data.insert( Meta::valUniqueId, strValue.prepend( "mb-" ) ); } } return data; }
QImage ASFTagHelper::embeddedCover() const { TagLib::ASF::AttributeListMap map = m_tag->attributeListMap(); TagLib::String name = fieldName( Meta::valHasCover ); TagLib::ASF::Picture cover, otherCover; bool hasCover = false, hasOtherCover = false; for( TagLib::ASF::AttributeListMap::ConstIterator it = map.begin(); it != map.end(); ++it ) { if( it->first == name ) { TagLib::ASF::AttributeList coverList = it->second; for( TagLib::ASF::AttributeList::ConstIterator it = coverList.begin(); it != coverList.end(); ++it ) { if( it->type() != TagLib::ASF::Attribute::BytesType ) continue; TagLib::ASF::Picture pict = it->toPicture(); if( pict.dataSize() < MIN_COVER_SIZE ) continue; if( pict.type() == TagLib::ASF::Picture::FrontCover ) { cover = pict; hasCover = true; } else if( pict.type() == TagLib::ASF::Picture::Other ) { otherCover = pict; hasOtherCover = true; } } } } if( !hasCover && hasOtherCover ) { cover = otherCover; hasCover = true; } if( !hasCover ) return QImage(); return QImage::fromData( ( uchar * ) cover.picture().data(), cover.picture().size() ); }
ASFTag::ASFTag( TagLib::Tag *tag, TagLib::ASF::Tag *asfTag ) : Tag( tag ) , m_asfTag( asfTag ) { TagLib::ASF::AttributeListMap map = m_asfTag->attributeListMap(); for( TagLib::ASF::AttributeListMap::ConstIterator it = map.begin(); it != map.end(); ++it ) { TagLib::String key = it->first; QString val = TStringToQString( it->second[ 0 ].toString() ); if( key == TagLib::String( "WM/AlbumTitle" ) ) //album artist { m_albumArtist = val; } else if( key == TagLib::String( "WM/Composer" ) ) { m_composer = val; } else if( key == TagLib::String( "WM/PartOfSet" ) ) { m_discNumber = processDiscNumber( val ); } } }