mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-30 19:46:38 +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.
110 lines
2.8 KiB
Go
110 lines
2.8 KiB
Go
// Package service — Fanart.tv image provider.
|
|
//
|
|
// Fanart.tv (https://fanart.tv) hosts community-curated artwork. We use
|
|
// it to upgrade movie / tv posters and backdrops with higher-resolution
|
|
// alternatives once a TMDb / Bangumi match is established.
|
|
//
|
|
// Endpoints used:
|
|
//
|
|
// GET /v3/movies/{tmdb_id} (artwork keyed by TMDb id)
|
|
// GET /v3/tv/{thetvdb_id} (artwork keyed by TheTVDB id)
|
|
//
|
|
// The provider is enabled iff secrets.fanart_tv_api_key is non-empty.
|
|
package service
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"time"
|
|
|
|
"go.uber.org/zap"
|
|
|
|
"github.com/ShukeBta/MediaStationGo/internal/config"
|
|
)
|
|
|
|
// FanartProvider talks to https://webservice.fanart.tv.
|
|
type FanartProvider struct {
|
|
cfg *config.Config
|
|
log *zap.Logger
|
|
client *http.Client
|
|
}
|
|
|
|
// NewFanartProvider is the constructor.
|
|
func NewFanartProvider(cfg *config.Config, log *zap.Logger) *FanartProvider {
|
|
return &FanartProvider{
|
|
cfg: cfg,
|
|
log: log,
|
|
client: &http.Client{Timeout: 15 * time.Second},
|
|
}
|
|
}
|
|
|
|
// Enabled reports whether an API key is configured.
|
|
func (f *FanartProvider) Enabled() bool { return f.cfg.Secrets.FanartAPIKey != "" }
|
|
|
|
// Artwork is the high-res image set returned by Fanart.tv.
|
|
type Artwork struct {
|
|
Poster string `json:"poster"`
|
|
Backdrop string `json:"backdrop"`
|
|
Logo string `json:"logo"`
|
|
Thumb string `json:"thumb"`
|
|
}
|
|
|
|
// MovieArtwork looks up the artwork bundle for a TMDb movie id.
|
|
func (f *FanartProvider) MovieArtwork(ctx context.Context, tmdbID int) (*Artwork, error) {
|
|
if !f.Enabled() || tmdbID <= 0 {
|
|
return nil, nil
|
|
}
|
|
type entry struct {
|
|
URL string `json:"url"`
|
|
Lang string `json:"lang"`
|
|
}
|
|
type page struct {
|
|
MoviePoster []entry `json:"movieposter"`
|
|
MovieBackgr []entry `json:"moviebackground"`
|
|
HDLogo []entry `json:"hdmovielogo"`
|
|
MovieThumb []entry `json:"moviethumb"`
|
|
}
|
|
u := fmt.Sprintf("https://webservice.fanart.tv/v3/movies/%d?api_key=%s",
|
|
tmdbID, f.cfg.Secrets.FanartAPIKey)
|
|
var p page
|
|
if err := f.getJSON(ctx, u, &p); err != nil {
|
|
return nil, err
|
|
}
|
|
a := &Artwork{}
|
|
if len(p.MoviePoster) > 0 {
|
|
a.Poster = p.MoviePoster[0].URL
|
|
}
|
|
if len(p.MovieBackgr) > 0 {
|
|
a.Backdrop = p.MovieBackgr[0].URL
|
|
}
|
|
if len(p.HDLogo) > 0 {
|
|
a.Logo = p.HDLogo[0].URL
|
|
}
|
|
if len(p.MovieThumb) > 0 {
|
|
a.Thumb = p.MovieThumb[0].URL
|
|
}
|
|
return a, nil
|
|
}
|
|
|
|
func (f *FanartProvider) getJSON(ctx context.Context, u string, out any) error {
|
|
req, err := http.NewRequestWithContext(ctx, http.MethodGet, u, nil)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
req.Header.Set("User-Agent", "MediaStationGo/0.1")
|
|
resp, err := f.client.Do(req)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
defer resp.Body.Close()
|
|
if resp.StatusCode == http.StatusNotFound {
|
|
return nil
|
|
}
|
|
if resp.StatusCode >= 400 {
|
|
return fmt.Errorf("fanart %s: %d", u, resp.StatusCode)
|
|
}
|
|
return json.NewDecoder(resp.Body).Decode(out)
|
|
}
|