-
Notifications
You must be signed in to change notification settings - Fork 1
/
acoustid.go
98 lines (83 loc) · 1.84 KB
/
acoustid.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Package acoustid is not production ready.
package acoustid
// TODO: replace types with MusicBrainz types? Or keep it independent? See how
// much overlaps. Use a design similar to gomusicbrainz.
import (
"encoding/json"
"io/ioutil"
"net/http"
"strconv"
)
const (
// ACOUSTID_URI is the root URI for all the AcoustID requests.
ACOUSTID_URI = "http://api.acoustid.org/v2/lookup?client="
// ACOUSTID_LOOKUP defines the standard lookup used throughout this package.
// Both release and recording IDs are required by MusicBrainz.
ACOUSTID_LOOKUP = "&meta=recordings+releases+tracks"
)
type Date struct {
Month int
Day int
Year int
}
type ReleaseEvent struct {
Date Date
Country string
}
type Track struct {
Position int
Artists []Artist
ID string
Title string
}
type Medium struct {
Position int
Tracks []Track
Track_count int
Format string
}
type Release struct {
Track_count int
ReleaseEvents []ReleaseEvent
Country string
Title string
Artists []Artist
Date Date
MediumCount int
Mediums []Medium
ID string
}
type Artist struct {
ID string
Name string
}
type Recording struct {
Releases []Release
Artists []Artist
Duration int
Title string
ID string
}
type Result struct {
Recordings []Recording
Score float64
ID string
}
type Meta struct {
Results []Result
Status string
Error struct{ Message string }
}
func Get(acoustIDKey string, fingerprint string, duration int) (metadata Meta, err error) {
resp, err := http.DefaultClient.Get(ACOUSTID_URI + acoustIDKey + ACOUSTID_LOOKUP + "&duration=" + strconv.Itoa(duration) + "&fingerprint=" + fingerprint)
if err != nil {
return
}
defer resp.Body.Close()
buf, err := ioutil.ReadAll(resp.Body)
if err != nil {
return
}
err = json.Unmarshal(buf, &metadata)
return
}