mirror of
https://github.com/rclone/rclone.git
synced 2025-01-05 05:49:33 +01:00
dlna: associate subtitles with all possible media nodes
When there was a .nfo and a .mp4, they were being associated only with the .nfo.
This commit is contained in:
parent
3f40849343
commit
8950b586c4
@ -192,14 +192,14 @@ func mediaWithResources(nodes vfs.Nodes) (vfs.Nodes, map[vfs.Node]vfs.Nodes) {
|
|||||||
media, mediaResources := vfs.Nodes{}, make(map[vfs.Node]vfs.Nodes)
|
media, mediaResources := vfs.Nodes{}, make(map[vfs.Node]vfs.Nodes)
|
||||||
|
|
||||||
// First, separate out the subtitles and media into maps, keyed by their lowercase base names.
|
// First, separate out the subtitles and media into maps, keyed by their lowercase base names.
|
||||||
mediaByName, subtitlesByName := make(map[string]vfs.Node), make(map[string]vfs.Node)
|
mediaByName, subtitlesByName := make(map[string]vfs.Nodes), make(map[string]vfs.Node)
|
||||||
for _, node := range nodes {
|
for _, node := range nodes {
|
||||||
baseName, ext := splitExt(strings.ToLower(node.Name()))
|
baseName, ext := splitExt(strings.ToLower(node.Name()))
|
||||||
switch ext {
|
switch ext {
|
||||||
case ".srt":
|
case ".srt":
|
||||||
subtitlesByName[baseName] = node
|
subtitlesByName[baseName] = node
|
||||||
default:
|
default:
|
||||||
mediaByName[baseName] = node
|
mediaByName[baseName] = append(mediaByName[baseName], node)
|
||||||
media = append(media, node)
|
media = append(media, node)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -207,11 +207,11 @@ func mediaWithResources(nodes vfs.Nodes) (vfs.Nodes, map[vfs.Node]vfs.Nodes) {
|
|||||||
// Find the associated media file for each subtitle
|
// Find the associated media file for each subtitle
|
||||||
for baseName, node := range subtitlesByName {
|
for baseName, node := range subtitlesByName {
|
||||||
// Find a media file with the same basename (video.mp4 for video.srt)
|
// Find a media file with the same basename (video.mp4 for video.srt)
|
||||||
mediaNode, found := mediaByName[baseName]
|
mediaNodes, found := mediaByName[baseName]
|
||||||
if !found {
|
if !found {
|
||||||
// Or basename of the basename (video.mp4 for video.en.srt)
|
// Or basename of the basename (video.mp4 for video.en.srt)
|
||||||
baseName, _ = splitExt(baseName)
|
baseName, _ = splitExt(baseName)
|
||||||
mediaNode, found = mediaByName[baseName]
|
mediaNodes, found = mediaByName[baseName]
|
||||||
}
|
}
|
||||||
|
|
||||||
// Just advise if no match found
|
// Just advise if no match found
|
||||||
@ -220,9 +220,12 @@ func mediaWithResources(nodes vfs.Nodes) (vfs.Nodes, map[vfs.Node]vfs.Nodes) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
fs.Debugf(mediaNode, "associating subtitle: %s", node.Name())
|
// Associate with all potential media nodes
|
||||||
|
fs.Debugf(mediaNodes, "associating subtitle: %s", node.Name())
|
||||||
|
for _, mediaNode := range mediaNodes {
|
||||||
mediaResources[mediaNode] = append(mediaResources[mediaNode], node)
|
mediaResources[mediaNode] = append(mediaResources[mediaNode], node)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return media, mediaResources
|
return media, mediaResources
|
||||||
}
|
}
|
||||||
|
0
cmd/serve/dlna/testdata/files/video.nfo
vendored
Normal file
0
cmd/serve/dlna/testdata/files/video.nfo
vendored
Normal file
Loading…
Reference in New Issue
Block a user