Files
MeBox/internal/service/organizer_reclassify_media_rows.go
T
truewhile b0fe40142a Rebrand MMTL to MeBox (name, logo, Docker image) (#17)
* Rebrand MMTL to MeBox across codebase and assets

Rename the project display name, Go module path, environment variable
prefix (MEBOX_*), Docker image references, and UI branding from MMTL/mmtl
to MeBox/mebox. Replace logo assets with the new MeBox icon and keep
legacy SQLite migration support for existing mmtl.db deployments.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

* Fix logo icons: use cube-only crop without truncated text

Previous icon generation cropped too much of the source image, including
partial MeBox wordmark text that was cut off in square icon containers.
Regenerate logo-64/192/512, favicon, and SVG from cube-only region.

Co-authored-by: truewhile <truewhile@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: truewhile <truewhile@users.noreply.github.com>
2026-09-02 16:26:28 +08:00

113 lines
3.1 KiB
Go

package service
import (
"context"
"strings"
"github.com/truewhile/MeBox/internal/model"
)
func (o *OrganizerService) updateReclassifiedMediaRow(ctx context.Context, oldPath, newPath string, req organizeExistingReclassifyRequest) error {
if o == nil || o.repo == nil || o.repo.DB == nil {
return nil
}
updates := map[string]any{
"path": newPath,
}
if strings.TrimSpace(req.TargetLibraryID) != "" {
updates["library_id"] = strings.TrimSpace(req.TargetLibraryID)
}
if strings.TrimSpace(req.Title) != "" {
updates["title"] = strings.TrimSpace(req.Title)
}
if req.Year > 0 {
updates["year"] = req.Year
}
if normalizeOrganizeMediaType(req.MediaType) == "movie" {
updates["season_num"] = 0
updates["episode_num"] = 0
} else if req.Season > 0 {
updates["season_num"] = req.Season
if req.Episode > 0 {
updates["episode_num"] = req.Episode
}
} else if req.Episode > 0 {
updates["episode_num"] = req.Episode
}
applyReclassifyMatchUpdates(updates, req.MetadataMatch)
return o.repo.DB.WithContext(ctx).Model(&model.Media{}).Where("path = ?", oldPath).Updates(updates).Error
}
func applyReclassifyMatchUpdates(updates map[string]any, match *Match) {
if updates == nil || match == nil {
return
}
if value := strings.TrimSpace(match.Title); value != "" {
updates["title"] = value
}
if value := strings.TrimSpace(match.OriginalName); value != "" {
updates["original_name"] = value
}
if value := strings.TrimSpace(match.Overview); value != "" {
updates["overview"] = value
}
if value := strings.TrimSpace(match.PosterURL); value != "" {
updates["poster_url"] = value
}
if value := strings.TrimSpace(match.BackdropURL); value != "" {
updates["backdrop_url"] = value
}
if match.Rating > 0 {
updates["rating"] = match.Rating
}
if match.Year > 0 {
updates["year"] = match.Year
}
if value := strings.TrimSpace(match.ReleaseDate); value != "" {
updates["release_date"] = value
}
if match.TMDbID > 0 {
updates["tm_db_id"] = match.TMDbID
}
if match.BangumiID > 0 {
updates["bangumi_id"] = match.BangumiID
}
if value := strings.TrimSpace(match.DoubanID); value != "" {
updates["douban_id"] = value
}
if value := strings.TrimSpace(match.TheTVDBID); value != "" {
updates["thetvdb_id"] = value
}
if len(match.Genres) > 0 {
updates["genres"] = strings.Join(match.Genres, ",")
}
if len(match.Countries) > 0 {
updates["countries"] = strings.Join(match.Countries, ",")
}
if len(match.Languages) > 0 {
updates["languages"] = strings.Join(match.Languages, ",")
}
if match.NSFW {
updates["nsfw"] = true
}
updates["scrape_status"] = "matched"
}
func (o *OrganizerService) deleteMediaRowForPath(ctx context.Context, path string) {
if o == nil || o.repo == nil || o.repo.DB == nil {
return
}
_ = o.repo.DB.WithContext(ctx).Unscoped().Where("path = ?", path).Delete(&model.Media{}).Error
}
func (o *OrganizerService) mediaPathExists(ctx context.Context, path string) bool {
if o == nil || o.repo == nil || o.repo.DB == nil {
return false
}
var count int64
if err := o.repo.DB.WithContext(ctx).Unscoped().Model(&model.Media{}).Where("path = ?", path).Count(&count).Error; err != nil {
return false
}
return count > 0
}