feat(indexers): btn improve parsing (#371)

* feat(indexers): btn improve parsing
This commit is contained in:
ze0s 2022-07-23 16:47:15 +02:00 committed by GitHub
parent 31441ff4c3
commit 4f3091a4a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 34 additions and 11 deletions

View file

@ -238,7 +238,9 @@ func (r *Release) ParseReleaseTagsString(tags string) {
if len(t.Other) > 0 { if len(t.Other) > 0 {
r.Other = append(r.Other, t.Other...) r.Other = append(r.Other, t.Other...)
} }
if r.Origin == "" && t.Origin != "" {
r.Origin = t.Origin
}
if r.Container == "" && t.Container != "" { if r.Container == "" && t.Container != "" {
r.Container = t.Container r.Container = t.Container
} }
@ -464,6 +466,10 @@ func (r *Release) MapVars(def *IndexerDefinition, varMap map[string]string) erro
r.Tags = tagArr r.Tags = tagArr
} }
if title, err := getStringMapValue(varMap, "title"); err == nil {
r.Title = title
}
// handle releaseTags. Most of them are redundant but some are useful // handle releaseTags. Most of them are redundant but some are useful
if releaseTags, err := getStringMapValue(varMap, "releaseTags"); err == nil { if releaseTags, err := getStringMapValue(varMap, "releaseTags"); err == nil {
r.ReleaseTags = releaseTags r.ReleaseTags = releaseTags

View file

@ -128,6 +128,14 @@ func init() {
} }
types["other"] = other types["other"] = other
origin := []*TagInfo{
{tag: "P2P", title: "P2P", regexp: "", re: nil},
{tag: "Scene", title: "Scene", regexp: "", re: nil},
{tag: "O-Scene", title: "O-Scene", regexp: "", re: nil},
{tag: "Internal", title: "Internal", regexp: "", re: nil},
}
types["origin"] = origin
source := []*TagInfo{ source := []*TagInfo{
{tag: "Cassette", title: "Cassette", regexp: "", re: nil}, {tag: "Cassette", title: "Cassette", regexp: "", re: nil},
{tag: "CD", title: "Compact Disc", regexp: "cd[\\-\\._ ]?(?:album)?", re: nil}, {tag: "CD", title: "Compact Disc", regexp: "cd[\\-\\._ ]?(?:album)?", re: nil},
@ -268,14 +276,15 @@ func Find(infos ...*TagInfo) FindFunc {
type ReleaseTags struct { type ReleaseTags struct {
Audio []string Audio []string
Channels string
Source string
Resolution string
Container string
Codec string
HDR []string
Other []string
Bonus []string Bonus []string
Channels string
Codec string
Container string
HDR []string
Origin string
Other []string
Resolution string
Source string
} }
func ParseReleaseTags(tags []string) ReleaseTags { func ParseReleaseTags(tags []string) ReleaseTags {
@ -309,6 +318,9 @@ func ParseReleaseTags(tags []string) ReleaseTags {
case "hdr": case "hdr":
releaseTags.HDR = append(releaseTags.HDR, info.Tag()) releaseTags.HDR = append(releaseTags.HDR, info.Tag())
continue continue
case "origin":
releaseTags.Origin = info.Tag()
break
case "other": case "other":
releaseTags.Other = append(releaseTags.Other, info.Tag()) releaseTags.Other = append(releaseTags.Other, info.Tag())
continue continue
@ -360,6 +372,9 @@ func ParseReleaseTagString(tags string) ReleaseTags {
case "hdr": case "hdr":
releaseTags.HDR = append(releaseTags.HDR, info.Tag()) releaseTags.HDR = append(releaseTags.HDR, info.Tag())
continue continue
case "origin":
releaseTags.Origin = info.Tag()
break
case "other": case "other":
releaseTags.Other = append(releaseTags.Other, info.Tag()) releaseTags.Other = append(releaseTags.Other, info.Tag())
continue continue

View file

@ -49,6 +49,9 @@ func TestParseReleaseTagString(t *testing.T) {
{name: "movies_8", args: args{tags: "H.264, DVD, Freeleech!"}, want: ReleaseTags{Codec: "H.264", Source: "DVD", Bonus: []string{"Freeleech"}}}, {name: "movies_8", args: args{tags: "H.264, DVD, Freeleech!"}, want: ReleaseTags{Codec: "H.264", Source: "DVD", Bonus: []string{"Freeleech"}}},
{name: "anime_1", args: args{tags: "Web / MKV / h264 / 1080p / AAC 2.0 / Softsubs (SubsPlease) / Episode 22 / Freeleech"}, want: ReleaseTags{Audio: []string{"AAC"}, Channels: "2.0", Source: "WEB", Resolution: "1080p", Container: "mkv", Codec: "H.264", Bonus: []string{"Freeleech"}}}, {name: "anime_1", args: args{tags: "Web / MKV / h264 / 1080p / AAC 2.0 / Softsubs (SubsPlease) / Episode 22 / Freeleech"}, want: ReleaseTags{Audio: []string{"AAC"}, Channels: "2.0", Source: "WEB", Resolution: "1080p", Container: "mkv", Codec: "H.264", Bonus: []string{"Freeleech"}}},
{name: "anime_2", args: args{tags: "Web | ISO | h264 | 1080p | AAC 2.0 | Softsubs (SubsPlease) | Episode 22 | Freeleech"}, want: ReleaseTags{Audio: []string{"AAC"}, Channels: "2.0", Source: "WEB", Resolution: "1080p", Container: "iso", Codec: "H.264", Bonus: []string{"Freeleech"}}}, {name: "anime_2", args: args{tags: "Web | ISO | h264 | 1080p | AAC 2.0 | Softsubs (SubsPlease) | Episode 22 | Freeleech"}, want: ReleaseTags{Audio: []string{"AAC"}, Channels: "2.0", Source: "WEB", Resolution: "1080p", Container: "iso", Codec: "H.264", Bonus: []string{"Freeleech"}}},
{name: "tv_1", args: args{tags: "MKV | H.264 | WEB-DL | 1080p | Internal | FastTorrent"}, want: ReleaseTags{Source: "WEB-DL", Codec: "H.264", Resolution: "1080p", Container: "mkv", Origin: "Internal"}},
{name: "tv_2", args: args{tags: "MKV | H.264 | WEB-DL | 1080p | Scene | FastTorrent"}, want: ReleaseTags{Source: "WEB-DL", Codec: "H.264", Resolution: "1080p", Container: "mkv", Origin: "Scene"}},
{name: "tv_3", args: args{tags: "MKV | H.264 | WEB-DL | 1080p | P2P | FastTorrent"}, want: ReleaseTags{Source: "WEB-DL", Codec: "H.264", Resolution: "1080p", Container: "mkv", Origin: "P2P"}},
} }
for _, tt := range tests { for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) { t.Run(tt.name, func(t *testing.T) {

View file

@ -70,12 +70,11 @@ parse:
- torrentName - torrentName
- test: - test:
- "[ Title: S06E07 ] [ Series: The Show ]" - "[ Title: S06E07 ] [ Series: The Show ]"
pattern: '^\[ Title: (.*) \] \[ Series: (.*) \]' pattern: '^\[ Title: .* \] \[ Series: (.*) \]'
vars: vars:
- title - title
- name1
- test: - test:
- "[ 2010 ] [ Episode ] [ MKV | x264 | WEB ] [ Uploader: Uploader1 ]" - "[ 2010 ] [ Episode ] [ MKV | x264 | WEB | P2P ] [ Uploader: Uploader1 ]"
pattern: '^(?:\[ (\d+) \] )?\[ (.*) \] \[ (.*) \] \[ Uploader: (.*?) \](?: \[ Pretime: (.*) \])?' pattern: '^(?:\[ (\d+) \] )?\[ (.*) \] \[ (.*) \] \[ Uploader: (.*?) \](?: \[ Pretime: (.*) \])?'
vars: vars:
- year - year