mirror of
https://github.com/rclone/rclone.git
synced 2024-12-22 07:01:46 +01:00
serve dlna: sort the directory entries by directories first then alphabetically by name
Some media boxes don't sort the items returned from the DLNA server, so sort them here, directories first then alphabetically by name. See: https://forum.rclone.org/t/serve-dlna-files-order-directories-first/47790
This commit is contained in:
parent
874d66658e
commit
b4ef890aa0
@ -11,6 +11,7 @@ import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/anacrolix/dms/dlna"
|
||||
@ -158,6 +159,18 @@ func (cds *contentDirectoryService) readContainer(o object, host string) (ret []
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the directory entries by directories first then alphabetically by name
|
||||
sort.Slice(dirEntries, func(i, j int) bool {
|
||||
iNode, jNode := dirEntries[i], dirEntries[j]
|
||||
iIsDir, jIsDir := iNode.IsDir(), jNode.IsDir()
|
||||
if iIsDir && !jIsDir {
|
||||
return true
|
||||
} else if !iIsDir && jIsDir {
|
||||
return false
|
||||
}
|
||||
return strings.ToLower(iNode.Name()) < strings.ToLower(jNode.Name())
|
||||
})
|
||||
|
||||
dirEntries, mediaResources := mediaWithResources(dirEntries)
|
||||
for _, de := range dirEntries {
|
||||
child := object{
|
||||
|
Loading…
Reference in New Issue
Block a user