mirror of
https://github.com/truewhile/MeBox.git
synced 2026-09-29 03:26:37 +08:00
fix: load real discover posters
This commit is contained in:
@@ -96,7 +96,7 @@ func (b *BangumiProvider) Search(ctx context.Context, query string) (*Match, err
|
||||
BangumiID: r.ID,
|
||||
Title: title,
|
||||
Overview: r.Summary,
|
||||
PosterURL: r.Images.Large,
|
||||
PosterURL: normalizeBangumiImageURL(r.Images.Large),
|
||||
Rating: r.Rating.Score,
|
||||
}
|
||||
if len(r.Air) >= 4 {
|
||||
@@ -141,7 +141,7 @@ func (b *BangumiProvider) GetSubject(ctx context.Context, bangumiID int) (*Match
|
||||
Title: title,
|
||||
OriginalName: r.Name,
|
||||
Overview: r.Summary,
|
||||
PosterURL: firstText(r.Images.Large, r.Images.Common),
|
||||
PosterURL: normalizeBangumiImageURL(firstText(r.Images.Large, r.Images.Common)),
|
||||
Rating: r.Rating.Score,
|
||||
}
|
||||
if len(r.Air) >= 4 {
|
||||
@@ -192,3 +192,26 @@ func (b *BangumiProvider) getJSON(ctx context.Context, u string, out any) error
|
||||
}
|
||||
return json.NewDecoder(resp.Body).Decode(out)
|
||||
}
|
||||
|
||||
func normalizeBangumiImageURL(raw string) string {
|
||||
raw = strings.TrimSpace(raw)
|
||||
if raw == "" {
|
||||
return ""
|
||||
}
|
||||
if strings.HasPrefix(raw, "//") {
|
||||
raw = "https:" + raw
|
||||
}
|
||||
u, err := url.Parse(raw)
|
||||
if err != nil || u.Host == "" {
|
||||
return raw
|
||||
}
|
||||
host := strings.ToLower(u.Host)
|
||||
if host != "lain.bgm.tv" && host != "bgm.tv" && !strings.HasSuffix(host, ".bgm.tv") {
|
||||
return raw
|
||||
}
|
||||
u.Scheme = "https"
|
||||
if strings.HasPrefix(u.Path, "/pic/cover/") {
|
||||
u.Path = "/r/400" + u.Path
|
||||
}
|
||||
return u.String()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package service
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestNormalizeBangumiImageURLUsesHTTPSResizedCover(t *testing.T) {
|
||||
got := normalizeBangumiImageURL("http://lain.bgm.tv/pic/cover/l/27/ff/377130_wDU1x.jpg")
|
||||
want := "https://lain.bgm.tv/r/400/pic/cover/l/27/ff/377130_wDU1x.jpg"
|
||||
if got != want {
|
||||
t.Fatalf("url = %q, want %q", got, want)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNormalizeBangumiImageURLLeavesExternalHostsAlone(t *testing.T) {
|
||||
raw := "https://image.tmdb.org/t/p/w500/poster.jpg"
|
||||
if got := normalizeBangumiImageURL(raw); got != raw {
|
||||
t.Fatalf("url = %q, want %q", got, raw)
|
||||
}
|
||||
}
|
||||
@@ -312,6 +312,7 @@ func (b *BangumiProvider) Calendar(ctx context.Context) ([]ExternalMediaResult,
|
||||
if poster == "" {
|
||||
poster = item.Images.Common
|
||||
}
|
||||
poster = normalizeBangumiImageURL(poster)
|
||||
year := 0
|
||||
if len(item.AirDate) >= 4 {
|
||||
year, _ = strconv.Atoi(item.AirDate[:4])
|
||||
|
||||
@@ -10,9 +10,9 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
discoverArtworkPrefetchLimit = 48
|
||||
discoverArtworkPrefetchConcurrency = 4
|
||||
discoverArtworkPrefetchTimeout = 45 * time.Second
|
||||
discoverArtworkPrefetchLimit = 384
|
||||
discoverArtworkPrefetchConcurrency = 8
|
||||
discoverArtworkPrefetchTimeout = 90 * time.Second
|
||||
)
|
||||
|
||||
func (d *DiscoverService) SetImageProxy(images *ImageProxy) *DiscoverService {
|
||||
@@ -23,19 +23,33 @@ func (d *DiscoverService) SetImageProxy(images *ImageProxy) *DiscoverService {
|
||||
}
|
||||
|
||||
func (d *DiscoverService) WarmMatchArtwork(items []Match) int {
|
||||
return d.warmArtworkURLs(matchArtworkURLs(items))
|
||||
}
|
||||
|
||||
func matchArtworkURLs(items []Match) []string {
|
||||
urls := make([]string, 0, len(items)*2)
|
||||
for _, item := range items {
|
||||
urls = append(urls, item.PosterURL, item.BackdropURL)
|
||||
urls = append(urls, item.PosterURL)
|
||||
}
|
||||
return d.warmArtworkURLs(urls)
|
||||
for _, item := range items {
|
||||
urls = append(urls, item.BackdropURL)
|
||||
}
|
||||
return urls
|
||||
}
|
||||
|
||||
func (d *DiscoverService) WarmExternalArtwork(items []ExternalMediaResult) int {
|
||||
return d.warmArtworkURLs(externalArtworkURLs(items))
|
||||
}
|
||||
|
||||
func externalArtworkURLs(items []ExternalMediaResult) []string {
|
||||
urls := make([]string, 0, len(items)*2)
|
||||
for _, item := range items {
|
||||
urls = append(urls, item.PosterURL, item.BackdropURL)
|
||||
urls = append(urls, item.PosterURL)
|
||||
}
|
||||
return d.warmArtworkURLs(urls)
|
||||
for _, item := range items {
|
||||
urls = append(urls, item.BackdropURL)
|
||||
}
|
||||
return urls
|
||||
}
|
||||
|
||||
func (d *DiscoverService) warmArtworkURLs(urls []string) int {
|
||||
|
||||
@@ -32,6 +32,28 @@ func TestUniqueDiscoverArtworkURLsFiltersDuplicatesAndLimits(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverArtworkURLsPrioritizePosters(t *testing.T) {
|
||||
items := []ExternalMediaResult{
|
||||
{PosterURL: "https://img.example/a-poster.jpg", BackdropURL: "https://img.example/a-backdrop.jpg"},
|
||||
{PosterURL: "https://img.example/b-poster.jpg", BackdropURL: "https://img.example/b-backdrop.jpg"},
|
||||
}
|
||||
urls := externalArtworkURLs(items)
|
||||
want := []string{
|
||||
"https://img.example/a-poster.jpg",
|
||||
"https://img.example/b-poster.jpg",
|
||||
"https://img.example/a-backdrop.jpg",
|
||||
"https://img.example/b-backdrop.jpg",
|
||||
}
|
||||
if len(urls) != len(want) {
|
||||
t.Fatalf("len = %d, want %d: %v", len(urls), len(want), urls)
|
||||
}
|
||||
for i := range want {
|
||||
if urls[i] != want[i] {
|
||||
t.Fatalf("url[%d] = %q, want %q", i, urls[i], want[i])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestDiscoverWarmExternalArtworkPrefetchesAndCaches(t *testing.T) {
|
||||
proxy := NewImageProxy(&config.Config{Cache: config.CacheConfig{CacheDir: filepath.Join(t.TempDir(), "cache")}}, zap.NewNop())
|
||||
var calls int32
|
||||
|
||||
@@ -128,7 +128,8 @@ function DiscoverCard({
|
||||
<img
|
||||
src={posterSrc}
|
||||
alt={item.title}
|
||||
loading="lazy"
|
||||
loading="eager"
|
||||
decoding="async"
|
||||
referrerPolicy="no-referrer"
|
||||
onError={markPosterUnavailable}
|
||||
onLoad={(event) => {
|
||||
|
||||
@@ -10,7 +10,7 @@ export const defaultSections = [
|
||||
]
|
||||
|
||||
export const discoverStorageKey = 'mediastation.discover.sections'
|
||||
const discoverStorageVersion = 2
|
||||
const discoverStorageVersion = 3
|
||||
const legacyDefaultAdditions = ['tmdb_latest_movie', 'tmdb_latest_tv']
|
||||
|
||||
export const defaultSectionDefs: DiscoverSection[] = [
|
||||
|
||||
Reference in New Issue
Block a user