summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b>2005-10-06 12:35:35 +0000
committerLarsAC <LarsAC@e10066b5-e1e2-0310-b819-94efdf66514b>2005-10-06 12:35:35 +0000
commitb32b5e5c224447e86b674e1fb068f672902b3e87 (patch)
tree1ddde2c2d6d7c54b9a6d3e190bc49463026b5090
parent49bfd5b60aaa86f9aa820f549ff597e1b47a0339 (diff)
downloadvdr-plugin-muggle-b32b5e5c224447e86b674e1fb068f672902b3e87.tar.gz
vdr-plugin-muggle-b32b5e5c224447e86b674e1fb068f672902b3e87.tar.bz2
Add tested code to obtain images from id3v2 tags
git-svn-id: https://vdr-muggle.svn.sourceforge.net/svnroot/vdr-muggle/trunk/muggle-plugin@843 e10066b5-e1e2-0310-b819-94efdf66514b
-rw-r--r--mg_image_provider.c86
1 files changed, 53 insertions, 33 deletions
diff --git a/mg_image_provider.c b/mg_image_provider.c
index 7406383..462e17d 100644
--- a/mg_image_provider.c
+++ b/mg_image_provider.c
@@ -201,58 +201,78 @@ void mgImageProvider::fillImageList( string dir )
}
}
-string mgImageProvider::extractImagesFromTag( string f )
+void writeImage( TagLib::ByteVector &image, int num, string &image_cache )
+{
+ char* image_data = image.data();
+ int len = image.size();
+
+ // save image_data to temporary file
+ char *buf;
+ asprintf( &buf, "%s/image-%d.jpg", image_cache.c_str(), num );
+
+ FILE *f = fopen( buf, "w+" );
+ fwrite( image_data, sizeof(char), len, f );
+ fclose( f );
+ free( buf );
+}
+
+string treatFrameList( TagLib::ID3v2::FrameList &l, string &image_cache )
{
- // currently not working due to bug #113770 in taglib
- // see http://bugs.kde.org/show_bug.cgi?id=113770
- return "";
+ string result;
+
+ if( !l.isEmpty() )
+ {
+ TagLib::ID3v2::FrameList::ConstIterator it = l.begin();
+
+ int num = 0;
+ while( !(it == l.end()) )
+ {
+ TagLib::ID3v2::AttachedPictureFrame *picframe = (TagLib::ID3v2::AttachedPictureFrame*) (*it);
+
+ TagLib::ByteVector image = picframe->picture();
+ writeImage( image, num, image_cache );
+
+ it++;
+ num++;
+ }
+ result = image_cache;
+ }
+ else
+ {
+ result = "";
+ }
+ return result;
+}
+
+string mgImageProvider::extractImagesFromTag( string f )
+{
TagLib::ID3v2::FrameList l;
const char *filename = f.c_str();
+ string image_cache = string( the_setup.ImageCacheDir );
+ string dir = "";
if( !strcasecmp(extension(filename), "flac") )
{
TagLib::FLAC::File f(filename);
l = f.ID3v2Tag()->frameListMap()["APIC"];
+ dir = treatFrameList( l, image_cache );
}
- else if ( !strcasecmp(extension(filename), "mp3") )
+ else if( !strcasecmp(extension(filename), "mp3") )
{
TagLib::MPEG::File f(filename);
l = f.ID3v2Tag()->frameListMap()["APIC"];
+ dir = treatFrameList( l, image_cache );
}
else if( !strcasecmp(extension(filename), "ogg") )
{
TagLib::Vorbis::File f(filename);
// l = f.ID3v2Tag()->frameListMap()["APIC"];
+ dir = treatFrameList( l, image_cache );
}
-
- string image_cache = string( the_setup.ImageCacheDir ); // TODO: obtain from setup!
- if( !l.isEmpty() )
- {
- TagLib::ID3v2::FrameList::ConstIterator it = l.begin();
- int num = 0;
- for(; it != l.end(); it++)
- {
- TagLib::ID3v2::AttachedPictureFrame *picframe = (TagLib::ID3v2::AttachedPictureFrame*) (*it);
- TagLib::ByteVector image = picframe->picture();
- char* image_data = image.data();
-
- // save image_data to temporary file
- char *buf;
- asprintf( &buf, "%s/image-%d.jpg", image_cache.c_str(), num );
- FILE *f = fopen( buf, "w+" );
- fprintf( f, "%s", image_data );
- fclose( f );
- free( buf );
-
- num ++;
- }
- return image_cache;
- }
- else
- {
- return "";
- }
+
+ // returns empty if no images were found in tags
+ return dir;
}
string mgImageProvider::getDefaultImage()