mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-01 12:06:38 +08:00
优化
优化
This commit is contained in:
@@ -3,42 +3,18 @@ package handler
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.uber.org/zap"
|
||||
|
||||
"github.com/ShukeBta/MediaStationGo/internal/service"
|
||||
)
|
||||
|
||||
func reclassifyMediaAfterScrape(ctx context.Context, svc *service.Container, mediaIDs ...string) int {
|
||||
return reclassifyMediaAfterScrapeWithTypeHints(ctx, svc, nil, mediaIDs...)
|
||||
// 刮削元数据时不再自动跨库纠偏或自动创建新媒体库,保持在当前媒体库内仅更新元数据
|
||||
func reclassifyMediaAfterScrape(_ context.Context, _ *service.Container, _ ...string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func reclassifyMediaAfterScrapeWithTypeHints(ctx context.Context, svc *service.Container, mediaTypeHints map[string]string, mediaIDs ...string) int {
|
||||
if svc == nil || svc.Organizer == nil {
|
||||
return 0
|
||||
}
|
||||
res, err := svc.Organizer.ReclassifyMisclassifiedMedia(ctx, service.MediaCategoryReclassifyOptions{
|
||||
MediaIDs: mediaIDs,
|
||||
MediaTypeHints: mediaTypeHints,
|
||||
})
|
||||
if err != nil {
|
||||
if svc.Log != nil {
|
||||
svc.Log.Warn("scrape reclassify media failed", zap.Strings("media_ids", mediaIDs), zap.Error(err))
|
||||
}
|
||||
return 0
|
||||
}
|
||||
return res.Reclassified
|
||||
func reclassifyMediaAfterScrapeWithTypeHints(_ context.Context, _ *service.Container, _ map[string]string, _ ...string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
func reclassifyLibraryAfterScrape(ctx context.Context, svc *service.Container, libraryIDs ...string) int {
|
||||
if svc == nil || svc.Organizer == nil {
|
||||
return 0
|
||||
}
|
||||
res, err := svc.Organizer.ReclassifyMisclassifiedMedia(ctx, service.MediaCategoryReclassifyOptions{LibraryIDs: libraryIDs})
|
||||
if err != nil {
|
||||
if svc.Log != nil {
|
||||
svc.Log.Warn("scrape reclassify library failed", zap.Strings("library_ids", libraryIDs), zap.Error(err))
|
||||
}
|
||||
return 0
|
||||
}
|
||||
return res.Reclassified
|
||||
func reclassifyLibraryAfterScrape(_ context.Context, _ *service.Container, _ ...string) int {
|
||||
return 0
|
||||
}
|
||||
|
||||
@@ -119,32 +119,32 @@ func (c *Container) RepairAndRescrapeAllLibraries(ctx context.Context, options .
|
||||
result.Errors++
|
||||
continue
|
||||
}
|
||||
result.Matched += scrapeResult.Matched
|
||||
result.Processed += scrapeResult.Processed
|
||||
result.Errors += scrapeResult.Failed
|
||||
}
|
||||
if c.Organizer != nil {
|
||||
reclassifyResult, err := c.Organizer.ReclassifyMisclassifiedMedia(ctx, MediaCategoryReclassifyOptions{})
|
||||
if err != nil {
|
||||
return result, err
|
||||
result.Matched += scrapeResult.Matched
|
||||
result.Processed += scrapeResult.Processed
|
||||
result.Errors += scrapeResult.Failed
|
||||
}
|
||||
if reclassifyResult != nil {
|
||||
result.Reclassified = reclassifyResult.Reclassified
|
||||
result.Errors += len(reclassifyResult.Errors)
|
||||
c.invalidateRepairReclassifyCache(ctx, reclassifyResult.Reclassified)
|
||||
if c.Organizer != nil {
|
||||
reclassifyResult, err := c.Organizer.ReclassifyMisclassifiedMedia(ctx, MediaCategoryReclassifyOptions{})
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
if reclassifyResult != nil {
|
||||
result.Reclassified = reclassifyResult.Reclassified
|
||||
result.Errors += len(reclassifyResult.Errors)
|
||||
c.invalidateRepairReclassifyCache(ctx, reclassifyResult.Reclassified)
|
||||
}
|
||||
}
|
||||
if c.Log != nil {
|
||||
c.Log.Info("repair and rescrape all libraries done",
|
||||
zap.Int("repaired", result.Repaired),
|
||||
zap.Int("reclassified", result.Reclassified),
|
||||
zap.Int("libraries", result.Libraries),
|
||||
zap.Int("matched", result.Matched),
|
||||
zap.Int("processed", result.Processed),
|
||||
zap.Int("errors", result.Errors))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
if c.Log != nil {
|
||||
c.Log.Info("repair and rescrape all libraries done",
|
||||
zap.Int("repaired", result.Repaired),
|
||||
zap.Int("reclassified", result.Reclassified),
|
||||
zap.Int("libraries", result.Libraries),
|
||||
zap.Int("matched", result.Matched),
|
||||
zap.Int("processed", result.Processed),
|
||||
zap.Int("errors", result.Errors))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// RepairAndRescrapeLibrary 修复并重刮单个媒体库:先从该库媒体路径中的占位符
|
||||
// 回填缺失/错误的外部 ID(重置相关行 scrape_status=pending),再对该库重刮
|
||||
@@ -182,31 +182,31 @@ func (c *Container) RepairAndRescrapeLibrary(ctx context.Context, libraryID stri
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
result.Matched = scrapeResult.Matched
|
||||
result.Processed = scrapeResult.Processed
|
||||
result.Errors = scrapeResult.Failed
|
||||
if c.Organizer != nil {
|
||||
reclassifyResult, err := c.Organizer.ReclassifyMisclassifiedMedia(ctx, MediaCategoryReclassifyOptions{LibraryIDs: libraryIDs})
|
||||
if err != nil {
|
||||
return result, err
|
||||
result.Matched = scrapeResult.Matched
|
||||
result.Processed = scrapeResult.Processed
|
||||
result.Errors = scrapeResult.Failed
|
||||
if c.Organizer != nil {
|
||||
reclassifyResult, err := c.Organizer.ReclassifyMisclassifiedMedia(ctx, MediaCategoryReclassifyOptions{LibraryIDs: libraryIDs})
|
||||
if err != nil {
|
||||
return result, err
|
||||
}
|
||||
if reclassifyResult != nil {
|
||||
result.Reclassified = reclassifyResult.Reclassified
|
||||
result.Errors += len(reclassifyResult.Errors)
|
||||
c.invalidateRepairReclassifyCache(ctx, reclassifyResult.Reclassified)
|
||||
}
|
||||
}
|
||||
if reclassifyResult != nil {
|
||||
result.Reclassified = reclassifyResult.Reclassified
|
||||
result.Errors += len(reclassifyResult.Errors)
|
||||
c.invalidateRepairReclassifyCache(ctx, reclassifyResult.Reclassified)
|
||||
if c.Log != nil {
|
||||
c.Log.Info("repair and rescrape library done",
|
||||
zap.String("library", libraryID),
|
||||
zap.Int("repaired", result.Repaired),
|
||||
zap.Int("reclassified", result.Reclassified),
|
||||
zap.Int("matched", result.Matched),
|
||||
zap.Int("processed", result.Processed),
|
||||
zap.Int("errors", result.Errors))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
if c.Log != nil {
|
||||
c.Log.Info("repair and rescrape library done",
|
||||
zap.String("library", libraryID),
|
||||
zap.Int("repaired", result.Repaired),
|
||||
zap.Int("reclassified", result.Reclassified),
|
||||
zap.Int("matched", result.Matched),
|
||||
zap.Int("processed", result.Processed),
|
||||
zap.Int("errors", result.Errors))
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
func (c *Container) invalidateRepairReclassifyCache(ctx context.Context, changed int) {
|
||||
if c == nil || c.Cache == nil || changed <= 0 {
|
||||
|
||||
@@ -18,19 +18,10 @@ func (s *ScannerService) startAutoScrape(ctx context.Context, libraryID string)
|
||||
scrapeCtx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 30*time.Minute)
|
||||
go func() {
|
||||
defer cancel()
|
||||
result, err := s.scraper.EnrichLibraryDetailedWithOptions(scrapeCtx, libraryID, skipEpisodeArtworkOptions(false))
|
||||
_, err := s.scraper.EnrichLibraryDetailedWithOptions(scrapeCtx, libraryID, skipEpisodeArtworkOptions(false))
|
||||
if err != nil {
|
||||
s.log.Warn("scraper enrich failed", zap.Error(err))
|
||||
return
|
||||
}
|
||||
if result.Processed > 0 && s.organizer != nil {
|
||||
if reclassified, err := s.organizer.ReclassifyMisclassifiedMedia(scrapeCtx, MediaCategoryReclassifyOptions{LibraryIDs: []string{libraryID}}); err != nil {
|
||||
s.log.Warn("scrape auto reclassify failed", zap.String("library_id", libraryID), zap.Error(err))
|
||||
} else if reclassified.Reclassified > 0 {
|
||||
s.log.Info("scrape auto reclassified media",
|
||||
zap.String("library_id", libraryID),
|
||||
zap.Int("reclassified", reclassified.Reclassified))
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user