forked from clandry94/agraph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
agraph.go
61 lines (49 loc) · 824 Bytes
/
agraph.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
package agraph
import (
id3 "github.com/clandry94/id3-go"
"fmt"
"os"
)
type Graph struct {
MetaData MetaData
Codec Codec
source *[]byte
sink *[]byte
filterGraph *FilterGraph
}
type MetaData struct {
Id3 id3.Tagger
Filepath string
Size int64
}
func New(filepath string) (*Graph, error) {
fileInfo, err := os.Stat(filepath)
if err != nil {
fmt.Println(err)
return nil, err
}
file, err := os.OpenFile(filepath, os.O_RDWR, 0666)
if err != nil {
return nil, err
}
id3Data, err := id3.Parse(file)
if err != nil {
fmt.Println(err)
return nil, err
}
meta := MetaData{
Id3: id3Data.Tagger,
Filepath: filepath,
Size: fileInfo.Size(),
}
codec := Mp3{
file: file,
}
return &Graph{
MetaData: meta,
Codec: codec,
source: nil,
sink: nil,
filterGraph: nil,
}, nil
}