@@ -29,15 +29,9 @@ type Ffprober interface {
29
29
}
30
30
31
31
// filePath used to derive info
32
- func New (filePath string , i * Info ) * Metadata {
33
- // create info if not passed as arg
34
- if i == nil {
35
- i = & Info {}
36
- }
37
-
38
- // create new metadata
32
+ func New (filePath string ) * Metadata {
39
33
var file string
40
- m := & Metadata { Filepath : filePath , Info : i }
34
+ m := & Metadata { Filepath : filePath , Info : & Info {} }
41
35
42
36
// derive file info if has file extension
43
37
if regexp .MustCompile (`\.[A-Za-z0-9]{1,5}$` ).FindString (filePath ) != "" {
@@ -56,11 +50,11 @@ func New(filePath string, i *Info) *Metadata {
56
50
}
57
51
58
52
// build info from ffprobe.Tags
59
- func probeTagsToInfo (p * ffprobe.Tags ) * Info {
53
+ func ProbeTagsToInfo (p * ffprobe.Tags ) * Info {
60
54
i := & Info { Artist : p .Artist , Disc : p .Disc ,
61
55
Track : p .Track , Title : p .Title }
62
56
63
- i .Album = i .MatchCleanAlbum (p .Album )
57
+ i .Album = strings . TrimSpace ( i .MatchCleanAlbum (p .Album ) )
64
58
return i
65
59
}
66
60
@@ -109,24 +103,6 @@ func (m *Metadata) fromFile(s string) {
109
103
m .Info .Title = matchAlbumOrTitle (s )
110
104
}
111
105
112
- func (m * Metadata ) Probe (ffp Ffprober , fp string ) error {
113
- // info from embedded tags within audio file
114
- d , err := ffp .GetData (fp )
115
- if err != nil {
116
- return err
117
- }
118
-
119
- // if artist not yet specified, use ffprobe artist tag
120
- if m .Info .Artist == "" {
121
- m .Info .Artist = d .Format .Tags .Artist
122
- }
123
-
124
- // combine info w/ embedded tags
125
- m .Info , m .Match = m .Info .matchProbeInfo (probeTagsToInfo (d .Format .Tags ))
126
-
127
- return nil
128
- }
129
-
130
106
func (i * Info ) MatchCleanAlbum (s string ) string {
131
107
s = i .matchDiscOnly (s )
132
108
s = i .matchDate (s )
@@ -169,15 +145,25 @@ func (i *Info) ToFile() string {
169
145
170
146
// compare file & path info against ffprobe.Tags info and combine into best
171
147
// return includes boolean if info sources match (no update necessary)
172
- func (i * Info ) matchProbeInfo (p * Info ) (* Info , bool ) {
148
+ func (i * Info ) MatchBestInfo (c , p * Info ) (* Info , bool ) {
149
+ // set custom artist
150
+ if len (c .Artist ) > 0 {
151
+ i .Artist = c .Artist
152
+ }
153
+
154
+ // set custom album
155
+ if len (c .Album ) > 0 {
156
+ i .Album = c .Album
157
+ }
158
+
173
159
// compare using safeFilename since info is derived from filename
174
160
compare := p
175
161
compare .Album = safeFilename (compare .Album )
176
162
compare .Title = safeFilename (compare .Title )
177
163
178
164
if * i != * compare {
179
165
// info overrides probe for Artist
180
- if p .Artist != i .Artist {
166
+ if len ( p .Artist ) == 0 || len ( c .Artist ) > 0 {
181
167
p .Artist = i .Artist
182
168
}
183
169
@@ -198,13 +184,10 @@ func (i *Info) matchProbeInfo(p *Info) (*Info, bool) {
198
184
p .Track = i .Track
199
185
}
200
186
201
- // TODO: use album of source that derived the most info
202
- p .Album = strings .TrimSpace (p .Album )
203
- if len (p .Album ) < len (i .Album ) {
187
+ if (len (p .Album ) < len (i .Album )) || len (c .Album ) > 0 {
204
188
p .Album = i .Album
205
189
}
206
190
207
- // use the longer title
208
191
if len (p .Title ) < len (i .Title ) {
209
192
p .Title = i .Title
210
193
}
0 commit comments