|
@@ -2,6 +2,7 @@ package read
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
"os"
|
|
"os"
|
|
|
|
|
+ "fmt"
|
|
|
|
|
|
|
|
tag "github.com/dhowden/tag"
|
|
tag "github.com/dhowden/tag"
|
|
|
|
|
|
|
@@ -13,16 +14,6 @@ type Song struct {
|
|
|
length int
|
|
length int
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func getSongDuration(file *os.File, tags tag.Metadata) int {
|
|
|
|
|
- switch tags.Format() {
|
|
|
|
|
- case "VORBIS":
|
|
|
|
|
- result, _ := duration.GetSongDurationVorbis(file.Name())
|
|
|
|
|
- return result
|
|
|
|
|
- default:
|
|
|
|
|
- return 0
|
|
|
|
|
- }
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
func ReadFile(fileName string) (song *Song, err error) {
|
|
func ReadFile(fileName string) (song *Song, err error) {
|
|
|
file, errFile := os.Open(fileName)
|
|
file, errFile := os.Open(fileName)
|
|
|
if errFile != nil {
|
|
if errFile != nil {
|
|
@@ -39,8 +30,35 @@ func ReadFile(fileName string) (song *Song, err error) {
|
|
|
title: tags.Title(),
|
|
title: tags.Title(),
|
|
|
artist: tags.Artist(),
|
|
artist: tags.Artist(),
|
|
|
album: tags.Album(),
|
|
album: tags.Album(),
|
|
|
- length: getSongDuration(file, tags),
|
|
|
|
|
|
|
+ length: duration.GetSongDuration(file, tags),
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
return &result, nil
|
|
return &result, nil
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func ReadMultipleFiles(files chan string, doneChan chan bool) (chan *Song, chan bool) {
|
|
|
|
|
+ songs := make(chan *Song)
|
|
|
|
|
+ processed := make(chan bool)
|
|
|
|
|
+
|
|
|
|
|
+ done := false
|
|
|
|
|
+
|
|
|
|
|
+ go func() {
|
|
|
|
|
+ for !done {
|
|
|
|
|
+ select {
|
|
|
|
|
+ case file := <- files:
|
|
|
|
|
+ song, err := ReadFile(file)
|
|
|
|
|
+ if err == nil {
|
|
|
|
|
+ songs <- song
|
|
|
|
|
+ } else {
|
|
|
|
|
+ fmt.Printf("Error reading file (%s): %s", file, err)
|
|
|
|
|
+ }
|
|
|
|
|
+ case <- doneChan:
|
|
|
|
|
+ done = true
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ processed <- true
|
|
|
|
|
+ }()
|
|
|
|
|
+
|
|
|
|
|
+ return songs, processed
|
|
|
|
|
+}
|