mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-07 22:06:38 +08:00
fix(subscription): apply rules on RSS path, dedup movies via library, MoviePilot-style default excludes
- runOne (RSS) now applies matchesSubscriptionRules so ExcludeWords/Resolution/Quality/Effects/ReleaseGroups take effect (previously only the Filter regex ran, so editing 排除 had no effect on RSS subscriptions) - movie candidate selection now consults library availability: non-wash subscriptions skip titles already in the library, stopping repeated downloads of 10bit/Dolby releases (aligns with MoviePilot 'download once = satisfied') - add MoviePilot-style default exclude list (cam/ts/枪版/trailer/sample...) merged with user excludes; latin tokens matched on word boundaries to avoid substring false positives - frontend: send rule fields as raw strings on edit so 排除词 can be cleared/changed (was dropped by '|| undefined') Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
@@ -205,6 +205,13 @@ func (s *SubscriptionService) runOne(ctx context.Context, sub *model.Subscriptio
|
|||||||
seenSet[g] = struct{}{}
|
seenSet[g] = struct{}{}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 非洗版订阅:成功下载一次即满足,预先算一次媒体库可用性用于跳过已入库的电影/剧集(对齐 MoviePilot)。
|
||||||
|
washOff := !sub.WashEnabled
|
||||||
|
var avail LocalAvailability
|
||||||
|
if washOff {
|
||||||
|
avail = SubscriptionLocalAvailability(ctx, s.repo, sub)
|
||||||
|
}
|
||||||
|
|
||||||
queued := 0
|
queued := 0
|
||||||
for _, item := range feed.Channel.Items {
|
for _, item := range feed.Channel.Items {
|
||||||
guid := item.GUID
|
guid := item.GUID
|
||||||
@@ -217,6 +224,15 @@ func (s *SubscriptionService) runOne(ctx context.Context, sub *model.Subscriptio
|
|||||||
if filter != nil && !filter.MatchString(item.Title) {
|
if filter != nil && !filter.MatchString(item.Title) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
// 应用订阅高级规则(排除词/分辨率/质量/特效/发布组)—— 此前 RSS 路径完全跳过,导致排除不生效。
|
||||||
|
if !matchesSubscriptionRules(sub, item.Title) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if washOff && subscriptionItemAlreadyAvailable(sub, avail, item.Title) {
|
||||||
|
seen = append(seen, guid)
|
||||||
|
seenSet[guid] = struct{}{}
|
||||||
|
continue
|
||||||
|
}
|
||||||
download := item.Enclosure.URL
|
download := item.Enclosure.URL
|
||||||
if download == "" {
|
if download == "" {
|
||||||
download = item.Link
|
download = item.Link
|
||||||
@@ -402,15 +418,20 @@ func selectSiteSearchCandidates(results []SearchResult, sub *model.Subscription,
|
|||||||
return candidates[i].Item.Size > candidates[j].Item.Size
|
return candidates[i].Item.Size > candidates[j].Item.Size
|
||||||
})
|
})
|
||||||
|
|
||||||
mediaType := normalizeMediaType(sub.MediaType, sub.Name+" "+sub.Filter, "")
|
|
||||||
if !isSubscriptionSeriesType(mediaType) {
|
|
||||||
return candidates[:1]
|
|
||||||
}
|
|
||||||
|
|
||||||
var local LocalAvailability
|
var local LocalAvailability
|
||||||
if len(availability) > 0 {
|
if len(availability) > 0 {
|
||||||
local = availability[0]
|
local = availability[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mediaType := normalizeMediaType(sub.MediaType, sub.Name+" "+sub.Filter, "")
|
||||||
|
if !isSubscriptionSeriesType(mediaType) {
|
||||||
|
// 对齐 MoviePilot:非洗版订阅成功下载一次即满足,媒体库/下载中已存在则不再重复下载。
|
||||||
|
if (sub == nil || !sub.WashEnabled) && local.LocalMediaCount > 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return candidates[:1]
|
||||||
|
}
|
||||||
|
|
||||||
if local.LocalMediaCount > 0 {
|
if local.LocalMediaCount > 0 {
|
||||||
if local.TotalEpisodes > 0 && len(local.MissingEpisodes) == 0 {
|
if local.TotalEpisodes > 0 && len(local.MissingEpisodes) == 0 {
|
||||||
return nil
|
return nil
|
||||||
@@ -451,12 +472,19 @@ func selectSiteSearchCandidates(results []SearchResult, sub *model.Subscription,
|
|||||||
return selected
|
return selected
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// defaultExcludeWords 是参考 MoviePilot 默认过滤的「垃圾版本」排除清单,对所有订阅生效,
|
||||||
|
// 与用户自定义排除词合并。拉丁词在 containsAnyExcludeToken 里按词边界匹配以避免子串误伤。
|
||||||
|
const defaultExcludeWords = "cam,ts,tc,telesync,telecine,hdcam,hdts,枪版,抢先,抢鲜,预告,trailer,sample"
|
||||||
|
|
||||||
func matchesSubscriptionRules(sub *model.Subscription, title string) bool {
|
func matchesSubscriptionRules(sub *model.Subscription, title string) bool {
|
||||||
|
titleFold := strings.ToLower(title)
|
||||||
|
if containsAnyExcludeToken(titleFold, defaultExcludeWords) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
if sub == nil {
|
if sub == nil {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
titleFold := strings.ToLower(title)
|
if sub.ExcludeWords != "" && containsAnyExcludeToken(titleFold, sub.ExcludeWords) {
|
||||||
if sub.ExcludeWords != "" && containsAnyToken(titleFold, sub.ExcludeWords) {
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
if sub.ReleaseGroups != "" && !containsAnyToken(titleFold, sub.ReleaseGroups) {
|
if sub.ReleaseGroups != "" && !containsAnyToken(titleFold, sub.ReleaseGroups) {
|
||||||
@@ -521,6 +549,63 @@ func containsAnyToken(titleFold, csv string) bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// containsAnyExcludeToken 用于排除词匹配:纯 ASCII 字母数字的词按词边界匹配(避免 "ts"
|
||||||
|
// 误伤 "tsukihime"、"cam" 误伤 "camp" 之类的子串误判),含 CJK/符号的词仍按子串匹配。
|
||||||
|
func containsAnyExcludeToken(titleFold, csv string) bool {
|
||||||
|
for _, token := range strings.FieldsFunc(strings.ToLower(csv), func(r rune) bool {
|
||||||
|
return r == ',' || r == '/' || r == '|' || r == ';' || r == ','
|
||||||
|
}) {
|
||||||
|
token = strings.TrimSpace(token)
|
||||||
|
if token == "" {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if isASCIIWordToken(token) {
|
||||||
|
if matchesWordBoundary(titleFold, token) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if strings.Contains(titleFold, token) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isASCIIWordToken(token string) bool {
|
||||||
|
for _, r := range token {
|
||||||
|
if r > unicode.MaxASCII || !(unicode.IsLetter(r) || unicode.IsDigit(r)) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return token != ""
|
||||||
|
}
|
||||||
|
|
||||||
|
// matchesWordBoundary 判断 token 是否作为独立词出现在 title 中,词边界为「非字母数字」。
|
||||||
|
func matchesWordBoundary(titleFold, token string) bool {
|
||||||
|
isWordRune := func(r rune) bool {
|
||||||
|
return unicode.IsLetter(r) || unicode.IsDigit(r)
|
||||||
|
}
|
||||||
|
from := 0
|
||||||
|
for {
|
||||||
|
idx := strings.Index(titleFold[from:], token)
|
||||||
|
if idx < 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
start := from + idx
|
||||||
|
end := start + len(token)
|
||||||
|
leftOK := start == 0 || !isWordRune(rune(titleFold[start-1]))
|
||||||
|
rightOK := end >= len(titleFold) || !isWordRune(rune(titleFold[end]))
|
||||||
|
if leftOK && rightOK {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
from = start + 1
|
||||||
|
if from >= len(titleFold) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func containsAnyEffect(titleFold, csv string) bool {
|
func containsAnyEffect(titleFold, csv string) bool {
|
||||||
for _, token := range strings.FieldsFunc(strings.ToLower(csv), func(r rune) bool {
|
for _, token := range strings.FieldsFunc(strings.ToLower(csv), func(r rune) bool {
|
||||||
return r == ',' || r == '/' || r == '|' || r == ';' || r == ','
|
return r == ',' || r == '/' || r == '|' || r == ';' || r == ','
|
||||||
@@ -742,6 +827,34 @@ func mergeLocalAvailability(values ...LocalAvailability) LocalAvailability {
|
|||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// subscriptionItemAlreadyAvailable 判断某个订阅条目(按其标题解析出的季/集)是否已在媒体库存在。
|
||||||
|
// 电影/无集号条目:媒体库已有该片即视为已存在;剧集条目:对应季集已入库即视为已存在。
|
||||||
|
func subscriptionItemAlreadyAvailable(sub *model.Subscription, avail LocalAvailability, title string) bool {
|
||||||
|
if avail.LocalMediaCount == 0 {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
if !isSubscriptionSeriesType(subscriptionMediaType(sub)) {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
wantSeason, wantEpisode := ParseEpisode(title)
|
||||||
|
if wantEpisode <= 0 {
|
||||||
|
// 整季合集 / 无法解析集号:库里已有内容时保守跳过,避免重复整季下载。
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
if wantSeason <= 0 {
|
||||||
|
wantSeason = 1
|
||||||
|
}
|
||||||
|
_, exists := avail.ExistingEpisodeKeys[episodeKey(wantSeason, wantEpisode)]
|
||||||
|
return exists
|
||||||
|
}
|
||||||
|
|
||||||
|
func subscriptionMediaType(sub *model.Subscription) string {
|
||||||
|
if sub == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
return sub.MediaType
|
||||||
|
}
|
||||||
|
|
||||||
func (s *SubscriptionService) downloadPathHasCandidate(ctx context.Context, sub *model.Subscription, title, savePath string) bool {
|
func (s *SubscriptionService) downloadPathHasCandidate(ctx context.Context, sub *model.Subscription, title, savePath string) bool {
|
||||||
savePath = strings.TrimSpace(savePath)
|
savePath = strings.TrimSpace(savePath)
|
||||||
if savePath == "" {
|
if savePath == "" {
|
||||||
|
|||||||
@@ -192,3 +192,96 @@ func TestSubscriptionPendingDownloadAvailabilitySkipsUnorganizedEpisodes(t *test
|
|||||||
t.Fatal("did not expect missing E03 to be detected")
|
t.Fatal("did not expect missing E03 to be detected")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMatchesSubscriptionRulesUserExcludeWords(t *testing.T) {
|
||||||
|
sub := &model.Subscription{ExcludeWords: "10bit,dolby vision,杜比"}
|
||||||
|
cases := []struct {
|
||||||
|
title string
|
||||||
|
want bool
|
||||||
|
}{
|
||||||
|
{"Movie 2024 1080p WEB-DL", true},
|
||||||
|
{"Movie 2024 2160p 10bit HEVC", false},
|
||||||
|
{"Movie 2024 2160p Dolby Vision", false},
|
||||||
|
{"电影 2024 杜比全景声", false},
|
||||||
|
}
|
||||||
|
for _, c := range cases {
|
||||||
|
if got := matchesSubscriptionRules(sub, c.title); got != c.want {
|
||||||
|
t.Errorf("matchesSubscriptionRules(%q) = %v, want %v", c.title, got, c.want)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMatchesSubscriptionRulesDefaultExcludesJunkReleases(t *testing.T) {
|
||||||
|
sub := &model.Subscription{}
|
||||||
|
for _, title := range []string{
|
||||||
|
"Some Movie 2024 CAM",
|
||||||
|
"Some Movie 2024 HDTS",
|
||||||
|
"某电影 2024 枪版",
|
||||||
|
"Some Movie 2024 TELESYNC",
|
||||||
|
"Some Show 预告",
|
||||||
|
} {
|
||||||
|
if matchesSubscriptionRules(sub, title) {
|
||||||
|
t.Errorf("expected default rules to exclude junk release %q", title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestMatchesSubscriptionRulesWordBoundaryAvoidsFalsePositives(t *testing.T) {
|
||||||
|
sub := &model.Subscription{}
|
||||||
|
// "ts" / "cam" / "tc" 作为子串出现在合法标题里时不应被默认排除误伤。
|
||||||
|
for _, title := range []string{
|
||||||
|
"Tsukihime 2024 1080p WEB-DL",
|
||||||
|
"Camp Rock 2024 1080p BluRay",
|
||||||
|
"Catch Me 2024 1080p WEB-DL",
|
||||||
|
} {
|
||||||
|
if !matchesSubscriptionRules(sub, title) {
|
||||||
|
t.Errorf("word-boundary match wrongly excluded %q", title)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSelectSiteSearchCandidatesSkipsExistingMovieWhenNotWashing(t *testing.T) {
|
||||||
|
sub := &model.Subscription{Name: "Inception 自动订阅", Filter: "Inception 2010", MediaType: "movie"}
|
||||||
|
results := []SearchResult{
|
||||||
|
{Title: "Inception 2010 2160p 10bit Dolby Vision Atmos", DownloadURL: "https://pt/download/dovi", Seeders: 500},
|
||||||
|
{Title: "Inception 2010 1080p WEB-DL", DownloadURL: "https://pt/download/web", Seeders: 90},
|
||||||
|
}
|
||||||
|
availability := LocalAvailability{LocalMediaCount: 1, InLibrary: true, DownloadedEpisodes: 1, TotalEpisodes: 1}
|
||||||
|
|
||||||
|
got := selectSiteSearchCandidates(results, sub, map[string]struct{}{}, availability)
|
||||||
|
if len(got) != 0 {
|
||||||
|
t.Fatalf("selected %#v, want none (movie already in library, wash disabled)", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSelectSiteSearchCandidatesAllowsMovieWashUpgrade(t *testing.T) {
|
||||||
|
sub := &model.Subscription{Name: "Inception 自动订阅", Filter: "Inception 2010", MediaType: "movie", WashEnabled: true, WashPriority: "resolution"}
|
||||||
|
results := []SearchResult{
|
||||||
|
{Title: "Inception 2010 2160p REMUX", DownloadURL: "https://pt/download/2160", Seeders: 80},
|
||||||
|
{Title: "Inception 2010 1080p WEB-DL", DownloadURL: "https://pt/download/1080", Seeders: 200},
|
||||||
|
}
|
||||||
|
availability := LocalAvailability{LocalMediaCount: 1, InLibrary: true, DownloadedEpisodes: 1, TotalEpisodes: 1}
|
||||||
|
|
||||||
|
got := selectSiteSearchCandidates(results, sub, map[string]struct{}{}, availability)
|
||||||
|
if len(got) != 1 || got[0].Download != "https://pt/download/2160" {
|
||||||
|
t.Fatalf("selected %#v, want 2160p upgrade allowed when washing", got)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSubscriptionItemAlreadyAvailable(t *testing.T) {
|
||||||
|
movieSub := &model.Subscription{MediaType: "movie"}
|
||||||
|
if !subscriptionItemAlreadyAvailable(movieSub, LocalAvailability{LocalMediaCount: 1}, "Inception 2010 2160p") {
|
||||||
|
t.Fatal("movie already in library should be reported available")
|
||||||
|
}
|
||||||
|
if subscriptionItemAlreadyAvailable(movieSub, LocalAvailability{}, "Inception 2010 2160p") {
|
||||||
|
t.Fatal("empty library should not be reported available")
|
||||||
|
}
|
||||||
|
tvSub := &model.Subscription{MediaType: "tv"}
|
||||||
|
avail := LocalAvailability{LocalMediaCount: 1, ExistingEpisodeKeys: map[string]struct{}{episodeKey(1, 2): {}}}
|
||||||
|
if !subscriptionItemAlreadyAvailable(tvSub, avail, "Show S01E02 1080p") {
|
||||||
|
t.Fatal("existing episode should be reported available")
|
||||||
|
}
|
||||||
|
if subscriptionItemAlreadyAvailable(tvSub, avail, "Show S01E03 1080p") {
|
||||||
|
t.Fatal("missing episode should not be reported available")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -50,10 +50,11 @@ export function SubscriptionsPage() {
|
|||||||
search_mode: searchMode,
|
search_mode: searchMode,
|
||||||
imdb_id: imdbID || undefined,
|
imdb_id: imdbID || undefined,
|
||||||
resolution,
|
resolution,
|
||||||
quality: quality || undefined,
|
// 规则类字段发送原始字符串(含空串),以便编辑时可清空/修改;create 存空串无害,update 才能真正生效。
|
||||||
effects: effects || undefined,
|
quality,
|
||||||
release_groups: releaseGroups || undefined,
|
effects,
|
||||||
exclude_words: excludeWords || undefined,
|
release_groups: releaseGroups,
|
||||||
|
exclude_words: excludeWords,
|
||||||
wash_enabled: washEnabled,
|
wash_enabled: washEnabled,
|
||||||
wash_priority: washPriority,
|
wash_priority: washPriority,
|
||||||
priority: 50,
|
priority: 50,
|
||||||
|
|||||||
Reference in New Issue
Block a user