Skip to content

Commit 014e30c

Browse files
committed
Add support for writing ID3 APIC frames to mythmusic. Currently unused.
1 parent 2080ca3 commit 014e30c

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

mythplugins/mythmusic/mythmusic/metaioid3.cpp

Lines changed: 53 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,59 @@ AlbumArtList MetaIOID3::readAlbumArt(TagLib::ID3v2::Tag *tag)
385385
return artlist;
386386
}
387387

388+
/*!
389+
* \brief Find an APIC tag by type and optionally description
390+
*
391+
* \param tag Pointer to TagLib::ID3v2::Tag object
392+
* \param type Type of picture to search for
393+
* \param description Description of picture to search for (optional)
394+
* \returns Pointer to frame
395+
*/
396+
AttachedPictureFrame* MetaIOID3::findAPIC(TagLib::ID3v2::Tag *tag,
397+
const AttachedPictureFrame::Type &type,
398+
const String &description)
399+
{
400+
TagLib::ID3v2::FrameList l = tag->frameList("APIC");
401+
for(TagLib::ID3v2::FrameList::Iterator it = l.begin(); it != l.end(); ++it)
402+
{
403+
AttachedPictureFrame *f = static_cast<AttachedPictureFrame *>(*it);
404+
if (f && f->type() == type &&
405+
(description.isNull() || f->description() == description))
406+
return f;
407+
}
408+
return NULL;
409+
}
410+
411+
/*!
412+
* \brief Write the albumart image to the file
413+
*
414+
* \param tag The ID3v2 tag object in which to look for Album Art
415+
* \returns True if successful
416+
*/
417+
bool MetaIOID3::writeAlbumArt(TagLib::ID3v2::Tag *tag, QByteArray *image,
418+
const AttachedPictureFrame::Type &type)
419+
{
420+
if (!tag || !image)
421+
return false;
422+
423+
AttachedPictureFrame *apic = findAPIC(tag, type);
424+
425+
if (!apic)
426+
{
427+
apic = new AttachedPictureFrame();
428+
tag->addFrame(apic);
429+
apic->setType(type);
430+
}
431+
432+
TagLib::ByteVector bytevector;
433+
bytevector.setData(image->data());
434+
delete image;
435+
436+
apic->setPicture(bytevector);
437+
438+
return true;
439+
}
440+
388441
/*!
389442
* \brief Find the a custom comment tag by description.
390443
* This is a copy of the same function in the
@@ -411,9 +464,6 @@ UserTextIdentificationFrame* MetaIOID3::find(TagLib::ID3v2::Tag *tag,
411464

412465
/*!
413466
* \brief Find the POPM tag associated with MythTV
414-
* This is a copy of the same function in the
415-
* TagLib::ID3v2::UserTextIdentificationFrame Class with a static
416-
* instead of dynamic cast.
417467
*
418468
* \param tag Pointer to TagLib::ID3v2::Tag object
419469
* \param email Email address associated with this POPM frame

mythplugins/mythmusic/mythmusic/metaioid3.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ class MetaIOID3 : public MetaIOTagLib
4646

4747
bool writePlayCount(TagLib::ID3v2::Tag *tag, int playcount);
4848
bool writeRating(TagLib::ID3v2::Tag *tag, int rating);
49+
bool writeAlbumArt(TagLib::ID3v2::Tag *tag, QByteArray *image,
50+
const AttachedPictureFrame::Type &type);
4951

5052
Metadata* read(QString filename);
5153
static QImage getAlbumArt(QString filename, ImageType type);
@@ -56,6 +58,8 @@ class MetaIOID3 : public MetaIOTagLib
5658
AlbumArtList readAlbumArt(TagLib::ID3v2::Tag *tag);
5759
UserTextIdentificationFrame* find(TagLib::ID3v2::Tag *tag, const String &description);
5860
PopularimeterFrame* findPOPM(TagLib::ID3v2::Tag *tag, const String &email);
61+
AttachedPictureFrame* findAPIC(TagLib::ID3v2::Tag *tag, const AttachedPictureFrame::Type &type,
62+
const String &description = String::null);
5963
};
6064

6165
#endif

0 commit comments

Comments
 (0)