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