Skip to content

Commit 98fbf68

Browse files
committed
Updated artwork example
1 parent 7183adf commit 98fbf68

File tree

2 files changed

+17
-32
lines changed

2 files changed

+17
-32
lines changed

README.md

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@ TODO
232232
### Retrieving Metadata and Artwork from a media file
233233

234234
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.
235236

236237
```go
237238
package main
@@ -240,20 +241,13 @@ import (
240241
"log"
241242
"os"
242243

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"
245246
)
246247

247248
func main() {
248-
manager, err := media.NewManager()
249-
if err != nil {
250-
log.Fatal(err)
251-
}
252-
253249
// 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])
257251
if err != nil {
258252
log.Fatal(err)
259253
}
@@ -267,14 +261,13 @@ func main() {
267261
}
268262

269263
// 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)
276270
}
277-
log.Print("got artwork", mimetype, ext)
278271
}
279272
}
280273
```

cmd/examples/metadata/main.go

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,13 @@ import (
44
"log"
55
"os"
66

7-
media "github.com/mutablelogic/go-media"
8-
file "github.com/mutablelogic/go-media/pkg/file"
7+
// Packages
8+
ffmpeg "github.com/mutablelogic/go-media/pkg/ffmpeg"
99
)
1010

1111
func main() {
12-
manager, err := media.NewManager()
13-
if err != nil {
14-
log.Fatal(err)
15-
}
16-
1712
// Open a media file for reading. The format of the file is guessed.
18-
// Alteratively, you can pass a format as the second argument. Further optional
19-
// arguments can be used to set the format options.
20-
reader, err := manager.Open(os.Args[1], nil)
13+
reader, err := ffmpeg.Open(os.Args[1])
2114
if err != nil {
2215
log.Fatal(err)
2316
}
@@ -33,12 +26,11 @@ func main() {
3326
// Retrieve artwork by using the MetaArtwork key. The value is of type []byte.
3427
// which needs to be converted to an image. There is a utility method to
3528
// detect the image type.
36-
for _, artwork := range reader.Metadata(media.MetaArtwork) {
37-
mimetype, ext, err := file.MimeType(artwork.Value().([]byte))
38-
if err != nil {
39-
log.Fatal(err)
29+
for _, artwork := range reader.Metadata(ffmpeg.MetaArtwork) {
30+
mimetype := artwork.Value()
31+
if mimetype != "" {
32+
log.Print("We got some artwork of mimetype ", mimetype)
4033
}
41-
log.Print("got artwork", mimetype, ext)
4234
}
4335

4436
}

0 commit comments

Comments
 (0)