|
|
|
@ -54,6 +54,7 @@ func readMetadata(f *os.File) *metadata {
|
|
|
|
|
type libraryEntry struct { |
|
|
|
|
File os.FileInfo |
|
|
|
|
Path string |
|
|
|
|
RealPath string |
|
|
|
|
Metadata *metadata |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -78,11 +79,25 @@ func scanFolder(scanPath string) []*libraryEntry {
|
|
|
|
|
var entries []*libraryEntry |
|
|
|
|
for _, fileInfo := range files { |
|
|
|
|
p := path.Join(scanPath, fileInfo.Name()) |
|
|
|
|
var r string |
|
|
|
|
|
|
|
|
|
b := path.Base(fileInfo.Name()) |
|
|
|
|
if fileInfo.IsDir() { |
|
|
|
|
if fileInfo.Mode()&os.ModeSymlink != 0 { |
|
|
|
|
r, err = os.Readlink(p) |
|
|
|
|
if err != nil { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if !path.IsAbs(r) { |
|
|
|
|
r = path.Join(scanPath, r) |
|
|
|
|
} |
|
|
|
|
} else { |
|
|
|
|
r = p |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
b := path.Base(p) |
|
|
|
|
if fileInfo.IsDir() || fileInfo.Mode()&os.ModeSymlink != 0 { |
|
|
|
|
if b != "" && (b[0] != '.' || showHiddenFolders) { |
|
|
|
|
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, Metadata: &metadata{Title: strings.TrimSpace(fileInfo.Name())}}) |
|
|
|
|
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, RealPath: r, Metadata: &metadata{Title: strings.TrimSpace(fileInfo.Name())}}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
continue |
|
|
|
@ -90,19 +105,21 @@ func scanFolder(scanPath string) []*libraryEntry {
|
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
f, err := os.Open(p) |
|
|
|
|
f, err := os.Open(r) |
|
|
|
|
if err != nil { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
metadata := readMetadata(f) |
|
|
|
|
f.Close() |
|
|
|
|
|
|
|
|
|
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, Metadata: metadata}) |
|
|
|
|
entries = append(entries, &libraryEntry{File: fileInfo, Path: p, RealPath: r, Metadata: metadata}) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
sort.Slice(entries, func(i, j int) bool { |
|
|
|
|
if entries[i].File.IsDir() != entries[j].File.IsDir() { |
|
|
|
|
return entries[i].File.IsDir() |
|
|
|
|
iDir := entries[i].File.IsDir() || entries[i].File.Mode()&os.ModeSymlink != 0 |
|
|
|
|
jDir := entries[j].File.IsDir() || entries[j].File.Mode()&os.ModeSymlink != 0 |
|
|
|
|
if iDir != jDir { |
|
|
|
|
return iDir |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if entries[i].Metadata.Album != "" && strings.ToLower(entries[i].Metadata.Album) == strings.ToLower(entries[j].Metadata.Album) && (entries[i].Metadata.Track > 0 || entries[j].Metadata.Track > 0) { |
|
|
|
@ -120,14 +137,14 @@ func scanFolderRecursively(path string) []*libraryEntry {
|
|
|
|
|
|
|
|
|
|
scanFiles := scanFolder(path) |
|
|
|
|
for _, entry := range scanFiles { |
|
|
|
|
if !entry.File.IsDir() { |
|
|
|
|
if !entry.File.IsDir() && entry.File.Mode()&os.ModeSymlink == 0 { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
entries = append(entries, scanFolderRecursively(entry.Path)...) |
|
|
|
|
entries = append(entries, scanFolderRecursively(entry.RealPath)...) |
|
|
|
|
} |
|
|
|
|
for _, entry := range scanFiles { |
|
|
|
|
if entry.File.IsDir() { |
|
|
|
|
if entry.File.IsDir() || entry.File.Mode()&os.ModeSymlink != 0 { |
|
|
|
|
continue |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|