Skip to content

Commit 56c4c36

Browse files
committed
fix(scan): ignore results with no year and extra files
1 parent 57ea29c commit 56c4c36

File tree

1 file changed

+28
-3
lines changed

1 file changed

+28
-3
lines changed

backend/internal/service/scan.go

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ func (s *ScannerService) executeScan(ctx context.Context, library dbgen.Library,
251251
if d.IsDir() || !isMediaFile(path) {
252252
return nil
253253
}
254+
if isExtraFile(path) {
255+
return nil
256+
}
254257

255258
stats.FilesSeen++
256259

@@ -769,13 +772,14 @@ func evaluateSearchResults(libraryType string, key tmdbSearchKey, searchResult t
769772
candidates = append(candidates, candidate{ID: r.ID, Title: title, Year: year})
770773
}
771774

772-
// If we have a year from guessit, narrow candidates to those matching the year first.
775+
// If we have a year from guessit, narrow candidates to exact year matches only.
773776
// This lets us auto-match even when TMDB returns multiple results (e.g. sequels/remakes),
774-
// as long as only one result has the right year.
777+
// as long as only one result has the right year. Results with no year (year==0) are
778+
// excluded because they are typically obscure entries that would prevent disambiguation.
775779
if key.Year != nil {
776780
var yearFiltered []candidate
777781
for _, c := range candidates {
778-
if c.Year == 0 || c.Year == *key.Year {
782+
if c.Year == *key.Year {
779783
yearFiltered = append(yearFiltered, c)
780784
}
781785
}
@@ -822,3 +826,24 @@ func isMediaFile(path string) bool {
822826
}
823827
return false
824828
}
829+
830+
// isExtraFile returns true for files in directories that contain bonus content
831+
// (featurettes, samples, extras, etc.) rather than the main movie/episode.
832+
func isExtraFile(path string) bool {
833+
for _, part := range strings.Split(filepath.Dir(path), string(filepath.Separator)) {
834+
switch strings.ToLower(part) {
835+
case "featurettes", "featurette", "sample", "samples",
836+
"extras", "extra", "bonus", "behind the scenes",
837+
"deleted scenes", "interviews", "trailers", "shorts":
838+
return true
839+
}
840+
}
841+
842+
// Also catch "sample.mkv" or files starting with "sample" at the filename level
843+
base := strings.ToLower(strings.TrimSuffix(filepath.Base(path), filepath.Ext(path)))
844+
if base == "sample" || strings.HasPrefix(base, "sample.") || strings.HasPrefix(base, "sample-") {
845+
return true
846+
}
847+
848+
return false
849+
}

0 commit comments

Comments
 (0)