Lines 65-93
Link Here
|
65 |
static void addMetaField(metadata_fields_t field, MP4FileHandle mp4, Ref<CdsItem> item) |
65 |
static void addMetaField(metadata_fields_t field, MP4FileHandle mp4, Ref<CdsItem> item) |
66 |
{ |
66 |
{ |
67 |
String value; |
67 |
String value; |
68 |
char* mp4_retval = NULL; |
|
|
69 |
u_int16_t track; |
70 |
u_int16_t total_tracks; |
71 |
|
72 |
Ref<StringConverter> sc = StringConverter::i2i(); |
68 |
Ref<StringConverter> sc = StringConverter::i2i(); |
73 |
|
69 |
|
|
|
70 |
const MP4Tags* new_tags = MP4TagsAlloc(); |
71 |
|
72 |
if (!MP4TagsFetch(new_tags, mp4)) |
73 |
return; |
74 |
|
74 |
switch (field) |
75 |
switch (field) |
75 |
{ |
76 |
{ |
76 |
case M_TITLE: |
77 |
case M_TITLE: |
77 |
MP4GetMetadataName(mp4, &mp4_retval); |
78 |
value = new_tags->name; |
78 |
break; |
79 |
break; |
79 |
case M_ARTIST: |
80 |
case M_ARTIST: |
80 |
MP4GetMetadataArtist(mp4, &mp4_retval); |
81 |
value = new_tags->artist; |
81 |
break; |
82 |
break; |
82 |
case M_ALBUM: |
83 |
case M_ALBUM: |
83 |
MP4GetMetadataAlbum(mp4, &mp4_retval); |
84 |
value = new_tags->album; |
84 |
break; |
85 |
break; |
85 |
case M_DATE: |
86 |
case M_DATE: |
86 |
MP4GetMetadataYear(mp4, &mp4_retval); |
87 |
value = new_tags->releaseDate; |
87 |
if (mp4_retval) |
88 |
if (value.length() > 0) |
88 |
{ |
89 |
{ |
89 |
value = mp4_retval; |
|
|
90 |
free(mp4_retval); |
91 |
if (string_ok(value)) |
90 |
if (string_ok(value)) |
92 |
value = value + "-01-01"; |
91 |
value = value + "-01-01"; |
93 |
else |
92 |
else |
Lines 95-128
Link Here
|
95 |
} |
94 |
} |
96 |
break; |
95 |
break; |
97 |
case M_GENRE: |
96 |
case M_GENRE: |
98 |
MP4GetMetadataGenre(mp4, &mp4_retval); |
97 |
value = new_tags->genre; |
99 |
break; |
98 |
break; |
100 |
case M_DESCRIPTION: |
99 |
case M_DESCRIPTION: |
101 |
MP4GetMetadataComment(mp4, &mp4_retval); |
100 |
value = new_tags->comments; |
102 |
break; |
101 |
break; |
103 |
case M_TRACKNUMBER: |
102 |
case M_TRACKNUMBER: |
104 |
MP4GetMetadataTrack(mp4, &track, &total_tracks); |
103 |
if (new_tags->track) |
105 |
if (track > 0) |
|
|
106 |
{ |
104 |
{ |
107 |
value = String::from(track); |
105 |
value = String::from(new_tags->track->index); |
108 |
item->setTrackNumber((int)track); |
106 |
item->setTrackNumber((int)new_tags->track->index); |
109 |
} |
107 |
} |
110 |
else |
108 |
else |
|
|
109 |
{ |
110 |
MP4TagsFree( new_tags ); |
111 |
return; |
111 |
return; |
|
|
112 |
} |
112 |
break; |
113 |
break; |
113 |
default: |
114 |
default: |
|
|
115 |
MP4TagsFree( new_tags ); |
114 |
return; |
116 |
return; |
115 |
} |
117 |
} |
116 |
|
118 |
|
117 |
if ((field != M_DATE) && (field != M_TRACKNUMBER) && |
119 |
MP4TagsFree( new_tags ); |
118 |
(mp4_retval)) |
|
|
119 |
{ |
120 |
value = mp4_retval; |
121 |
free(mp4_retval); |
122 |
} |
123 |
|
124 |
value = trim_string(value); |
120 |
value = trim_string(value); |
125 |
|
121 |
|
126 |
if (string_ok(value)) |
122 |
if (string_ok(value)) |
127 |
{ |
123 |
{ |
128 |
item->setMetadata(MT_KEYS[field].upnp, sc->convert(value)); |
124 |
item->setMetadata(MT_KEYS[field].upnp, sc->convert(value)); |
Lines 190-203
Link Here
|
190 |
} |
186 |
} |
191 |
|
187 |
|
192 |
#if defined(HAVE_MAGIC) |
188 |
#if defined(HAVE_MAGIC) |
193 |
u_int8_t *art_data; |
189 |
void *art_data = 0; |
194 |
u_int32_t art_data_len; |
190 |
u_int32_t art_data_len = 0; |
195 |
String art_mimetype; |
191 |
String art_mimetype; |
|
|
192 |
|
193 |
const MP4Tags* new_tags = MP4TagsAlloc(); |
194 |
MP4TagsFetch(new_tags, mp4); |
195 |
if (new_tags->artworkCount) |
196 |
{ |
197 |
art_data = new_tags->artwork->data; |
198 |
art_data_len = new_tags->artwork->size; |
199 |
} |
196 |
#ifdef HAVE_MP4_GET_METADATA_COVER_ART_COUNT |
200 |
#ifdef HAVE_MP4_GET_METADATA_COVER_ART_COUNT |
197 |
if (MP4GetMetadataCoverArtCount(mp4) && |
201 |
if (new_tags->artworkCount && art_data_len > 0) |
198 |
MP4GetMetadataCoverArt(mp4, &art_data, &art_data_len)) |
|
|
199 |
#else |
200 |
MP4GetMetadataCoverArt(mp4, &art_data, &art_data_len); |
201 |
#endif |
202 |
#endif |
202 |
{ |
203 |
{ |
203 |
if (art_data) |
204 |
if (art_data) |
Lines 211-221
Link Here
|
211 |
} |
212 |
} |
212 |
catch (Exception ex) |
213 |
catch (Exception ex) |
213 |
{ |
214 |
{ |
214 |
free(art_data); |
215 |
MP4TagsFree(new_tags); |
215 |
throw ex; |
216 |
throw ex; |
216 |
} |
217 |
} |
217 |
|
218 |
|
218 |
free(art_data); |
|
|
219 |
if (art_mimetype != _(MIMETYPE_DEFAULT)) |
219 |
if (art_mimetype != _(MIMETYPE_DEFAULT)) |
220 |
{ |
220 |
{ |
221 |
Ref<CdsResource> resource(new CdsResource(CH_MP4)); |
221 |
Ref<CdsResource> resource(new CdsResource(CH_MP4)); |
Lines 225-230
Link Here
|
225 |
} |
225 |
} |
226 |
} |
226 |
} |
227 |
} |
227 |
} |
|
|
228 |
MP4TagsFree(new_tags); |
228 |
#endif |
229 |
#endif |
229 |
MP4Close(mp4); |
230 |
MP4Close(mp4); |
230 |
} |
231 |
} |
Lines 249-274
Link Here
|
249 |
|
250 |
|
250 |
if (ctype != ID3_ALBUM_ART) |
251 |
if (ctype != ID3_ALBUM_ART) |
251 |
throw _Exception(_("LibMP4V2Handler: got unknown content type: ") + ctype); |
252 |
throw _Exception(_("LibMP4V2Handler: got unknown content type: ") + ctype); |
|
|
253 |
|
254 |
const MP4Tags* new_tags = MP4TagsAlloc(); |
255 |
if (MP4TagsFetch(new_tags, mp4)) |
256 |
{ |
252 |
#ifdef HAVE_MP4_GET_METADATA_COVER_ART_COUNT |
257 |
#ifdef HAVE_MP4_GET_METADATA_COVER_ART_COUNT |
253 |
if (!MP4GetMetadataCoverArtCount(mp4)) |
258 |
if (!new_tags->artworkCount) |
254 |
throw _Exception(_("LibMP4V2Handler: resource has no album art information")); |
259 |
throw _Exception(_("LibMP4V2Handler: resource has no album art information")); |
255 |
#endif |
260 |
#endif |
256 |
u_int8_t *art_data; |
261 |
void *art_data = 0; |
257 |
u_int32_t art_data_len; |
262 |
u_int32_t art_data_len; |
258 |
if (MP4GetMetadataCoverArt(mp4, &art_data, &art_data_len)) |
263 |
|
259 |
{ |
264 |
const MP4TagArtwork* art = new_tags->artwork; |
260 |
if (art_data) |
265 |
art_data = art->data; |
|
|
266 |
art_data_len = art->size; |
267 |
if (art) |
261 |
{ |
268 |
{ |
262 |
*data_size = (off_t)art_data_len; |
269 |
if (art_data) |
263 |
Ref<IOHandler> h(new MemIOHandler((void *)art_data, art_data_len)); |
270 |
{ |
264 |
free(art_data); |
271 |
*data_size = (off_t)art_data_len; |
265 |
return h; |
272 |
Ref<IOHandler> h(new MemIOHandler(art_data, art_data_len)); |
|
|
273 |
MP4TagsFree(new_tags); |
274 |
return h; |
275 |
} |
266 |
} |
276 |
} |
|
|
277 |
MP4TagsFree(new_tags); |
267 |
} |
278 |
} |
268 |
|
|
|
269 |
throw _Exception(_("LibMP4V2Handler: could not serve album art " |
279 |
throw _Exception(_("LibMP4V2Handler: could not serve album art " |
270 |
"for file") + item->getLocation() + |
280 |
"for file") + item->getLocation() + |
271 |
" - embedded image not found"); |
281 |
" - embedded image not found"); |
272 |
} |
282 |
} |
273 |
|
283 |
|
274 |
#endif // HAVE_LIBMP4V2 |
284 |
#endif // HAVE_LIBMP4V2 |