mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-06 21:36:37 +08:00
fix: honor explicit scrape media type
This commit is contained in:
@@ -662,14 +662,17 @@ func (s *ScraperService) determineMediaType(lib *model.Library, match *Match) st
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (s *ScraperService) determineMediaTypeForMedia(lib *model.Library, media *model.Media, match *Match) string {
|
func (s *ScraperService) determineMediaTypeForMedia(lib *model.Library, media *model.Media, match *Match) string {
|
||||||
|
if match != nil {
|
||||||
|
switch normalizeOrganizeMediaType(match.MediaType) {
|
||||||
|
case "tv", "anime", "variety":
|
||||||
|
return "tv"
|
||||||
|
case "movie", "adult":
|
||||||
|
return "movie"
|
||||||
|
}
|
||||||
|
}
|
||||||
if media != nil && mediaIsEpisodic(media, lib) {
|
if media != nil && mediaIsEpisodic(media, lib) {
|
||||||
return "tv"
|
return "tv"
|
||||||
}
|
}
|
||||||
if match != nil {
|
|
||||||
if mediaType := normalizeOrganizeMediaType(match.MediaType); mediaType != "" {
|
|
||||||
return mediaType
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if lib != nil {
|
if lib != nil {
|
||||||
switch lib.Type {
|
switch lib.Type {
|
||||||
case "tv", "anime", "variety", "show", "shows":
|
case "tv", "anime", "variety", "show", "shows":
|
||||||
|
|||||||
@@ -111,6 +111,38 @@ func TestEnrichOneTreatsEpisodicMediaInMovieLibraryAsTV(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestDetermineMediaTypeForMediaHonorsExplicitMatchType(t *testing.T) {
|
||||||
|
scraper := &ScraperService{}
|
||||||
|
lib := &model.Library{Name: "欧美剧", Type: "tv"}
|
||||||
|
media := &model.Media{
|
||||||
|
Title: "错误识别的电影",
|
||||||
|
Path: filepath.Join("library", "欧美剧", "错误识别的电影 (2024)", "错误识别的电影.S01E202.mkv"),
|
||||||
|
SeasonNum: 1,
|
||||||
|
EpisodeNum: 202,
|
||||||
|
}
|
||||||
|
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
match *Match
|
||||||
|
want string
|
||||||
|
}{
|
||||||
|
{name: "movie match overrides stale episode hints", match: &Match{MediaType: "movie"}, want: "movie"},
|
||||||
|
{name: "tv match stays tv", match: &Match{MediaType: "tv"}, want: "tv"},
|
||||||
|
{name: "anime match uses tmdb tv endpoint", match: &Match{MediaType: "anime"}, want: "tv"},
|
||||||
|
{name: "variety match uses tmdb tv endpoint", match: &Match{MediaType: "variety"}, want: "tv"},
|
||||||
|
{name: "adult match uses tmdb movie endpoint", match: &Match{MediaType: "adult"}, want: "movie"},
|
||||||
|
{name: "unknown match falls back to episodic hints", match: &Match{}, want: "tv"},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
if got := scraper.determineMediaTypeForMedia(lib, media, tt.match); got != tt.want {
|
||||||
|
t.Fatalf("determineMediaTypeForMedia() = %q, want %q", got, tt.want)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestEnrichOneWritesTMDbEpisodeMetadata(t *testing.T) {
|
func TestEnrichOneWritesTMDbEpisodeMetadata(t *testing.T) {
|
||||||
scraper, repos, closeServer := newTestScraper(t)
|
scraper, repos, closeServer := newTestScraper(t)
|
||||||
defer closeServer()
|
defer closeServer()
|
||||||
|
|||||||
Reference in New Issue
Block a user