diff --git a/internal/domain/filter.go b/internal/domain/filter.go index 03b4731..3366879 100644 --- a/internal/domain/filter.go +++ b/internal/domain/filter.go @@ -1030,6 +1030,30 @@ func containsAnySlice(tags []string, filters []string) bool { return false } +func basicContainsSlice(tag string, filters []string) bool { + return basicContainsMatch([]string{tag}, filters) +} + +func basicContainsMatch(tags []string, filters []string) bool { + for _, tag := range tags { + if tag == "" { + continue + } + + for _, filter := range filters { + if filter == "" { + continue + } + + if tag == filter { + return true + } + } + } + + return false +} + func checkFreeleechPercent(announcePercent int, filterPercent string) bool { filters := strings.Split(filterPercent, ",") diff --git a/internal/domain/filter_test.go b/internal/domain/filter_test.go index d978a15..fb00b65 100644 --- a/internal/domain/filter_test.go +++ b/internal/domain/filter_test.go @@ -56,6 +56,21 @@ func TestFilter_CheckFilter(t *testing.T) { }, want: true, }, + { + name: "movie_parse_1", + fields: &Release{ + TorrentName: "White Christmas 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1-VHS", + }, + args: args{ + filter: Filter{ + Enabled: true, + Sources: []string{"BluRay", "UHD.BluRay"}, + MatchReleaseGroups: "VHS", + }, + rejectionReasons: &RejectionReasons{data: []Rejection{}}, + }, + want: true, + }, { name: "movie_parse_2", diff --git a/internal/domain/release.go b/internal/domain/release.go index f6e26d6..4ba4a68 100644 --- a/internal/domain/release.go +++ b/internal/domain/release.go @@ -360,6 +360,50 @@ func (r *Release) ParseString(title string) { } r.ParseReleaseTagsString(r.ReleaseTags) + r.extraParseSource(rel) +} + +func (r *Release) extraParseSource(rel rls.Release) { + if rel.Type != rls.Movie && rel.Type != rls.Series && rel.Type != rls.Episode { + return + } + + tags := rel.Tags() + if len(tags) < 3 { + return + } + + // handle special cases like -VHS + if r.Group == "" { + // check the next to last item separator to be - or whitespace then check the next and use as group if empty + //if tags[len(tags)-1].TagType() == rls.TagTypeSource && (tags[len(tags)-2].TagType() == rls.TagTypeDelim && (tags[len(tags)-2].Delim() == "-" || tags[len(tags)-2].Delim() == " ")) { + lastItem := tags[len(tags)-1] + if lastItem.TagType() == rls.TagTypeSource && lastItem.Prev() == rls.TagTypeWhitespace { + group := lastItem.Text() + + // handle special cases like -VHS + if r.Source == group { + r.Source = "" + } + + r.Group = group + } + } + + if basicContainsSlice(r.Source, []string{"WEB-DL", "BluRay", "UHD.BluRay"}) { + return + } + + // check res to be 1080p or 2160p and codec to be AVC, HEVC or if other contains Remux, then set source to BluRay if it differs + if !basicContainsSlice(r.Source, []string{"WEB-DL", "BluRay", "UHD.BluRay"}) && basicContainsSlice(r.Resolution, []string{"1080p", "2160p"}) && basicContainsMatch(r.Codec, []string{"AVC", "HEVC"}) && basicContainsMatch(r.Other, []string{"REMUX"}) { + // handle missing or unexpected source for some bluray releases + if r.Resolution == "1080p" { + r.Source = "BluRay" + + } else if r.Resolution == "2160p" { + r.Source = "UHD.BluRay" + } + } } func (r *Release) ParseReleaseTagsString(tags string) { diff --git a/internal/domain/release_test.go b/internal/domain/release_test.go index 9d9f3f9..22e1281 100644 --- a/internal/domain/release_test.go +++ b/internal/domain/release_test.go @@ -338,6 +338,85 @@ func TestRelease_Parse(t *testing.T) { Type: "series", }, }, + { + name: "parse_missing_source", + fields: Release{ + TorrentName: "Old Movie 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1-CiNEPHiLES", + }, + want: Release{ + TorrentName: "Old Movie 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1-CiNEPHiLES", + Title: "Old Movie", + Year: 1954, + Source: "UHD.BluRay", + Resolution: "2160p", + Other: []string{"REMUX"}, + HDR: []string{"DV", "HDR10"}, + Codec: []string{"HEVC"}, + Audio: []string{"DTS-HD.MA"}, + AudioChannels: "5.1", + Group: "CiNEPHiLES", + Type: "movie", + }, + }, + { + name: "parse_missing_source", + fields: Release{ + TorrentName: "Death Hunt 1981 1080p Remux AVC DTS-HD MA 2.0-playBD", + }, + want: Release{ + TorrentName: "Death Hunt 1981 1080p Remux AVC DTS-HD MA 2.0-playBD", + Title: "Death Hunt", + Year: 1981, + Source: "BluRay", + Resolution: "1080p", + Other: []string{"REMUX"}, + Codec: []string{"AVC"}, + Audio: []string{"DTS-HD.MA"}, + AudioChannels: "2.0", + Group: "playBD", + Type: "movie", + }, + }, + { + name: "parse_confusing_group", + fields: Release{ + TorrentName: "Old Movie 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1-VHS", + }, + want: Release{ + TorrentName: "Old Movie 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1-VHS", + Title: "Old Movie", + Year: 1954, + Source: "UHD.BluRay", + Resolution: "2160p", + Other: []string{"REMUX"}, + HDR: []string{"DV", "HDR10"}, + Codec: []string{"HEVC"}, + Audio: []string{"DTS-HD.MA"}, + AudioChannels: "5.1", + Group: "VHS", + Type: "movie", + }, + }, + { + name: "parse_confusing_group", + fields: Release{ + TorrentName: "Old Movie 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1 VHS", + }, + want: Release{ + TorrentName: "Old Movie 1954 2160p Remux DoVi HDR10 HEVC DTS-HD MA 5.1 VHS", + Title: "Old Movie", + Year: 1954, + Source: "UHD.BluRay", + Resolution: "2160p", + Other: []string{"REMUX"}, + HDR: []string{"DV", "HDR10"}, + Codec: []string{"HEVC"}, + Audio: []string{"DTS-HD.MA"}, + AudioChannels: "5.1", + Group: "VHS", + Type: "movie", + }, + }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {