mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-30 03:36:37 +08:00
8824638efb
Backend
- service/transcoder.go: encoder selector (software / nvenc / qsv /
vaapi) with proper hwaccel + scale_* filters per encoder; configurable
bitrate/preset/height/segment-seconds via transcoder.* config; new
Active() snapshot + ActiveJob struct for the Tasks panel; unit-tested
via buildFFmpegArgs(...).
- service/thetvdb.go: TheTVDB v4 provider — login() caches the JWT for
24h, SearchSeries() returns Match struct.
- service/fanart.go: Fanart.tv provider — high-res movie artwork keyed
by TMDb id; used to upgrade poster/backdrop after a successful match.
- service/scraper.go: provider chain reworked — anime → Bangumi, tv →
TheTVDB, default → TMDb, with optional Fanart upgrade post-match.
- service/discover.go: TMDb /trending/movie/day + /movie/popular for
the Discover rail.
- service/ai.go: OpenAI-compatible client. SmartSearch() turns a free-
form query into a structured SearchIntent JSON; Recommend() emits a
short list of titles given the user's history. Disabled when
ai.api_key is empty.
- service/nfo.go: per-movie .nfo writer (Kodi/Jellyfin schema) +
library-scope batch exporter.
- service/media.go: SoftDelete / Restore / Purge / ListRecycleBin
helpers backed by gorm Unscoped().
- service/service.go: container wires Fanart, TheTVDB, Discover, AI,
NFO; everything still tears down cleanly via Close().
- config: new transcoder.* section (encoder, preset, video_bitrate,
max_rate, buf_size, max_height, segment_seconds) with sensible
defaults.
Handlers / routes
- new files: discover.go, recycle.go, nfo.go, ai.go, tasks.go.
- registers GET /tasks, /discover/{trending,popular},
/ai/{status,search,recommend}; admin-only GET /recycle and
DELETE/POST /media/:id (soft delete / restore / purge); admin-only
POST /media/:id/nfo and /libraries/:id/nfo.
Frontend
- new pages: DiscoverPage, TasksPage, RecycleBinPage; SearchPage gains
an optional AI smart-search toggle that calls /api/ai/search.
- MediaDetailPage gains admin actions for 导出 NFO and 移至回收站.
- new api/ helpers: ai.ts, discover.ts, recycle.ts, tasks.ts.
- App.tsx routes /discover, /tasks, /recycle (last two admin-only).
- Layout sidebar groups now include Discover + Tasks + Recycle Bin.
Docker / config
- Dockerfile: adds intel-media-driver / libva-utils / mesa-va-gallium
so QSV + VAAPI work out of the box on Intel iGPUs.
- docker-compose.yml: documents devices + group_add + nvidia runtime
overrides for hardware transcoding.
Verified: go build, go vet, go test (incl. new TestBuildFFmpegArgs across
software / nvenc / qsv / vaapi encoder profiles); tsc -b && vite build
emits 22 route chunks plus the deferred hls chunk; main bundle 248 KB /
83 KB gzipped.
118 lines
3.0 KiB
Go
118 lines
3.0 KiB
Go
// Package service — TMDb discovery (trending / popular).
|
|
//
|
|
// DiscoverService surfaces curated lists from TMDb so the React home
|
|
// page can show "Trending" and "Popular" rails alongside the user's own
|
|
// library. All methods gracefully no-op when the TMDb provider is
|
|
// disabled.
|
|
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
)
|
|
|
|
// DiscoverService talks to TMDb's /trending and /movie/popular endpoints.
|
|
type DiscoverService struct {
|
|
log *zap.Logger
|
|
tmdb *TMDbProvider
|
|
client *http.Client
|
|
}
|
|
|
|
// NewDiscoverService is the constructor.
|
|
func NewDiscoverService(log *zap.Logger, tmdb *TMDbProvider) *DiscoverService {
|
|
return &DiscoverService{
|
|
log: log,
|
|
tmdb: tmdb,
|
|
client: &http.Client{Timeout: 15 * time.Second},
|
|
}
|
|
}
|
|
|
|
// Trending returns the daily trending movies (TMDb /trending/movie/day).
|
|
func (d *DiscoverService) Trending(ctx context.Context) ([]Match, error) {
|
|
return d.fetch(ctx, "/trending/movie/day")
|
|
}
|
|
|
|
// Popular returns the popular movies list (TMDb /movie/popular).
|
|
func (d *DiscoverService) Popular(ctx context.Context) ([]Match, error) {
|
|
return d.fetch(ctx, "/movie/popular")
|
|
}
|
|
|
|
// fetch is the shared helper that paginates page=1 only — that's all the
|
|
// home page needs and it keeps us under TMDb's 50 rps limit.
|
|
func (d *DiscoverService) fetch(ctx context.Context, path string) ([]Match, error) {
|
|
if d.tmdb == nil || !d.tmdb.Enabled() {
|
|
return nil, nil
|
|
}
|
|
q := url.Values{}
|
|
q.Set("api_key", d.tmdb.cfg.Secrets.TMDbAPIKey)
|
|
q.Set("language", "zh-CN")
|
|
q.Set("page", "1")
|
|
u := d.tmdb.base + path + "?" + q.Encode()
|
|
|
|
type result struct {
|
|
ID int `json:"id"`
|
|
Title string `json:"title"`
|
|
Name string `json:"name"`
|
|
Overview string `json:"overview"`
|
|
PosterPath string `json:"poster_path"`
|
|
BackdropPath string `json:"backdrop_path"`
|
|
ReleaseDate string `json:"release_date"`
|
|
FirstAirDate string `json:"first_air_date"`
|
|
VoteAverage float32 `json:"vote_average"`
|
|
}
|
|
type page struct {
|
|
Results []result `json:"results"`
|
|
}
|
|
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
resp, err := d.client.Do(req)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode >= 400 {
|
|
return nil, fmt.Errorf("tmdb %s: %d", path, resp.StatusCode)
|
|
}
|
|
var p page
|
|
if err := json.NewDecoder(resp.Body).Decode(&p); err != nil {
|
|
return nil, err
|
|
}
|
|
out := make([]Match, 0, len(p.Results))
|
|
for _, r := range p.Results {
|
|
title := r.Title
|
|
if title == "" {
|
|
title = r.Name
|
|
}
|
|
m := Match{
|
|
TMDbID: r.ID,
|
|
Title: title,
|
|
Overview: r.Overview,
|
|
Rating: r.VoteAverage,
|
|
}
|
|
if r.PosterPath != "" {
|
|
m.PosterURL = d.tmdb.imgCDN + "/w500" + r.PosterPath
|
|
}
|
|
if r.BackdropPath != "" {
|
|
m.BackdropURL = d.tmdb.imgCDN + "/w1280" + r.BackdropPath
|
|
}
|
|
date := r.ReleaseDate
|
|
if date == "" {
|
|
date = r.FirstAirDate
|
|
}
|
|
if len(date) >= 4 {
|
|
fmt.Sscanf(date[:4], "%d", &m.Year)
|
|
}
|
|
out = append(out, m)
|
|
}
|
|
return out, nil
|
|
}
|