Publish current app and server
This commit is contained in:
@@ -14,8 +14,9 @@ import (
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
)
|
||||
|
||||
const sonarrCalendarCachePrefix = "sonarr:calendar:"
|
||||
const sonarrPrerollCachePrefix = "sonarr:preroll:"
|
||||
const sonarrCalendarCachePrefix = "sonarr:calendar:v2:"
|
||||
const sonarrPrerollCachePrefix = "sonarr:preroll:v2:"
|
||||
const sonarrScheduleDays = 5
|
||||
|
||||
type prerollScheduleResponse struct {
|
||||
Today []prerollScheduleEntry `json:"today"`
|
||||
@@ -23,6 +24,8 @@ type prerollScheduleResponse struct {
|
||||
}
|
||||
|
||||
type prerollScheduleEntry struct {
|
||||
ItemID string `json:"itemId"`
|
||||
ImageType string `json:"imageType,omitempty"`
|
||||
Series string `json:"series"`
|
||||
Episode string `json:"episode"`
|
||||
EpisodeCode string `json:"episodeCode"`
|
||||
@@ -103,12 +106,22 @@ func buildPrerollSchedule(
|
||||
continue
|
||||
}
|
||||
airTime := episode.AirDateUTC.In(location)
|
||||
seriesID := episode.Series.ID
|
||||
if seriesID == 0 {
|
||||
seriesID = episode.SeriesID
|
||||
}
|
||||
entry := prerollScheduleEntry{
|
||||
ItemID: fmt.Sprintf("sonarr:%d:%d", seriesID, episode.ID),
|
||||
Series: episode.Series.Title,
|
||||
Episode: episode.Title,
|
||||
EpisodeCode: fmt.Sprintf("S%02dE%02d", episode.SeasonNumber, episode.EpisodeNumber),
|
||||
Availability: prerollAvailability(episode),
|
||||
}
|
||||
if hasCover(episode.Series.Images, "fanart") {
|
||||
entry.ImageType = "backdrop"
|
||||
} else if hasCover(episode.Series.Images, "poster") {
|
||||
entry.ImageType = "primary"
|
||||
}
|
||||
if airTime.Before(todayEnd) {
|
||||
entry.Schedule = airTime.Format("3:04 PM")
|
||||
if len(result.Today) < 4 {
|
||||
@@ -169,6 +182,7 @@ type sonarrScheduleItem struct {
|
||||
MembyEpisodeCode string `json:"MembyEpisodeCode"`
|
||||
MembyAirsAt string `json:"MembyAirsAt,omitempty"`
|
||||
MembyAddedAt string `json:"MembyAddedAt,omitempty"`
|
||||
MembyAirDayLabel string `json:"MembyAirDayLabel"`
|
||||
MembyAirLabel string `json:"MembyAirLabel"`
|
||||
MembyAvailability string `json:"MembyAvailability"`
|
||||
MembyAvailabilityText string `json:"MembyAvailabilityText"`
|
||||
@@ -199,7 +213,11 @@ func (s *Server) sonarrAiringTodayRow(ctx context.Context) (*recommend.Row, erro
|
||||
return row, nil
|
||||
}
|
||||
|
||||
episodes, err := s.sonarr.Calendar(ctx, dayStart, dayStart.AddDate(0, 0, 1))
|
||||
episodes, err := s.sonarr.Calendar(
|
||||
ctx,
|
||||
dayStart,
|
||||
dayStart.AddDate(0, 0, sonarrScheduleDays),
|
||||
)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -240,7 +258,16 @@ func buildSonarrRow(episodes []sonarr.Episode, now time.Time, location *time.Loc
|
||||
})
|
||||
|
||||
items := make([]json.RawMessage, 0, len(episodes))
|
||||
dayStart := localDayStart(now, location)
|
||||
windowEnd := dayStart.AddDate(0, 0, sonarrScheduleDays)
|
||||
for _, episode := range episodes {
|
||||
if episode.AirDateUTC == nil {
|
||||
continue
|
||||
}
|
||||
localAirTime := episode.AirDateUTC.In(location)
|
||||
if localAirTime.Before(dayStart) || !localAirTime.Before(windowEnd) {
|
||||
continue
|
||||
}
|
||||
item := toSonarrScheduleItem(episode, now, location)
|
||||
raw, err := json.Marshal(item)
|
||||
if err != nil {
|
||||
@@ -250,7 +277,7 @@ func buildSonarrRow(episodes []sonarr.Episode, now time.Time, location *time.Loc
|
||||
}
|
||||
return &recommend.Row{
|
||||
ID: "sonarr-airing-today",
|
||||
Title: "Shows airing today",
|
||||
Title: "Shows airing in the next 5 days",
|
||||
Kind: "schedule",
|
||||
Items: items,
|
||||
}, nil
|
||||
@@ -286,13 +313,11 @@ func toSonarrScheduleItem(episode sonarr.Episode, now time.Time, location *time.
|
||||
if episode.AirDateUTC != nil {
|
||||
airTime := episode.AirDateUTC.In(location)
|
||||
item.MembyAirsAt = airTime.Format(time.RFC3339)
|
||||
if airTime.After(now) {
|
||||
item.MembyAirLabel = "Airs today at " + airTime.Format("3:04 PM")
|
||||
} else {
|
||||
item.MembyAirLabel = "Aired today at " + airTime.Format("3:04 PM")
|
||||
}
|
||||
item.MembyAirDayLabel = scheduleAirDayLabel(airTime, now, location)
|
||||
item.MembyAirLabel = scheduleAirLabel(airTime, now, location)
|
||||
} else {
|
||||
item.MembyAirLabel = "Airs today"
|
||||
item.MembyAirDayLabel = "Upcoming"
|
||||
item.MembyAirLabel = "Coming up"
|
||||
}
|
||||
|
||||
addedAt := episodeFileAddedAt(episode)
|
||||
@@ -321,6 +346,50 @@ func toSonarrScheduleItem(episode sonarr.Episode, now time.Time, location *time.
|
||||
return item
|
||||
}
|
||||
|
||||
func scheduleAirDayLabel(airTime, now time.Time, location *time.Location) string {
|
||||
airTime = airTime.In(location)
|
||||
now = now.In(location)
|
||||
today := localDayStart(now, location)
|
||||
airDay := localDayStart(airTime, location)
|
||||
switch {
|
||||
case airDay.Equal(today):
|
||||
return "Today"
|
||||
case airDay.Equal(today.AddDate(0, 0, 1)):
|
||||
return "Tomorrow"
|
||||
default:
|
||||
return airTime.Format("Monday")
|
||||
}
|
||||
}
|
||||
|
||||
func scheduleAirLabel(airTime, now time.Time, location *time.Location) string {
|
||||
airTime = airTime.In(location)
|
||||
now = now.In(location)
|
||||
clock := airTime.Format("3:04 PM")
|
||||
today := localDayStart(now, location)
|
||||
airDay := localDayStart(airTime, location)
|
||||
switch {
|
||||
case airDay.Equal(today) && !airTime.After(now):
|
||||
return "Aired today at " + clock
|
||||
case airDay.Equal(today):
|
||||
remaining := airTime.Sub(now)
|
||||
if remaining < time.Hour {
|
||||
minutes := int((remaining + time.Minute - 1) / time.Minute)
|
||||
return fmt.Sprintf("In %d minutes (%s)", minutes, clock)
|
||||
}
|
||||
hours := int((remaining + time.Hour - 1) / time.Hour)
|
||||
return fmt.Sprintf("In %d hours (%s)", hours, clock)
|
||||
case airDay.Equal(today.AddDate(0, 0, 1)):
|
||||
return "Tomorrow: " + clock
|
||||
default:
|
||||
return airTime.Format("Monday") + ": " + clock
|
||||
}
|
||||
}
|
||||
|
||||
func localDayStart(value time.Time, location *time.Location) time.Time {
|
||||
value = value.In(location)
|
||||
return time.Date(value.Year(), value.Month(), value.Day(), 0, 0, 0, 0, location)
|
||||
}
|
||||
|
||||
func episodeFileAddedAt(episode sonarr.Episode) *time.Time {
|
||||
if episode.EpisodeFile == nil {
|
||||
return nil
|
||||
|
||||
Reference in New Issue
Block a user