fix(releases): parse missing source and misinterpreted group name (#1820)

fix(releases): parse missing source and groups
This commit is contained in:
ze0s 2024-11-23 15:08:58 +01:00 committed by GitHub
parent 50f1e4e7d5
commit c0882aff84
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 162 additions and 0 deletions

View file

@ -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, ",")

View file

@ -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",

View file

@ -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) {

View file

@ -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) {