[mythtv] patch - AlbumArt - id3v2 pic frame

Christian Poetzsch cp at BurningDragon.de
Mon May 10 05:43:08 EDT 2004


Dan Morphis wrote:
> diff -u is the prefered way to receive patches as they are more readable.
> 
> -dan
> 
Sorry, the same thing with diff -u.
Will this patch applied ?

Chris
-------------- next part --------------
--- visualize.cpp	2004-01-31 07:35:10.000000000 +0100
+++ new/visualize.cpp	2004-05-07 11:05:59.333610000 +0200
@@ -23,6 +23,7 @@
 #include <iostream>
 using namespace std;
 
+#include <id3tag.h>
 #include <mythtv/mythcontext.h>
 
 Spectrum::Spectrum()
@@ -281,51 +282,94 @@
         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))
+    // If the size/file has changed do it again
+    if (filename != curfile || cursize != size)
     {
-        // Directory has changed
+        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;
-        // Get filter
-        QString namefilter = gContext->GetSetting("AlbumArtFilter",
+ 
+        // 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);
+            // 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;
+                     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();
     }
-    art.reset();
     return true;
 }
 


More information about the mythtv-dev mailing list