mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 19:36:36 +08:00
b0fe40142a
* Rebrand MMTL to MeBox across codebase and assets Rename the project display name, Go module path, environment variable prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl to MeBox/mebox. Replace logo assets with the new MeBox icon and keep legacy SQLite migration support for existing mmtl.db deployments. Co-authored-by: truewhile <truewhile@users.noreply.github.com> * Fix logo icons: use cube-only crop without truncated text Previous icon generation cropped too much of the source image, including partial MeBox wordmark text that was cut off in square icon containers. Regenerate logo-64/192/512, favicon, and SVG from cube-only region. 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>
119 lines
3.6 KiB
Go
119 lines
3.6 KiB
Go
package service
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
|
|
"github.com/truewhile/MeBox/internal/model"
|
|
)
|
|
|
|
func TestManualEnrichLibraryRetriesNoMatchAndCountsRealMatches(t *testing.T) {
|
|
scraper, repos, closeServer := newTestScraper(t)
|
|
defer closeServer()
|
|
|
|
lib := model.Library{Name: "番剧", Path: t.TempDir(), Type: "tv", Enabled: true}
|
|
if err := repos.DB.Create(&lib).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
mediaPath := filepath.Join(lib.Path, "间谍过家家 - S02E02.mkv")
|
|
if err := repos.DB.Create(&model.Media{
|
|
LibraryID: lib.ID,
|
|
Title: "间谍过家家",
|
|
Path: mediaPath,
|
|
SeasonNum: 2,
|
|
EpisodeNum: 2,
|
|
ScrapeStatus: "no_match",
|
|
}).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
if matched, err := scraper.EnrichLibrary(t.Context(), lib.ID); err != nil || matched != 0 {
|
|
t.Fatalf("default EnrichLibrary matched=%d err=%v, want skipped no_match", matched, err)
|
|
}
|
|
if matched, err := scraper.EnrichLibrary(t.Context(), lib.ID, true); err != nil || matched != 1 {
|
|
t.Fatalf("manual EnrichLibrary matched=%d err=%v, want one real match", matched, err)
|
|
}
|
|
}
|
|
|
|
func TestManualEnrichLibraryCanRefreshAlreadyMatchedRows(t *testing.T) {
|
|
scraper, repos, closeServer := newTestScraper(t)
|
|
defer closeServer()
|
|
|
|
lib := model.Library{Name: "番剧", Path: t.TempDir(), Type: "tv", Enabled: true}
|
|
if err := repos.DB.Create(&lib).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
media := model.Media{
|
|
LibraryID: lib.ID,
|
|
Title: "间谍过家家",
|
|
Path: filepath.Join(lib.Path, "间谍过家家 - S02E02.mkv"),
|
|
SeasonNum: 2,
|
|
EpisodeNum: 2,
|
|
ScrapeStatus: "matched",
|
|
}
|
|
if err := repos.DB.Create(&media).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
defaultResult, err := scraper.EnrichLibraryDetailedWithOptions(t.Context(), lib.ID, ScrapeOptions{RetryNoMatch: true})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if defaultResult.Processed != 0 || defaultResult.Candidates != 0 {
|
|
t.Fatalf("default manual scrape result=%+v, want matched rows skipped without IncludeMatched", defaultResult)
|
|
}
|
|
|
|
refreshResult, err := scraper.EnrichLibraryDetailedWithOptions(t.Context(), lib.ID, ScrapeOptions{
|
|
RetryNoMatch: true,
|
|
IncludeMatched: true,
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if refreshResult.Processed != 1 || refreshResult.Matched != 1 || refreshResult.Candidates != 1 {
|
|
t.Fatalf("refresh result=%+v, want already matched row reprocessed", refreshResult)
|
|
}
|
|
}
|
|
|
|
func TestScrapeCandidateRowsPrioritizeLibraryArtworkBeforeEpisodes(t *testing.T) {
|
|
scraper, repos, closeServer := newTestScraper(t)
|
|
defer closeServer()
|
|
|
|
lib := model.Library{Name: "番剧", Path: t.TempDir(), Type: "tv", Enabled: true}
|
|
if err := repos.DB.Create(&lib).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
rows := []model.Media{
|
|
{
|
|
Base: model.Base{ID: "001-episode"},
|
|
LibraryID: lib.ID,
|
|
Title: "间谍过家家 第 1 集",
|
|
Path: filepath.Join(lib.Path, "间谍过家家 - S02E01.mkv"),
|
|
SeasonNum: 2,
|
|
EpisodeNum: 1,
|
|
ScrapeStatus: "pending",
|
|
},
|
|
{
|
|
Base: model.Base{ID: "999-series"},
|
|
LibraryID: lib.ID,
|
|
Title: "间谍过家家",
|
|
Path: filepath.Join(lib.Path, "间谍过家家.mkv"),
|
|
ScrapeStatus: "pending",
|
|
},
|
|
}
|
|
if err := repos.DB.Create(&rows).Error; err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
|
|
got, err := scraper.scrapeCandidateRows(t.Context(), lib.ID, ScrapeOptions{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if len(got) != 2 {
|
|
t.Fatalf("candidate rows = %d, want 2", len(got))
|
|
}
|
|
if got[0].ID != "999-series" || got[1].ID != "001-episode" {
|
|
t.Fatalf("scrape order = [%s, %s], want series-level row before episode row", got[0].ID, got[1].ID)
|
|
}
|
|
}
|