-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
72 lines (58 loc) · 1.39 KB
/
main.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
package main
import (
"fmt"
"log"
"os"
"flag"
"path/filepath"
"github.com/dhowden/tag"
"gopkg.in/alessio/shellescape.v1"
)
func main() {
var files []string
verbose := flag.Bool("verbose", false, "increase verbosity")
printFrames := flag.Bool("print-frames", false, "print all id3 frames in file")
matchText := flag.String("match-text", "", "find text in frame (requires match-frame)")
matchFrame := flag.String("match-frame", "", "find text in frame (requires match-frame)")
flag.Parse()
if *verbose {
fmt.Printf("Searching for %s = %s\n\n", *matchFrame, *matchText)
}
root := "./"
err := filepath.Walk(root, func(path string, info os.FileInfo, err error) error {
files = append(files, path)
return nil
})
if err != nil {
panic(err)
}
for _, file := range files {
if len(file) > 3 {
if file[len(file)-4:len(file)] == ".mp3" {
fileContents, err := os.Open(file) // For read access.
if err != nil {
log.Print(err)
} else {
m, err := tag.ReadFrom(fileContents)
if err != nil {
log.Print(err)
} else {
if *printFrames {
fmt.Println()
fmt.Println(file)
}
for k, v := range m.Raw() {
if *printFrames {
fmt.Printf("%s: %s\n", k, v)
} else {
if k == *matchFrame && v == *matchText {
fmt.Println(shellescape.Quote(file))
}
}
}
}
}
}
}
}
}