This commit is contained in:
ponzischeme89
2026-08-19 06:57:59 +12:00
parent 8c847c59b8
commit 2b43b9ef12
94 changed files with 6359 additions and 778 deletions
+42 -3
View File
@@ -56,6 +56,13 @@ type radarrScheduleItem struct {
MembyLifecycle string `json:"MembyLifecycle,omitempty"`
MembyLifecycleText string `json:"MembyLifecycleText,omitempty"`
MembyPlayable bool `json:"MembyPlayable"`
// The Emby film this card stands for, when the library already holds it — the
// MembySeriesItemId arrangement, and for the same reason: it is what decides whether
// pressing the card opens the ordinary Memby page or the Radarr-only one. A film the
// household has not downloaded carries none. The detail route resolves it again from
// live data, because this row is cached for the day and a film imported at lunchtime
// must not be stuck behind a cache until midnight.
MembyMovieItemID string `json:"MembyMovieItemId,omitempty"`
}
func (s *Server) radarrUpcomingMoviesRow(ctx context.Context) (*recommend.Row, error) {
@@ -90,7 +97,7 @@ func (s *Server) radarrUpcomingMoviesRow(ctx context.Context) (*recommend.Row, e
if err != nil {
return nil, err
}
row, err := buildRadarrRow(movies, now, location)
row, err := buildRadarrRow(movies, now, location, s.embyMovieIndex(ctx, movies))
if err != nil {
return nil, err
}
@@ -114,7 +121,37 @@ func (s *Server) cachedRadarrRow(ctx context.Context, key string) *recommend.Row
return &row
}
func buildRadarrRow(movies []radarr.Movie, now time.Time, location *time.Location) (*recommend.Row, error) {
// embyMovieIndex answers which of these films Emby already holds, keyed by TMDb id.
//
// Films are matched on the id both systems record rather than on their titles, which is
// what the Sonarr schedule row has to fall back on: Radarr writes a TMDb id and the
// library import asks Emby for ProviderIds, so there is nothing here to guess at. A
// failure is not fatal — the row is about what is coming, and losing the link only costs a
// downloaded card its ordinary detail page.
func (s *Server) embyMovieIndex(ctx context.Context, movies []radarr.Movie) map[int]string {
if s.store == nil || len(movies) == 0 {
return nil
}
ids := make([]int, 0, len(movies))
for _, movie := range movies {
if movie.TMDBID > 0 {
ids = append(ids, movie.TMDBID)
}
}
found, err := s.store.LibraryProviderItemIDs(ctx, "Tmdb", ids)
if err != nil {
s.loggerFor(ctx).Warn("emby movie index unavailable for schedule row", "error", err)
return nil
}
return found
}
func buildRadarrRow(
movies []radarr.Movie,
now time.Time,
location *time.Location,
embyItems map[int]string,
) (*recommend.Row, error) {
sort.SliceStable(movies, func(i, j int) bool {
left, leftOK := effectiveRadarrRelease(movies[i])
right, rightOK := effectiveRadarrRelease(movies[j])
@@ -139,7 +176,9 @@ func buildRadarrRow(movies []radarr.Movie, now time.Time, location *time.Locatio
if localRelease.Before(dayStart) || !localRelease.Before(windowEnd) {
continue
}
raw, err := json.Marshal(toRadarrScheduleItem(movie, release, now, location))
item := toRadarrScheduleItem(movie, release, now, location)
item.MembyMovieItemID = embyItems[movie.TMDBID]
raw, err := json.Marshal(item)
if err != nil {
return nil, err
}