mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-05 13:06:36 +08:00
Fix cloud playback and organize ingest pipeline
This commit is contained in:
@@ -69,6 +69,75 @@ func TestOrganizeDirectoryScanAndScrapeAfter(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizeScanAndScrapeRetriesNoMatchRows(t *testing.T) {
|
||||
scraper, repos, closeServer := newTestScraper(t)
|
||||
defer closeServer()
|
||||
|
||||
root := t.TempDir()
|
||||
libRoot := filepath.Join(root, "media", "电视剧")
|
||||
mediaPath := filepath.Join(libRoot, "间谍过家家", "Season 02", "间谍过家家 - S02E02.mkv")
|
||||
writeOrgFile(t, mediaPath, "episode")
|
||||
|
||||
lib := model.Library{
|
||||
Name: "剧集",
|
||||
Path: libRoot,
|
||||
Type: "tv",
|
||||
Enabled: true,
|
||||
}
|
||||
if err := repos.Library.Create(t.Context(), &lib); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
media := model.Media{
|
||||
LibraryID: lib.ID,
|
||||
Title: "间谍过家家",
|
||||
Path: mediaPath,
|
||||
SeasonNum: 2,
|
||||
EpisodeNum: 2,
|
||||
ScrapeStatus: "no_match",
|
||||
}
|
||||
if err := repos.Media.Upsert(t.Context(), &media); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
scanner := NewScannerService(&config.Config{}, zap.NewNop(), repos, NewHub(zap.NewNop()), nil, scraper)
|
||||
_, scrapes := scanner.ScanAndScrapeLibrariesForPath(t.Context(), filepath.Join(root, "media"), "", true)
|
||||
if len(scrapes) != 1 || scrapes[0].Matched != 1 || scrapes[0].Error != "" || scrapes[0].Skipped {
|
||||
t.Fatalf("scrapes = %#v, want one retried no_match row", scrapes)
|
||||
}
|
||||
|
||||
var got model.Media
|
||||
if err := repos.DB.First(&got, "path = ?", mediaPath).Error; err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got.ScrapeStatus != "matched" || got.TMDbID != 12345 {
|
||||
t.Fatalf("media scrape status=%q tmdb=%d, want matched/12345", got.ScrapeStatus, got.TMDbID)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizeResultNeedsVisibilitySyncIgnoresScannedDuplicates(t *testing.T) {
|
||||
if OrganizeResultNeedsVisibilitySync(&OrganizeResult{
|
||||
Skipped: 1,
|
||||
Items: []OrganizePreviewItem{{Action: "skip", Reason: organizeSkipDuplicateLibrary}},
|
||||
}) {
|
||||
t.Fatal("already-scanned duplicate should not trigger another visibility scan")
|
||||
}
|
||||
if OrganizeResultNeedsVisibilitySync(&OrganizeResult{
|
||||
Skipped: 1,
|
||||
Items: []OrganizePreviewItem{{Action: "skip", Reason: organizeSkipSampleClip}},
|
||||
}) {
|
||||
t.Fatal("sample clip skip should not trigger visibility scan")
|
||||
}
|
||||
if !OrganizeResultNeedsVisibilitySync(&OrganizeResult{
|
||||
Skipped: 1,
|
||||
Items: []OrganizePreviewItem{{Action: "skip", Reason: organizeSkipTargetExists}},
|
||||
}) {
|
||||
t.Fatal("unscanned target file should trigger visibility scan")
|
||||
}
|
||||
if !OrganizeResultNeedsVisibilitySync(&OrganizeResult{Organized: 1}) {
|
||||
t.Fatal("organized files must trigger visibility scan")
|
||||
}
|
||||
}
|
||||
|
||||
func TestOrganizeScrapeAfterEnabledDefaultsOn(t *testing.T) {
|
||||
if !OrganizeScrapeAfterEnabled(t.Context(), nil) {
|
||||
t.Fatalf("organize scrape-after should default on without a repo")
|
||||
|
||||
Reference in New Issue
Block a user