Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

[embedded art] read coverart data in tags into the MusicInfoTag rathe…

…r than caching directly
  • Loading branch information...
commit fd0f6264d32f6cd07348110bbedb694da5b71f59 1 parent 268a0ab
authored May 26, 2012
31  xbmc/music/tags/FlacTag.cpp
@@ -26,7 +26,6 @@
26 26
 #include "filesystem/File.h"
27 27
 #include "utils/log.h"
28 28
 #include "utils/EndianSwap.h"
29  
-#include "ThumbnailCache.h"
30 29
 
31 30
 
32 31
 #define BYTES_TO_CHECK_FOR_BAD_TAGS 16384
@@ -112,13 +111,7 @@ bool CFlacTag::Read(const CStdString& strFile)
112 111
   if (!cover)
113 112
     cover = third_cover;
114 113
 
115  
-  CStdString strCoverArt;
116  
-  if (!m_musicInfoTag.GetAlbum().IsEmpty() && (!m_musicInfoTag.GetAlbumArtist().empty() || !m_musicInfoTag.GetArtist().empty()))
117  
-    strCoverArt = CThumbnailCache::GetAlbumThumb(&m_musicInfoTag);
118  
-  else
119  
-    strCoverArt = CThumbnailCache::GetMusicThumb(m_musicInfoTag.GetURL());
120  
-
121  
-  if (cover && !CUtil::ThumbExists(strCoverArt))
  114
+  if (cover)
122 115
   {
123 116
     char info[1024];
124 117
     m_file->Seek(cover, SEEK_SET);
@@ -138,29 +131,21 @@ bool CFlacTag::Read(const CStdString& strFile)
138 131
     if (size > 1023)
139 132
       m_file->Seek(size - 1023, SEEK_CUR);
140 133
 
141  
-    int nPos = mimeType.Find('/');
142  
-    if (nPos > -1)
143  
-      mimeType.Delete(0, nPos + 1);
144  
-
145 134
     // and now our actual image info
146 135
     unsigned int picInfo[4];
147 136
     m_file->Read(picInfo, 16);
148 137
 
149 138
     unsigned int picSize = ReadUnsigned();
150  
-    BYTE *picData = new BYTE[picSize];
151  
-    if (picData)
  139
+    m_musicInfoTag.SetCoverArtInfo(picSize, mimeType);
  140
+    if (m_art)
152 141
     {
153  
-      m_file->Read(picData, picSize);
154  
-      if (CPicture::CreateThumbnailFromMemory(picData, picSize, mimeType, strCoverArt))
155  
-      {
156  
-        CUtil::ThumbCacheAdd(strCoverArt, true);
157  
-      }
158  
-      else
  142
+      uint8_t *picData = new uint8_t[picSize];
  143
+      if (picData)
159 144
       {
160  
-        CUtil::ThumbCacheAdd(strCoverArt, false);
161  
-        CLog::Log(LOGERROR, "%s Unable to create album art for %s (extension=%s, size=%d)", __FUNCTION__, m_musicInfoTag.GetURL().c_str(), mimeType.c_str(), picSize);
  145
+        m_file->Read(picData, picSize);
  146
+        m_art->set(picData, picSize, mimeType);
  147
+        delete[] picData;
162 148
       }
163  
-      delete[] picData;
164 149
     }
165 150
   }
166 151
   return foundTag;
29  xbmc/music/tags/Id3Tag.cpp
@@ -27,7 +27,6 @@
27 27
 #include "guilib/LocalizeStrings.h"
28 28
 #include "utils/CharsetConverter.h"
29 29
 #include "utils/log.h"
30  
-#include "ThumbnailCache.h"
31 30
 
32 31
 #include <set>
33 32
 
@@ -168,34 +167,16 @@ bool CID3Tag::Parse()
168 167
       bFound = true;
169 168
   }
170 169
 
171  
-  // if we don't have an album tag, cache with the full file path so that
172  
-  // other non-tagged files don't get this album image
173  
-  CStdString strCoverArt;
174  
-  if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().empty() || !tag.GetArtist().empty()))
175  
-    strCoverArt = CThumbnailCache::GetAlbumThumb(&tag);
176  
-  else
177  
-    strCoverArt = CThumbnailCache::GetMusicThumb(tag.GetURL());
178  
-  if (bFound && !CUtil::ThumbExists(strCoverArt))
  170
+  if (bFound)
179 171
   {
180  
-    CStdString strExtension=GetPictureMimeType(pictype);
181  
-
182  
-    int nPos = strExtension.Find('/');
183  
-    if (nPos > -1)
184  
-      strExtension.Delete(0, nPos + 1);
185  
-
186 172
     id3_length_t nBufSize = 0;
187 173
     const BYTE* pPic = GetPictureData(pictype, &nBufSize );
  174
+    std::string mimeType = GetPictureMimeType(pictype);
188 175
     if (pPic != NULL && nBufSize > 0)
189 176
     {
190  
-      if (CPicture::CreateThumbnailFromMemory(pPic, nBufSize, strExtension, strCoverArt))
191  
-      {
192  
-        CUtil::ThumbCacheAdd(strCoverArt, true);
193  
-      }
194  
-      else
195  
-      {
196  
-        CUtil::ThumbCacheAdd(strCoverArt, false);
197  
-        CLog::Log(LOGERROR, "Tag loader mp3: Unable to create album art for %s (extension=%s, size=%lu)", tag.GetURL().c_str(), strExtension.c_str(), nBufSize);
198  
-      }
  177
+      tag.SetCoverArtInfo(nBufSize, mimeType);
  178
+      if (m_art)
  179
+        m_art->set(pPic, nBufSize, mimeType);
199 180
     }
200 181
   }
201 182
 
45  xbmc/music/tags/MusicInfoTagLoaderMP4.cpp
@@ -27,7 +27,6 @@
27 27
 #include "guilib/LocalizeStrings.h"
28 28
 #include "utils/AutoPtrHandle.h"
29 29
 #include "utils/log.h"
30  
-#include "ThumbnailCache.h"
31 30
 
32 31
 using namespace XFILE;
33 32
 using namespace AUTOPTR;
@@ -229,12 +228,18 @@ void CMusicInfoTagLoaderMP4::ParseTag( unsigned int metaKey, const char* pMetaDa
229 228
       // This cover-art handling is pretty much what was in the old MP4 tag processing code..
230 229
 
231 230
       // note that according to http://atomicparsley.sourceforge.net/mpeg-4files.html the type
232  
-      // of image (PNG=14 or JPG=13) is contained in pMetadata[-5] but we currently don't use this.
233  
-      m_thumbSize = metaSize;
234  
-      delete[] m_thumbData;
235  
-      m_thumbData = new BYTE[m_thumbSize];
236  
-      if (m_thumbData)
237  
-        memcpy(m_thumbData, pMetaData, metaSize);
  231
+      // of image (PNG=14 or JPG=13) is contained in pMetadata[-5]
  232
+      std::string mimeType;
  233
+      if (pMetaData[-5] == 13)
  234
+        mimeType = "image/jpeg";
  235
+      else if (pMetaData[-5] == 14)
  236
+        mimeType = "image/png";
  237
+      else
  238
+        CLog::Log(LOGDEBUG, "Unknown art mimetype %d", pMetaData[-5]);
  239
+
  240
+      tag.SetCoverArtInfo(metaSize, mimeType);
  241
+      if (art)
  242
+        art->set((const uint8_t*)pMetaData, metaSize, mimeType);
238 243
       break;
239 244
     }
240 245
   default:
@@ -386,35 +391,9 @@ bool CMusicInfoTagLoaderMP4::Load(const CStdString& strFileName, CMusicInfoTag&
386 391
     tag.SetURL(strFileName);
387 392
 
388 393
     // Now go parse our atom data
389  
-    m_thumbSize = false;
390  
-    m_thumbData = NULL;
391 394
     m_isCompilation = false;
392 395
     ParseAtom( 0, m_file.GetLength(), tag, art );
393 396
 
394  
-    if (m_thumbData)
395  
-    { // cache the thumb
396  
-      // if we don't have an album tag, cache with the full file path so that
397  
-      // other non-tagged files don't get this album image
398  
-      CStdString strCoverArt;
399  
-      if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().empty() || !tag.GetArtist().empty()))
400  
-        strCoverArt = CThumbnailCache::GetAlbumThumb(&tag);
401  
-      else
402  
-        strCoverArt = CThumbnailCache::GetMusicThumb(tag.GetURL());
403  
-      if (!CUtil::ThumbExists(strCoverArt))
404  
-      {
405  
-        if (CPicture::CreateThumbnailFromMemory( m_thumbData, m_thumbSize, "", strCoverArt ) )
406  
-        {
407  
-          CUtil::ThumbCacheAdd( strCoverArt, true );
408  
-        }
409  
-        else
410  
-        {
411  
-          CLog::Log(LOGDEBUG, "%s unable to cache thumb as %s", __FUNCTION__, strCoverArt.c_str());
412  
-          CUtil::ThumbCacheAdd( strCoverArt, false );
413  
-        }
414  
-      }
415  
-      delete[] m_thumbData;
416  
-    }
417  
-
418 397
     if (m_isCompilation)
419 398
     { // iTunes compilation flag is set - this could be a various artists file
420 399
       if (tag.GetAlbumArtist().empty())
2  xbmc/music/tags/MusicInfoTagLoaderMP4.h
@@ -40,8 +40,6 @@ class CMusicInfoTagLoaderMP4: public IMusicInfoTagLoader
40 40
   int GetILSTOffset( const char* pBuffer, int bufferSize );
41 41
   int ParseAtom( int64_t startOffset, int64_t stopOffset, CMusicInfoTag& tag, EmbeddedArt *art );
42 42
 
43  
-  unsigned int m_thumbSize;
44  
-  BYTE *m_thumbData;
45 43
   bool m_isCompilation;
46 44
 
47 45
   XFILE::CFile m_file;
34  xbmc/music/tags/MusicInfoTagLoaderWMA.cpp
@@ -28,7 +28,6 @@
28 28
 #include "utils/AutoPtrHandle.h"
29 29
 #include "utils/CharsetConverter.h"
30 30
 #include "utils/log.h"
31  
-#include "ThumbnailCache.h"
32 31
 #include "utils/StringUtils.h"
33 32
 
34 33
 using namespace AUTOPTR;
@@ -514,36 +513,11 @@ void CMusicInfoTagLoaderWMA::SetTagValueBinary(const CStdString& strFrameName, c
514 513
     // Cover Front (3) or Other (0) as the cover.
515 514
     if (picture.bPictureType == 3 || picture.bPictureType == 0) // Cover Front
516 515
     {
517  
-      CStdString strExtension(picture.pwszMIMEType);
518  
-      // if we don't have an album tag, cache with the full file path so that
519  
-      // other non-tagged files don't get this album image
520  
-      CStdString strCoverArt;
521  
-      if (!tag.GetAlbum().IsEmpty() && (!tag.GetAlbumArtist().empty() || !tag.GetArtist().empty()))
522  
-        strCoverArt = CThumbnailCache::GetAlbumThumb(&tag);
523  
-      else
524  
-        strCoverArt = CThumbnailCache::GetMusicThumb(tag.GetURL());
525  
-      if (!CUtil::ThumbExists(strCoverArt))
  516
+      if (picture.pbData != NULL && picture.dwDataLen > 0)
526 517
       {
527  
-        int nPos = strExtension.Find('/');
528  
-        if (nPos > -1)
529  
-          strExtension.Delete(0, nPos + 1);
530  
-
531  
-        if (picture.pbData != NULL && picture.dwDataLen > 0)
532  
-        {
533  
-          if (CPicture::CreateThumbnailFromMemory(picture.pbData, picture.dwDataLen, strExtension, strCoverArt))
534  
-          {
535  
-            CUtil::ThumbCacheAdd(strCoverArt, true);
536  
-          }
537  
-          else
538  
-          {
539  
-            CUtil::ThumbCacheAdd(strCoverArt, false);
540  
-            CLog::Log(LOGERROR, "Tag loader wma: "
541  
-                                "Unable to create album art for %s "
542  
-                                "(extension=%s, size=%u)",
543  
-                      tag.GetURL().c_str(), strExtension.c_str(),
544  
-                      picture.dwDataLen);
545  
-          }
546  
-        }
  518
+        tag.SetCoverArtInfo(picture.dwDataLen, picture.pwszMIMEType);
  519
+        if (art)
  520
+          art->set(picture.pbData, picture.dwDataLen, picture.pwszMIMEType);
547 521
       }
548 522
     }
549 523
   }

0 notes on commit fd0f626

Please sign in to comment.
Something went wrong with that request. Please try again.