mirror of
https://github.com/truewhile/MeBox.git
synced 2026-10-12 08:16:37 +08:00
fix: improve media grouping and bot startup
This commit is contained in:
@@ -2,7 +2,6 @@ package service
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
@@ -193,145 +192,3 @@ func (o *OrganizerService) lookupOrganizeAdultMetadata(ctx context.Context, src,
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func organizeMetadataMatchTrusted(query string, sourceYear int, match *Match) bool {
|
||||
if match == nil || strings.TrimSpace(match.Title) == "" {
|
||||
return false
|
||||
}
|
||||
if unsafeAutomaticEpisodeQuery(query) {
|
||||
return false
|
||||
}
|
||||
if sourceYear > 0 && match.Year > 0 {
|
||||
diff := sourceYear - match.Year
|
||||
if diff < 0 {
|
||||
diff = -diff
|
||||
}
|
||||
if diff > 1 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return automaticMetadataTitleTrusted(query, match)
|
||||
}
|
||||
|
||||
func organizeMatchFromLocalMetadata(local *LocalMetadata) *Match {
|
||||
if local == nil || strings.TrimSpace(local.Title) == "" {
|
||||
return nil
|
||||
}
|
||||
match := &Match{
|
||||
Title: strings.TrimSpace(local.Title),
|
||||
OriginalName: strings.TrimSpace(local.OriginalName),
|
||||
Overview: local.Overview,
|
||||
PosterURL: local.PosterURL,
|
||||
BackdropURL: local.BackdropURL,
|
||||
Year: local.Year,
|
||||
Rating: local.Rating,
|
||||
TMDbID: local.TMDbID,
|
||||
DoubanID: local.DoubanID,
|
||||
TheTVDBID: local.TheTVDBID,
|
||||
NSFW: local.NSFW,
|
||||
}
|
||||
if local.Genres != "" {
|
||||
match.Genres = splitNFOList(local.Genres)
|
||||
}
|
||||
if local.Countries != "" {
|
||||
match.Countries = splitNFOList(local.Countries)
|
||||
}
|
||||
if local.Languages != "" {
|
||||
match.Languages = splitNFOList(local.Languages)
|
||||
}
|
||||
return match
|
||||
}
|
||||
|
||||
func (o *OrganizerService) lookupOrganizeSourceMedia(ctx context.Context, path string) *model.Media {
|
||||
if o == nil || o.repo == nil || o.repo.DB == nil {
|
||||
return nil
|
||||
}
|
||||
path = filepath.Clean(strings.TrimSpace(path))
|
||||
if path == "" || path == "." {
|
||||
return nil
|
||||
}
|
||||
var media model.Media
|
||||
if err := o.repo.DB.WithContext(ctx).
|
||||
Where("path = ? AND deleted_at IS NULL", path).
|
||||
Limit(1).
|
||||
Take(&media).Error; err != nil {
|
||||
return nil
|
||||
}
|
||||
return &media
|
||||
}
|
||||
|
||||
func organizeMatchFromMedia(media *model.Media) *Match {
|
||||
if media == nil || strings.TrimSpace(media.Title) == "" {
|
||||
return nil
|
||||
}
|
||||
return &Match{
|
||||
TMDbID: media.TMDbID,
|
||||
BangumiID: media.BangumiID,
|
||||
DoubanID: strings.TrimSpace(media.DoubanID),
|
||||
TheTVDBID: strings.TrimSpace(media.TheTVDBID),
|
||||
Title: strings.TrimSpace(media.Title),
|
||||
OriginalName: strings.TrimSpace(media.OriginalName),
|
||||
Overview: media.Overview,
|
||||
PosterURL: media.PosterURL,
|
||||
BackdropURL: media.BackdropURL,
|
||||
Year: media.Year,
|
||||
Rating: media.Rating,
|
||||
Languages: parseCommaList(media.Languages),
|
||||
Countries: parseCommaList(media.Countries),
|
||||
Genres: parseCommaList(media.Genres),
|
||||
NSFW: media.NSFW,
|
||||
}
|
||||
}
|
||||
|
||||
func applyOrganizeMetadataMatch(match *Match, title, parsedTitle *string, year *int) {
|
||||
if match == nil {
|
||||
return
|
||||
}
|
||||
if matchedTitle := sanitizeFilename(strings.TrimSpace(match.Title)); matchedTitle != "" {
|
||||
*title = matchedTitle
|
||||
*parsedTitle = strings.TrimSpace(match.Title)
|
||||
}
|
||||
if match.Year > 0 {
|
||||
*year = match.Year
|
||||
}
|
||||
}
|
||||
|
||||
func organizeMetadataCacheKey(mediaType, query string, year int) string {
|
||||
return strings.ToLower(strings.TrimSpace(mediaType)) + "|" + fmt.Sprint(year) + "|" + strings.ToLower(strings.TrimSpace(query))
|
||||
}
|
||||
|
||||
func (o *OrganizerService) smartClassifySourceFile(ctx context.Context, src, sourceRoot, mediaType, title, parsedTitle string, metadataMatch *Match) string {
|
||||
if o == nil || !o.isSmartClassifyEnabled(ctx) {
|
||||
return ""
|
||||
}
|
||||
seriesLike := isSeriesLibraryType(mediaType)
|
||||
input := mediaClassifyInput{
|
||||
MediaType: mediaType,
|
||||
Title: strings.Join([]string{title, parsedTitle, filepath.Base(src)}, " "),
|
||||
Category: strings.Join(organizeDirectoryCategoryCandidates(src, sourceRoot), " "),
|
||||
}
|
||||
if metadataMatch != nil {
|
||||
input.Title = strings.Join([]string{
|
||||
metadataMatch.OriginalName,
|
||||
title,
|
||||
parsedTitle,
|
||||
filepath.Base(src),
|
||||
}, " ")
|
||||
input.Languages = metadataMatch.Languages
|
||||
input.Countries = metadataMatch.Countries
|
||||
input.Genres = metadataMatch.Genres
|
||||
if metadataMatch.NSFW {
|
||||
input.MediaType = "adult"
|
||||
}
|
||||
}
|
||||
if meta, err := ReadLocalMetadata(src, sourceRoot, seriesLike); err == nil && meta != nil && meta.HasNFO {
|
||||
input.Title = strings.Join([]string{meta.Title, meta.OriginalName, title, parsedTitle, filepath.Base(src)}, " ")
|
||||
input.Languages = parseCommaList(meta.Languages)
|
||||
input.Countries = parseCommaList(meta.Countries)
|
||||
input.Genres = parseCommaList(meta.Genres)
|
||||
if meta.NSFW {
|
||||
input.MediaType = "adult"
|
||||
}
|
||||
}
|
||||
return sanitizeFilename(classifyMediaCategory(input, o.categoryMap()))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user