mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-28 03:06:38 +08:00
38b85bb487
* feat(strm): 同名多版本择优/keep_ext,并支持合并展示与播放切换 默认对同名不同扩展(如 .mkv/.mp4)按体积→mtime→扩展名优先级择优生成一条 strm,冲突打日志;开启 keep_ext 则分别生成 name.ext.strm。媒体详情与播放器可切换版本,列表继续合并同片多版本,Emby MediaSources 名称区分容器/分辨率。 Co-authored-by: truewhile <truewhile@users.noreply.github.com> * fix(meta): 边车匹配忽略 .mkv.strm 中间扩展,同片共享 NFO/海报/字幕 NFO、海报、字幕与刮削写出统一使用 mediaSidecarBase 词干,使竞女01.mkv.strm 与竞女01.mp4.strm 配对同一套 竞女01.nfo / 竞女01-poster / 竞女01.srt; 仍兼容历史上的 name.mkv.nfo 命名。 Co-authored-by: truewhile <truewhile@users.noreply.github.com> * fix(emby): People NFO 按共享词干匹配 keep_ext strm resolveMediaPeople 改为查找竞女01.nfo(并兼容旧的竞女01.mkv.nfo), 同时修正把 decodeNFOFile 的 partial 误当 ok 导致完整 NFO 被跳过的问题。 Co-authored-by: truewhile <truewhile@users.noreply.github.com> --------- Co-authored-by: Cursor Agent <cursoragent@cursor.com> Co-authored-by: truewhile <truewhile@users.noreply.github.com>
108 lines
3.0 KiB
Go
108 lines
3.0 KiB
Go
package service
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/truewhile/MeBox/internal/model"
|
|
"github.com/truewhile/MeBox/internal/repository"
|
|
)
|
|
|
|
func TestMediaSidecarBaseIgnoresKeepExt(t *testing.T) {
|
|
cases := map[string]string{
|
|
"/media/竞女01.mkv.strm": "竞女01",
|
|
"/media/竞女01.mp4.strm": "竞女01",
|
|
"/media/竞女01.strm": "竞女01",
|
|
"/media/竞女01.mkv": "竞女01",
|
|
"/lib/Show.S01E02.mkv.strm": "Show.S01E02",
|
|
`C:/lib/Show.S01E02.mkv.strm`: "Show.S01E02",
|
|
}
|
|
for in, want := range cases {
|
|
if got := mediaSidecarBase(in); got != want {
|
|
t.Fatalf("mediaSidecarBase(%q)=%q want %q", in, got, want)
|
|
}
|
|
}
|
|
}
|
|
|
|
func TestNFOPathUsesSharedStemForKeepExt(t *testing.T) {
|
|
got := nfoPath("/strm/竞女01.mkv.strm")
|
|
want := filepath.Join("/strm", "竞女01.nfo")
|
|
if got != want {
|
|
t.Fatalf("nfoPath keep_ext = %q want %q", got, want)
|
|
}
|
|
if nfoPath("/strm/竞女01.mp4.strm") != want {
|
|
t.Fatalf("mkv/mp4 versions should share nfo path")
|
|
}
|
|
}
|
|
|
|
func TestFindMovieNFOMatchesSharedStemBesideKeepExtStrm(t *testing.T) {
|
|
dir := t.TempDir()
|
|
media := filepath.Join(dir, "竞女01.mkv.strm")
|
|
nfo := filepath.Join(dir, "竞女01.nfo")
|
|
writeFileContent(t, media, "http://example/play")
|
|
writeFileContent(t, nfo, `<movie><title>竞女01</title></movie>`)
|
|
|
|
doc, path, err := findMovieNFO(media, dir)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if path != nfo {
|
|
t.Fatalf("path=%q want %q", path, nfo)
|
|
}
|
|
if doc == nil || strings.TrimSpace(doc.Title) != "竞女01" {
|
|
t.Fatalf("unexpected nfo doc: %#v", doc)
|
|
}
|
|
}
|
|
|
|
func TestLocalPosterCandidatesIncludeSharedStem(t *testing.T) {
|
|
cands := localPosterCandidates("/strm/竞女01.mkv.strm")
|
|
found := false
|
|
for _, name := range cands {
|
|
if name == "竞女01-poster" || name == "竞女01" {
|
|
found = true
|
|
break
|
|
}
|
|
}
|
|
if !found {
|
|
t.Fatalf("expected shared stem poster candidates, got %#v", cands)
|
|
}
|
|
}
|
|
|
|
func TestSubtitleDiscoveryMatchesSharedStemBesideKeepExt(t *testing.T) {
|
|
dir := t.TempDir()
|
|
mediaPath := filepath.Join(dir, "竞女01.mkv.strm")
|
|
subPath := filepath.Join(dir, "竞女01.zh.srt")
|
|
writeFileContent(t, mediaPath, "http://example/play")
|
|
writeFileContent(t, subPath, "1\n00:00:01,000 --> 00:00:02,000\nhi\n")
|
|
|
|
db := newServiceTestDB(t, &model.Media{})
|
|
repos := repository.New(db)
|
|
media := model.Media{Title: "竞女01", Path: mediaPath}
|
|
if err := repos.Media.Upsert(t.Context(), &media); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
svc := &SubtitleService{repo: repos}
|
|
tracks, err := svc.discoverUncached(t.Context(), media.ID)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(tracks) != 1 {
|
|
t.Fatalf("tracks=%d want 1 (%#v)", len(tracks), tracks)
|
|
}
|
|
if tracks[0].Path != subPath {
|
|
t.Fatalf("track path=%q want %q", tracks[0].Path, subPath)
|
|
}
|
|
}
|
|
|
|
func writeFileContent(t *testing.T, path, data string) {
|
|
t.Helper()
|
|
if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if err := os.WriteFile(path, []byte(data), 0o644); err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|