fix review regressions in titles and strm paths

This commit is contained in:
ShukeBta
2026-06-27 16:07:30 +08:00
parent e22b537de4
commit 41f39d9701
4 changed files with 16 additions and 31 deletions
+8 -26
View File
@@ -29,40 +29,22 @@ func strmLibrarySpecificOutputDir(base string, lib *model.Library) string {
if outputDir == "" || outputDir == "." || lib == nil {
return outputDir
}
outputDir = stripSTRMLibraryCategoryAfterRoot(outputDir)
subdir := strmLibraryOutputSubdir(*lib)
if subdir == "" || strmPathHasSuffix(outputDir, subdir) || pathAlreadyEndsWith(outputDir, filepath.Base(subdir)) {
return outputDir
}
if tail := strmMissingCategoryTail(outputDir, subdir); tail != "" {
return filepath.Join(outputDir, tail)
}
return filepath.Join(outputDir, subdir)
}
func stripSTRMLibraryCategoryAfterRoot(pathValue string) string {
normalized := filepath.ToSlash(filepath.Clean(strings.TrimSpace(pathValue)))
parts := strings.Split(normalized, "/")
strmIndex := -1
for i, part := range parts {
if strings.EqualFold(strings.TrimSpace(part), "strm") {
strmIndex = i
}
func strmMissingCategoryTail(outputDir, subdir string) string {
parts := strmSlashParts(subdir)
if len(parts) < 2 || !pathAlreadyEndsWith(outputDir, parts[0]) {
return ""
}
if strmIndex < 0 || strmIndex >= len(parts)-1 {
return pathValue
}
tail := make([]string, 0, len(parts)-strmIndex-1)
for _, part := range parts[strmIndex+1:] {
if strings.TrimSpace(part) != "" {
tail = append(tail, part)
}
}
if len(strmCategoryPartsFromPath(tail)) == 0 {
return pathValue
}
root := strings.Join(parts[:strmIndex+1], "/")
if root == "" {
return pathValue
}
return filepath.FromSlash(root)
return filepath.Join(parts[1:]...)
}
func strmPathHasSuffix(pathValue, suffix string) bool {
+3 -3
View File
@@ -232,8 +232,8 @@ func TestSTRMLibraryOutputSubdirUsesLibraryCategoryPath(t *testing.T) {
}
}
func TestSTRMLibrarySpecificOutputDirStripsPreviousLibraryCategory(t *testing.T) {
base := filepath.Join(t.TempDir(), "strm", "电影", "演唱会")
func TestSTRMLibrarySpecificOutputDirPreservesExplicitCategoryRoot(t *testing.T) {
base := filepath.Join(t.TempDir(), "strm", "电视剧")
lib := model.Library{
Name: "国产剧",
Path: BuildCloudLibraryPath("openlist", "/电视剧/国产剧", "/电视剧/国产剧"),
@@ -241,7 +241,7 @@ func TestSTRMLibrarySpecificOutputDirStripsPreviousLibraryCategory(t *testing.T)
}
got := strmLibrarySpecificOutputDir(base, &lib)
want := filepath.Join(filepath.Dir(filepath.Dir(base)), "电视剧", "国产剧")
want := filepath.Join(base, "国产剧")
if got != want {
t.Fatalf("strmLibrarySpecificOutputDir() = %q, want %q", got, want)
}