diff --git a/internal/domain/list.go b/internal/domain/list.go index 359f630..00b67ab 100644 --- a/internal/domain/list.go +++ b/internal/domain/list.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package domain import ( diff --git a/internal/http/list.go b/internal/http/list.go index 8872639..5c7d0e2 100644 --- a/internal/http/list.go +++ b/internal/http/list.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package http import ( diff --git a/internal/http/webhook.go b/internal/http/webhook.go index 8e97571..ffc8d30 100644 --- a/internal/http/webhook.go +++ b/internal/http/webhook.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package http import ( diff --git a/internal/list/process_arr_lidarr.go b/internal/list/process_arr_lidarr.go index c9267e4..53fb04d 100644 --- a/internal/list/process_arr_lidarr.go +++ b/internal/list/process_arr_lidarr.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_arr_radarr.go b/internal/list/process_arr_radarr.go index 1dff6bc..c3565d9 100644 --- a/internal/list/process_arr_radarr.go +++ b/internal/list/process_arr_radarr.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_arr_readarr.go b/internal/list/process_arr_readarr.go index 2bb6765..ca7e3d8 100644 --- a/internal/list/process_arr_readarr.go +++ b/internal/list/process_arr_readarr.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_arr_sonarr.go b/internal/list/process_arr_sonarr.go index 7d3efe2..2dbec1b 100644 --- a/internal/list/process_arr_sonarr.go +++ b/internal/list/process_arr_sonarr.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_list_mdblist.go b/internal/list/process_list_mdblist.go index 37baca1..62add3a 100644 --- a/internal/list/process_list_mdblist.go +++ b/internal/list/process_list_mdblist.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_list_metacritic.go b/internal/list/process_list_metacritic.go index 03f1f52..1190d3b 100644 --- a/internal/list/process_list_metacritic.go +++ b/internal/list/process_list_metacritic.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_list_plaintext.go b/internal/list/process_list_plaintext.go index 29a9ef4..d8ddd4d 100644 --- a/internal/list/process_list_plaintext.go +++ b/internal/list/process_list_plaintext.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_list_steam.go b/internal/list/process_list_steam.go index c0a8574..67d67d2 100644 --- a/internal/list/process_list_steam.go +++ b/internal/list/process_list_steam.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/process_list_trakt.go b/internal/list/process_list_trakt.go index 3985f21..4fba181 100644 --- a/internal/list/process_list_trakt.go +++ b/internal/list/process_list_trakt.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/scheduled_jobs.go b/internal/list/scheduled_jobs.go index 538724c..8f20ca7 100644 --- a/internal/list/scheduled_jobs.go +++ b/internal/list/scheduled_jobs.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/service.go b/internal/list/service.go index 5537cf0..8c0002b 100644 --- a/internal/list/service.go +++ b/internal/list/service.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( diff --git a/internal/list/tags.go b/internal/list/tags.go index 68ed4cf..02f42d8 100644 --- a/internal/list/tags.go +++ b/internal/list/tags.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import "github.com/autobrr/autobrr/pkg/arr" diff --git a/internal/list/tags_test.go b/internal/list/tags_test.go new file mode 100644 index 0000000..c108816 --- /dev/null +++ b/internal/list/tags_test.go @@ -0,0 +1,70 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + +package list + +import ( + "testing" + + "github.com/autobrr/autobrr/pkg/arr" + + "github.com/magiconair/properties/assert" +) + +func Test_containsTag(t *testing.T) { + type args struct { + tags []*arr.Tag + titleTags []int + checkTags []string + } + + tags := []*arr.Tag{ + { + ID: 1, + Label: "Want", + }, + { + ID: 2, + Label: "exclude-me", + }, + } + + tests := []struct { + name string + args args + want bool + }{ + { + name: "test_1", + args: args{ + tags: tags, + titleTags: []int{}, + checkTags: []string{"Want"}, + }, + want: false, + }, + { + name: "test_2", + args: args{ + tags: tags, + titleTags: []int{1}, + checkTags: []string{"Want"}, + }, + want: true, + }, + { + name: "test_3", + args: args{ + tags: tags, + titleTags: []int{1}, + checkTags: nil, + }, + want: false, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + assert.Equal(t, tt.want, containsTag(tt.args.tags, tt.args.titleTags, tt.args.checkTags)) + }) + } +} diff --git a/internal/list/title.go b/internal/list/title.go index 232c2a1..3336732 100644 --- a/internal/list/title.go +++ b/internal/list/title.go @@ -1,3 +1,6 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + package list import ( @@ -16,6 +19,7 @@ var ( parenthesesEndRegexp = regexp.MustCompile(`\)$`) ) +// yearRegexp = regexp.MustCompile(`\(\d{4}\)$`) func processTitle(title string, matchRelease bool) []string { // Checking if the title is empty. if strings.TrimSpace(title) == "" { @@ -83,6 +87,10 @@ func NewTitleSlice() *Titles { } func (ts *Titles) Add(title string, matchRelease bool) { + if title == "" || title == "*" { + return + } + if matchRelease { title = strings.Trim(title, "?") title = fmt.Sprintf("*%v*", title) diff --git a/internal/list/title_test.go b/internal/list/title_test.go new file mode 100644 index 0000000..0ec0473 --- /dev/null +++ b/internal/list/title_test.go @@ -0,0 +1,262 @@ +// Copyright (c) 2021 - 2024, Ludvig Lundgren and the autobrr contributors. +// SPDX-License-Identifier: GPL-2.0-or-later + +package list + +import ( + "github.com/stretchr/testify/assert" + "testing" +) + +func Test_processTitle(t *testing.T) { + type args struct { + title string + matchRelease bool + } + tests := []struct { + name string + args args + want []string + }{ + { + name: "test_01", + args: args{ + title: "The Quick Brown Fox (2022)", + matchRelease: false, + }, + want: []string{"The?Quick?Brown?Fox", "The?Quick?Brown?Fox*2022", "The?Quick?Brown?Fox*2022?"}, + }, + { + name: "test_02", + args: args{ + title: "The Matrix - Reloaded (2929)", + matchRelease: false, + }, + want: []string{"The?Matrix*Reloaded", "The?Matrix*Reloaded*2929", "The?Matrix*Reloaded*2929?"}, + }, + { + name: "test_03", + args: args{ + title: "The Matrix -(Test)- Reloaded (2929)", + matchRelease: false, + }, + want: []string{"The?Matrix*", "The?Matrix", "The?Matrix*Test*Reloaded*2929?", "The?Matrix*Test*Reloaded*2929"}, + }, + { + name: "test_04", + args: args{ + title: "The Marvelous Mrs. Maisel", + matchRelease: false, + }, + want: []string{"The?Marvelous?Mrs*Maisel"}, + }, + { + name: "test_05", + args: args{ + title: "Arrr!! The Title (2020)", + matchRelease: false, + }, + want: []string{"Arrr*The?Title", "Arrr*The?Title*2020", "Arrr*The?Title*2020?"}, + }, + { + name: "test_06", + args: args{ + title: "Whose Line Is It Anyway? (US)", + matchRelease: false, + }, + want: []string{"Whose?Line?Is?It?Anyway", "Whose?Line?Is?It?Anyway*US", "Whose?Line?Is?It?Anyway?", "Whose?Line?Is?It?Anyway*US?"}, + }, + { + name: "test_07", + args: args{ + title: "MasterChef (US)", + matchRelease: false, + }, + want: []string{"MasterChef*US", "MasterChef", "MasterChef*US?"}, + }, + { + name: "test_08", + args: args{ + title: "Brooklyn Nine-Nine", + matchRelease: false, + }, + want: []string{"Brooklyn?Nine?Nine"}, + }, + { + name: "test_09", + args: args{ + title: "S.W.A.T.", + matchRelease: false, + }, + want: []string{"S?W?A?T?", "S?W?A?T"}, + }, + { + name: "test_10", + args: args{ + title: "The Handmaid's Tale", + matchRelease: false, + }, + want: []string{"The?Handmaid?s?Tale", "The?Handmaids?Tale"}, + }, + { + name: "test_11", + args: args{ + title: "The Handmaid's Tale (US)", + matchRelease: false, + }, + want: []string{"The?Handmaid?s?Tale*US", "The?Handmaids?Tale*US", "The?Handmaid?s?Tale", "The?Handmaids?Tale", "The?Handmaid?s?Tale*US?", "The?Handmaids?Tale*US?"}, + }, + { + name: "test_12", + args: args{ + title: "Monsters, Inc.", + matchRelease: false, + }, + want: []string{"Monsters*Inc?", "Monsters*Inc"}, + }, + { + name: "test_13", + args: args{ + title: "Hello Tomorrow!", + matchRelease: false, + }, + want: []string{"Hello?Tomorrow?", "Hello?Tomorrow"}, + }, + { + name: "test_14", + args: args{ + title: "Be Cool, Scooby-Doo!", + matchRelease: false, + }, + want: []string{"Be?Cool*Scooby?Doo?", "Be?Cool*Scooby?Doo"}, + }, + { + name: "test_15", + args: args{ + title: "Scooby-Doo! Mystery Incorporated", + matchRelease: false, + }, + want: []string{"Scooby?Doo*Mystery?Incorporated"}, + }, + { + name: "test_16", + args: args{ + title: "Master.Chef (US)", + matchRelease: false, + }, + want: []string{"Master?Chef*US", "Master?Chef", "Master?Chef*US?"}, + }, + { + name: "test_17", + args: args{ + title: "Whose Line Is It Anyway? (US)", + matchRelease: false, + }, + want: []string{"Whose?Line?Is?It?Anyway*US", "Whose?Line?Is?It?Anyway?", "Whose?Line?Is?It?Anyway", "Whose?Line?Is?It?Anyway*US?"}, + }, + { + name: "test_18", + args: args{ + title: "90 Day Fiancé: Pillow Talk", + matchRelease: false, + }, + want: []string{"90?Day?Fianc*Pillow?Talk"}, + }, + { + name: "test_19", + args: args{ + title: "進撃の巨人", + matchRelease: false, + }, + want: []string{"進撃の巨人"}, + }, + { + name: "test_20", + args: args{ + title: "呪術廻戦 0: 東京都立呪術高等専門学校", + matchRelease: false, + }, + want: []string{"呪術廻戦?0*東京都立呪術高等専門学校"}, + }, + { + name: "test_21", + args: args{ + title: "-!", + matchRelease: false, + }, + want: []string{"-!"}, + }, + { + name: "test_22", + args: args{ + title: "A\u00a0Quiet\u00a0Place:\u00a0Day One", + matchRelease: false, + }, + want: []string{"A?Quiet?Place*Day?One"}, + }, + { + name: "test_23", + args: args{ + title: "Whose Line Is It Anyway? (US) (1932)", + matchRelease: false, + }, + want: []string{"Whose?Line?Is?It?Anyway", "Whose?Line?Is?It?Anyway?", "Whose?Line?Is?It?Anyway*US*1932", "Whose?Line?Is?It?Anyway*US*1932?"}, + }, + { + name: "test_24", + args: args{ + title: "What If…?", + matchRelease: false, + }, + want: []string{"What?If", "What?If*"}, + }, + { + name: "test_25", + args: args{ + title: "Shōgun (2024)", + matchRelease: false, + }, + want: []string{"Sh?gun*2024?", "Sh?gun*2024", "Sh?gun"}, + }, + { + name: "test_26", + args: args{ + title: "Pinball FX3 - Bethesda® Pinball", + matchRelease: false, + }, + want: []string{ + "Pinball?FX3*Bethesda*Pinball", + }, + }, + { + name: "test_27", + args: args{ + title: "Sally Goes to the Mall", + matchRelease: true, + }, + want: []string{"*Sally?Goes?to?the?Mall*"}, + }, + { + name: "test_28", + args: args{ + title: "*****… (los asteriscos…)", + matchRelease: false, + }, + want: []string{"*los?asteriscos*", "*los?asteriscos"}, + }, + { + name: "test_29", + args: args{ + title: "The Office (US)", + matchRelease: false, + }, + want: []string{"The?Office", "The?Office*US", "The?Office*US?"}, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + // order seem to be random so lets check if the elements are what we expect + assert.ElementsMatch(t, tt.want, processTitle(tt.args.title, tt.args.matchRelease)) + }) + } +}