Добавил поиск метаданных по каталогам
This commit is contained in:
@@ -528,6 +528,80 @@ func TestApplyOverrides(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRecognizeOne_AutoApplies(t *testing.T) {
|
||||
root := t.TempDir()
|
||||
downloads := filepath.Join(root, "downloads")
|
||||
movies := filepath.Join(root, "movies")
|
||||
series := filepath.Join(root, "series")
|
||||
for _, d := range []string{downloads, movies, series} {
|
||||
_ = os.MkdirAll(d, 0o755)
|
||||
}
|
||||
plan := seriesResult().Plan
|
||||
plan.Confidence = 0.95
|
||||
for _, f := range plan.Files {
|
||||
p := filepath.Join(downloads, f.Src)
|
||||
_ = os.MkdirAll(filepath.Dir(p), 0o755)
|
||||
_ = os.WriteFile(p, []byte("x"), 0o644)
|
||||
}
|
||||
lay, _ := layout.New(layout.Config{MoviesDir: movies, SeriesDir: series})
|
||||
|
||||
st := newMemStore()
|
||||
st.put(completedDownload(1))
|
||||
qb := &fakeQbt{
|
||||
torrents: []qbt.Torrent{{Hash: ihTest, Name: "Show", SavePath: downloads, Category: "jellybit"}},
|
||||
files: []qbt.File{{Name: "Show/e1.mkv", Size: 1}, {Name: "Show/e2.mkv", Size: 1}},
|
||||
}
|
||||
rec := &fakeRecognizer{result: recognize.Result{
|
||||
Plan: plan,
|
||||
Decision: recognize.Decision{Auto: true},
|
||||
Match: &recognize.Match{Provider: "tmdb", ProviderID: "42", Title: "Show", Year: 2006},
|
||||
}}
|
||||
w := testWorkerWith(st, qb, rec, lay)
|
||||
|
||||
w.recognizeOne(context.Background(), 1)
|
||||
|
||||
if st.downloads[1].State != store.StateDone {
|
||||
t.Fatalf("state = %q, want done (auto)", st.downloads[1].State)
|
||||
}
|
||||
// Provider-тег попал в имя папки.
|
||||
want := filepath.Join(series, "Show (2006) [tmdbid-42]", "Season 02", "Show (2006) S02E01.mkv")
|
||||
if _, err := os.Stat(want); err != nil {
|
||||
t.Errorf("expected auto-linked file %q: %v", want, err)
|
||||
}
|
||||
if len(st.links) != 2 {
|
||||
t.Errorf("file_links = %d, want 2", len(st.links))
|
||||
}
|
||||
}
|
||||
|
||||
func TestApply_UsesProviderTag(t *testing.T) {
|
||||
f := newApplyFixture(t, seriesResult().Plan)
|
||||
f.st.recs[0].Provider = store.NullString("tmdb")
|
||||
f.st.recs[0].ProviderID = store.NullString("603")
|
||||
|
||||
if err := f.w.Apply(context.Background(), 1); err != nil {
|
||||
t.Fatalf("Apply: %v", err)
|
||||
}
|
||||
want := filepath.Join(f.series, "Show (2006) [tmdbid-603]", "Season 02", "Show (2006) S02E01.mkv")
|
||||
if _, err := os.Stat(want); err != nil {
|
||||
t.Errorf("expected tagged path %q: %v", want, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProviderTag(t *testing.T) {
|
||||
cases := []struct{ provider, id, want string }{
|
||||
{"tmdb", "603", "tmdbid-603"},
|
||||
{"tvdb", "123", "tvdbid-123"},
|
||||
{"none", "", ""},
|
||||
{"tmdb", "", ""},
|
||||
{"weird", "1", ""},
|
||||
}
|
||||
for _, c := range cases {
|
||||
if got := providerTag(c.provider, c.id); got != c.want {
|
||||
t.Errorf("providerTag(%q,%q) = %q, want %q", c.provider, c.id, got, c.want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestToLayoutPlan(t *testing.T) {
|
||||
s, e := 1, 3
|
||||
plan := recognize.Plan{
|
||||
@@ -537,7 +611,7 @@ func TestToLayoutPlan(t *testing.T) {
|
||||
{Src: "sample.mkv", Role: "sample"},
|
||||
},
|
||||
}
|
||||
lp := toLayoutPlan(plan, "/d")
|
||||
lp := toLayoutPlan(plan, "/d", "tmdbid-1")
|
||||
if len(lp.Files) != 1 {
|
||||
t.Fatalf("want 1 linkable file, got %d", len(lp.Files))
|
||||
}
|
||||
@@ -547,4 +621,7 @@ func TestToLayoutPlan(t *testing.T) {
|
||||
if lp.Files[0].Role != layout.RoleEpisode {
|
||||
t.Errorf("role = %q", lp.Files[0].Role)
|
||||
}
|
||||
if lp.ProviderTag != "tmdbid-1" {
|
||||
t.Errorf("provider tag = %q", lp.ProviderTag)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user