diff --git a/constant/constant.go b/constant/constant.go deleted file mode 100644 index 851101a..0000000 --- a/constant/constant.go +++ /dev/null @@ -1,8 +0,0 @@ -package constant - -const ( - TagUncensored = "无码" - TagChineseSubtitle = "中文字幕" - Tag4K = "4K" - TagLeak = "无码流出" -) diff --git a/number/constant.go b/number/constant.go index 75f22a1..e59764a 100644 --- a/number/constant.go +++ b/number/constant.go @@ -6,3 +6,10 @@ const ( defaultSuffix4K = "4K" defaultSuffixMultiCD = "CD" ) + +const ( + defaultTagUncensored = "无码" + defaultTagChineseSubtitle = "中文字幕" + defaultTag4K = "4K" + defaultTagLeak = "无码流出" +) diff --git a/number/model.go b/number/model.go index e304135..a2a6347 100644 --- a/number/model.go +++ b/number/model.go @@ -1,6 +1,8 @@ package number -import "strconv" +import ( + "strconv" +) type Number struct { number string @@ -56,6 +58,23 @@ func (n *Number) GenerateSuffix(base string) string { return base } +func (n *Number) GenerateTags() []string { + rs := make([]string, 0, 5) + if n.GetIsUncensorMovie() { + rs = append(rs, defaultTagUncensored) + } + if n.GetIsChineseSubtitle() { + rs = append(rs, defaultTagChineseSubtitle) + } + if n.GetIs4K() { + rs = append(rs, defaultTag4K) + } + if n.GetIsLeak() { + rs = append(rs, defaultTagLeak) + } + return rs +} + func (n *Number) GenerateFileName() string { return n.GenerateSuffix(n.GetNumberID()) } diff --git a/processor/handler/tag_padder.go b/processor/handler/tag_padder.go index 79f7820..caacc63 100644 --- a/processor/handler/tag_padder.go +++ b/processor/handler/tag_padder.go @@ -2,7 +2,6 @@ package handler import ( "context" - "yamdc/constant" "yamdc/model" "yamdc/utils" ) @@ -10,18 +9,7 @@ import ( type tagPadder struct{} func (h *tagPadder) Handle(ctx context.Context, fc *model.FileContext) error { - if fc.Number.GetIsUncensorMovie() { - fc.Meta.Genres = append(fc.Meta.Genres, constant.TagUncensored) - } - if fc.Number.GetIsChineseSubtitle() { - fc.Meta.Genres = append(fc.Meta.Genres, constant.TagChineseSubtitle) - } - if fc.Number.GetIs4K() { - fc.Meta.Genres = append(fc.Meta.Genres, constant.Tag4K) - } - if fc.Number.GetIsLeak() { - fc.Meta.Genres = append(fc.Meta.Genres, constant.TagLeak) - } + fc.Meta.Genres = append(fc.Meta.Genres, fc.Number.GenerateTags()...) fc.Meta.Genres = utils.DedupStringList(fc.Meta.Genres) return nil } diff --git a/processor/handler/tag_padder_test.go b/processor/handler/tag_padder_test.go index 44e9343..e3a1f67 100644 --- a/processor/handler/tag_padder_test.go +++ b/processor/handler/tag_padder_test.go @@ -3,7 +3,6 @@ package handler import ( "context" "testing" - "yamdc/constant" "yamdc/model" "yamdc/number" @@ -20,7 +19,4 @@ func TestTagPadde(t *testing.T) { } padder.Handle(context.Background(), fc) assert.Equal(t, 3, len(fc.Meta.Genres)) - assert.Contains(t, fc.Meta.Genres, constant.Tag4K) - assert.Contains(t, fc.Meta.Genres, constant.TagChineseSubtitle) - assert.Contains(t, fc.Meta.Genres, constant.TagUncensored) }