Skip to content

Commit

Permalink
feat: support LEAK watermark
Browse files Browse the repository at this point in the history
  • Loading branch information
xxxsen committed Aug 15, 2024
1 parent e30ce74 commit 8ff2c3c
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 12 deletions.
3 changes: 3 additions & 0 deletions capture/capture.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ func (c *Capture) resolveFileInfo(fc *model.FileContext, file string) error {
if fc.Number.IsChineseSubtitle() {
fc.SaveFileBase += "-C"
}
if fc.Number.IsLeak() {
fc.SaveFileBase += "-LEAK"
}
if fc.Number.IsMultiCD() {
fc.SaveFileBase += "-CD" + strconv.FormatInt(int64(fc.Number.MultiCDIndex()), 10)
}
Expand Down
1 change: 1 addition & 0 deletions constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ const (
TagUncensored = "无码"
TagChineseSubtitle = "中文字幕"
Tag4K = "4K"
TagLeak = "无码流出"
)
Binary file added image/resource/leak.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions image/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ var ResIMGUncensored []byte

//go:embed 4k.png
var ResIMG4K []byte

//go:embed leak.png
var ResIMGLeak []byte
28 changes: 16 additions & 12 deletions image/watermark.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,22 @@ const (
WMChineseSubtitle Watermark = 1
WMUncensored Watermark = 2
WM4K Watermark = 3
WMLeak Watermark = 4
)

var resMap = make(map[Watermark][]byte)

func registerResource() {
resMap[WMChineseSubtitle] = resource.ResIMGSubtitle
resMap[WM4K] = resource.ResIMG4K
resMap[WMUncensored] = resource.ResIMGUncensored
resMap[WMLeak] = resource.ResIMGLeak
}

func init() {
registerResource()
}

const (
defaultMaxWaterMarkCount = 4 //最大的水印个数
defaultWaterMarkWidthToImageWidthRatio = float64(31.58) / 100 //水印与整张图片的宽度比, W(watermark)/W(image) = 0.3158
Expand Down Expand Up @@ -57,18 +71,8 @@ func addWatermarkToImage(img image.Image, wms []image.Image) (image.Image, error
}

func selectWatermarkResource(w Watermark) ([]byte, bool) {
var out []byte
switch w {
case WMChineseSubtitle:
out = resource.ResIMGSubtitle
case WMUncensored:
out = resource.ResIMGUncensored
case WM4K:
out = resource.ResIMG4K
default:
break
}
if len(out) == 0 {
out, ok := resMap[w]
if !ok {
return nil, false
}
rs := make([]byte, len(out))
Expand Down
5 changes: 5 additions & 0 deletions number/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Number struct {
multiCDIndex int
isUncensorMovie bool
is4k bool
isLeak bool
}

func (n *Number) Number() string {
Expand All @@ -32,3 +33,7 @@ func (n *Number) IsUncensorMovie() bool {
func (n *Number) Is4K() bool {
return n.is4k
}

func (n *Number) IsLeak() bool {
return n.isLeak
}
9 changes: 9 additions & 0 deletions number/number.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var defaultSuffixResolverList = []suffixInfoResolveFunc{
resolveIsChineseSubTitle,
resolveCDInfo,
resolve4K,
resolveLeak,
}

var defaultNumberInfoResolverList = []numberInfoResolveFunc{
Expand Down Expand Up @@ -66,6 +67,14 @@ func resolveCDInfo(info *Number, str string) bool {
return true
}

func resolveLeak(info *Number, str string) bool {
if str != "LEAK" {
return false
}
info.isLeak = true
return true
}

func resolve4K(info *Number, str string) bool {
if str != "4K" {
return false
Expand Down
5 changes: 5 additions & 0 deletions number/number_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,11 @@ func TestNumber(t *testing.T) {
isChineseSubtitle: true,
is4k: true,
},
"abc-leak-c.mp4": {
number: "ABC",
isLeak: true,
isChineseSubtitle: true,
},
}
for file, info := range checkList {
rs, err := ParseWithFileName(file)
Expand Down
3 changes: 3 additions & 0 deletions processor/handler/tag_padder.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ func (h *tagPadder) Handle(ctx context.Context, fc *model.FileContext) error {
if fc.Number.Is4K() {
fc.Meta.Genres = append(fc.Meta.Genres, constant.Tag4K)
}
if fc.Number.IsLeak() {
fc.Meta.Genres = append(fc.Meta.Genres, constant.TagLeak)
}
fc.Meta.Genres = utils.DedupStringList(fc.Meta.Genres)
return nil
}
Expand Down
3 changes: 3 additions & 0 deletions processor/handler/watermark_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ func (h *watermark) Handle(ctx context.Context, fc *model.FileContext) error {
if fc.Number.IsChineseSubtitle() {
tags = append(tags, image.WMChineseSubtitle)
}
if fc.Number.IsLeak() {
tags = append(tags, image.WMLeak)
}
if len(tags) == 0 {
logutil.GetLogger(ctx).Debug("no watermark tag found, skip watermark proc")
return nil
Expand Down

0 comments on commit 8ff2c3c

Please sign in to comment.