mirror of
https://github.com/tuxbox-neutrino/neutrino.git
synced 2025-09-01 01:41:23 +02:00
- audioplayer: show cover from id3-tag or folder.jpg in header
if exist a file called folder.jpg in same dir as the audiofile or a audiocover is defined in id3-tag it will be displayed in header. cover in tag is preferred. ported from mohusch. original patch by tangocash. thx!
This commit is contained in:
@@ -944,6 +944,7 @@ bool CMP3Dec::GetMetaData(FILE* in, const bool nice, CAudioMetaData* const m)
|
||||
{
|
||||
res = GetMP3Info(in, nice, m);
|
||||
GetID3(in, m);
|
||||
SaveCover(in, m);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -1344,6 +1345,82 @@ void CMP3Dec::GetID3(FILE* in, CAudioMetaData* const m)
|
||||
}
|
||||
}
|
||||
|
||||
bool CMP3Dec::SaveCover(FILE * in, CAudioMetaData * const m)
|
||||
{
|
||||
struct id3_frame const *frame;
|
||||
const char * coverfile = "/tmp/cover.jpg";
|
||||
|
||||
/* text information */
|
||||
struct id3_file *id3file = id3_file_fdopen(fileno(in), ID3_FILE_MODE_READONLY);
|
||||
|
||||
if(id3file == 0)
|
||||
{
|
||||
printf("CMP3Dec::SaveCover: error open id3 file\n");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
id3_tag * tag = id3_file_tag(id3file);
|
||||
if(tag)
|
||||
{
|
||||
frame = id3_tag_findframe(tag, "APIC", 0);
|
||||
|
||||
if (frame)
|
||||
{
|
||||
printf("CMP3Dec::SaveCover: Cover found\n");
|
||||
// Picture file data
|
||||
unsigned int j;
|
||||
union id3_field const *field;
|
||||
|
||||
for (j = 0; (field = id3_frame_field(frame, j)); j++)
|
||||
{
|
||||
switch (id3_field_type(field))
|
||||
{
|
||||
case ID3_FIELD_TYPE_BINARYDATA:
|
||||
id3_length_t size;
|
||||
id3_byte_t const *data;
|
||||
|
||||
data = id3_field_getbinarydata(field, &size);
|
||||
if ( data )
|
||||
{
|
||||
m->cover = coverfile;
|
||||
FILE * pFile;
|
||||
pFile = fopen ( coverfile , "wb" );
|
||||
fwrite (data , 1 , size , pFile );
|
||||
fclose (pFile);
|
||||
}
|
||||
break;
|
||||
|
||||
case ID3_FIELD_TYPE_INT8:
|
||||
//pic->type = id3_field_getint(field);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
id3_tag_delete(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
printf("CMP3Dec::SaveCover: error open id3 tag\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
id3_finish_file(id3file);
|
||||
}
|
||||
|
||||
if(0)
|
||||
{
|
||||
printf("CMP3Dec::SaveCover:id3: not enough memory to display tag\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// this is a copy of static libid3tag function "finish_file"
|
||||
// which cannot be called from outside
|
||||
void id3_finish_file(struct id3_file* file)
|
||||
|
@@ -73,6 +73,7 @@ public:
|
||||
State* const state, CAudioMetaData* m,
|
||||
time_t* const t, unsigned int* const secondsToSkip);
|
||||
bool GetMetaData(FILE *in, const bool nice, CAudioMetaData* const m);
|
||||
bool SaveCover(FILE*, CAudioMetaData * const m);
|
||||
CMP3Dec(){};
|
||||
|
||||
};
|
||||
|
@@ -51,7 +51,7 @@ CAudioMetaData::CAudioMetaData( const CAudioMetaData& src )
|
||||
audio_start_pos( src.audio_start_pos ), vbr( src.vbr ),
|
||||
hasInfoOrXingTag( src.hasInfoOrXingTag ), artist( src.artist ),
|
||||
title( src.title ), album( src.album ), sc_station( src.sc_station ),
|
||||
date( src.date ), genre( src.genre ), track( src.track ),
|
||||
date( src.date ), genre( src.genre ), track( src.track ),cover(src.cover),
|
||||
changed( src.changed )
|
||||
{
|
||||
}
|
||||
@@ -81,6 +81,7 @@ void CAudioMetaData::operator=( const CAudioMetaData& src )
|
||||
date = src.date;
|
||||
genre = src.genre;
|
||||
track = src.track;
|
||||
cover = src.cover;
|
||||
sc_station = src.sc_station;
|
||||
changed = src.changed;
|
||||
}
|
||||
@@ -104,5 +105,6 @@ void CAudioMetaData::clear()
|
||||
date.clear();
|
||||
genre.clear();
|
||||
track.clear();
|
||||
cover.clear();
|
||||
changed=false;
|
||||
}
|
||||
|
@@ -84,6 +84,7 @@ public:
|
||||
std::string date;
|
||||
std::string genre;
|
||||
std::string track;
|
||||
std::string cover;
|
||||
bool changed;
|
||||
};
|
||||
#endif /* __AUDIO_METADATA__ */
|
||||
|
Reference in New Issue
Block a user