232
232
### Retrieving Metadata and Artwork from a media file
233
233
234
234
Here is an example of opening a media file and retrieving metadata and artwork.
235
+ You have to read the artwork separately from the metadata.
235
236
236
237
``` go
237
238
package main
@@ -240,20 +241,13 @@ import (
240
241
" log"
241
242
" os"
242
243
243
- media " github.com/mutablelogic/go-media "
244
- file " github.com/mutablelogic/go-media/pkg/file "
244
+ // Packages
245
+ ffmpeg " github.com/mutablelogic/go-media/pkg/ffmpeg "
245
246
)
246
247
247
248
func main () {
248
- manager , err := media.NewManager ()
249
- if err != nil {
250
- log.Fatal (err)
251
- }
252
-
253
249
// Open a media file for reading. The format of the file is guessed.
254
- // Alteratively, you can pass a format as the second argument. Further optional
255
- // arguments can be used to set the format options.
256
- reader , err := manager.Open (os.Args [1 ], nil )
250
+ reader , err := ffmpeg.Open (os.Args [1 ])
257
251
if err != nil {
258
252
log.Fatal (err)
259
253
}
@@ -267,14 +261,13 @@ func main() {
267
261
}
268
262
269
263
// Retrieve artwork by using the MetaArtwork key. The value is of type []byte.
270
- // which needs to be converted to an image. There is a utility method to
271
- // detect the image type.
272
- for _ , artwork := range reader. Metadata (media. MetaArtwork ) {
273
- mimetype , ext , err := file. MimeType (artwork. Value ().([] byte ))
274
- if err != nil {
275
- log.Fatal (err )
264
+ // which needs to be converted to an image.
265
+ for _ , artwork := range reader. Metadata (ffmpeg. MetaArtwork ) {
266
+ mimetype := artwork. Value ()
267
+ if mimetype != " " {
268
+ // Retrieve the data using the metadata.Bytes() method
269
+ log.Print ( " We got some artwork of mimetype " , mimetype )
276
270
}
277
- log.Print (" got artwork" , mimetype, ext)
278
271
}
279
272
}
280
273
```
0 commit comments