-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmf.go
91 lines (78 loc) · 1.61 KB
/
mf.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
package mf
import (
"os"
"path/filepath"
"regexp"
)
// type Media int
// const (
// Music Media = iota
// Video
// )
// type Library struct {
// Name string
// Path string
// Kind Media
// }
type Music interface {
FileType() string
Title() string
Album() string
Artist() string
AlbumArtist() string
Composer() string
Year() int
Genre() string
Track() (int, int)
Disc() (int, int)
// Picture() *Picture
Lyrics() string
Tags() map[string]string
}
type Track interface {
Track() int
Type() string
Codec() string
Language() string
Pixel() (int, int)
Display() (int, int)
SamplingFrequency() int
Channels() int
}
type Video interface {
FileType() string
Tracks() []Track
}
type VideoFunc func(path string, video Video, err error) error
func ScanVideo(path string, scanFun VideoFunc) {
filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
matched, err := regexp.MatchString("\\.(mkv)$", path)
if !matched {
return nil
}
file, err := os.Open(path)
if err != nil {
return nil
}
defer file.Close()
video, err := parseMatroska(file)
return scanFun(path, video, err)
})
}
type MusicFunc func(path string, music Music, err error) error
func ScanMusic(path string, scanFn MusicFunc) {
filepath.Walk(path, func(path string, f os.FileInfo, err error) error {
//matched, err := regexp.MatchString("\\.(mp3|m4a|ogg)$", path)
matched, err := regexp.MatchString("\\.(mp3)$", path)
if !matched {
return nil
}
file, err := os.Open(path)
if err != nil {
return nil
}
defer file.Close()
music, err := parseMusic(file)
return scanFn(path, music, err)
})
}