[mythtv] patch - AlbumArt - id3v2 pic frame
Dan Morphis
dan at milkcarton.com
Fri May 7 13:32:56 EDT 2004
diff -u is the prefered way to receive patches as they are more readable.
-dan
Christian Poetzsch wrote:
> Hello,
> This patch is used to get the album art out of
> the id3v2 tag as descripted in http://www.id3.org/develop.html.
>
> It's uses id3lib for id3 part.
>
> First its look in the file for a APIC frame and
> if one found its used as art. If no one where found
> the behaviour is like before.
>
> Cheers,
> Chris
>
>------------------------------------------------------------------------
>
>*** visualize.cpp 2004-01-31 07:35:10.000000000 +0100
>--- new/visualize.cpp 2004-05-07 11:05:59.333610000 +0200
>***************
>*** 23,28 ****
>--- 23,29 ----
> #include <iostream>
> using namespace std;
>
>+ #include <id3tag.h>
> #include <mythtv/mythcontext.h>
>
> Spectrum::Spectrum()
>***************
>*** 281,331 ****
> return false;
>
> QString curfile = pParent->decoder()->getFilename();
>! QString curdir = curfile.left(curfile.findRev("/"));
>! QImage art;
>!
>! // If the directory has changed (new album) or the size, reload
>! if ((directory.compare(curdir) != 0) || (cursize != size))
> {
>! // Directory has changed
> directory = curdir;
>! // Get filter
>! QString namefilter = gContext->GetSetting("AlbumArtFilter",
> "*.png;*.jpg;*.jpeg;*.gif");
>! // Get directory contents based on filter
>! QDir folder(curdir, namefilter, QDir::Name | QDir::IgnoreCase,
>! QDir::Files | QDir::Hidden);
>!
>! QString fileart = "";
>!
>! if (folder.count())
>! fileart = folder[rand() % folder.count()];
>!
>! curdir.append("/");
>! curdir.append(fileart);
>! art.load(curdir);
> if (art.isNull())
> {
> p->fillRect(0, 0, size.width(), size.height(), back);
> p->setPen(Qt::white);
> p->setFont(gContext->GetMediumFont());
> p->drawText(size.width() / 2 - 200, size.height() / 2 - 10, 400, 20,
>! Qt::AlignCenter, QObject::tr("?"));
>! return true;
> }
>-
> QSize artsize = art.scale(size, QImage::ScaleMin).size();
>-
> // Paint the image
> p->fillRect(0, 0, size.width(), size.height(), back);
> p->drawPixmap((size.width() - artsize.width()) / 2,
> (size.height() - artsize.height()) / 2,
> art.smoothScale(size, QImage::ScaleMin));
>! // Store our new size
>! cursize = size;
>! return true;
> }
>- art.reset();
> return true;
> }
>
>--- 282,375 ----
> return false;
>
> QString curfile = pParent->decoder()->getFilename();
>! // If the size/file has changed do it again
>! if (filename != curfile || cursize != size)
> {
>! QImage art;
>!
>! filename = curfile;
>!
>! // Try to load the picture from id3v2 tag
>! id3_file *id3file = id3_file_open(curfile.local8Bit(),
>! ID3_FILE_MODE_READONLY);
>! if (id3file)
>! {
>! id3_tag *tag = id3_file_tag(id3file);
>! if (tag)
>! {
>! // Search for a picture frame
>! struct id3_frame *frame = id3_tag_findframe(tag, "APIC", 0);
>! if (frame)
>! {
>! // Some debug
>! if (0)
>! {
>! cout << "ID3 id: " << frame->id << endl;
>! cout << "ID3 description: " << frame->description << endl;
>! cout << "ID3 nfields: " << frame->nfields << endl;
>! cout << "ID3 mimetype: " << id3_field_getlatin1(id3_frame_field(frame, 1)) << endl;
>! }
>! // Check if it is a hyperlink
>! // thats current not supported
>! // (Its the case if "-->" is in the mime field)
>! const char* mime = (const char*)id3_field_getlatin1(id3_frame_field(frame, 1));
>! if (strcmp(mime, "-->") != 0)
>! {
>! id3_length_t len=frame->decoded_length;
>! // Get the picture data
>! const id3_byte_t* pictData = id3_field_getbinarydata(id3_frame_field(frame, 4), &len);
>! // Try to load it
>! art.loadFromData (pictData, len);
>! }
>! }
>! }
>! id3_file_close(id3file);
>! }
>!
>! QString curdir = curfile.left(curfile.findRev("/"));
> directory = curdir;
>!
>! // If there was no id3 picture tag, try to load
>! // some picture in the directory tree
>! if (art.isNull())
>! {
>! // Get filter
>! QString namefilter = gContext->GetSetting("AlbumArtFilter",
> "*.png;*.jpg;*.jpeg;*.gif");
>! // Get directory contents based on filter
>! QDir folder(curdir, namefilter, QDir::Name | QDir::IgnoreCase,
>! QDir::Files | QDir::Hidden);
>!
>! QString fileart = "";
>!
>! if (folder.count())
>! fileart = folder[rand() % folder.count()];
>!
>! curdir.append("/");
>! curdir.append(fileart);
>! art.load(curdir);
>! }
>! // Store our new size
>! cursize = size;
>! // If nothing was found
>! // paint some usefull art :-)
> if (art.isNull())
> {
> p->fillRect(0, 0, size.width(), size.height(), back);
> p->setPen(Qt::white);
> p->setFont(gContext->GetMediumFont());
> p->drawText(size.width() / 2 - 200, size.height() / 2 - 10, 400, 20,
>! Qt::AlignCenter, QObject::tr("?"));
>! return true;
> }
> QSize artsize = art.scale(size, QImage::ScaleMin).size();
> // Paint the image
> p->fillRect(0, 0, size.width(), size.height(), back);
> p->drawPixmap((size.width() - artsize.width()) / 2,
> (size.height() - artsize.height()) / 2,
> art.smoothScale(size, QImage::ScaleMin));
>! art.reset();
> }
> return true;
> }
>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>mythtv-dev mailing list
>mythtv-dev at mythtv.org
>http://mythtv.org/cgi-bin/mailman/listinfo/mythtv-dev
>
>
More information about the mythtv-dev
mailing list