Add poster image support to Matrix download listings
Some checks failed
Test action / kaas (push) Failing after 2s
Some checks failed
Test action / kaas (push) Failing after 2s
- Fetch and display poster images for tracked items in Matrix - Show monitored/unmonitored icons in listings - Limit displayed items to 12, with count and overflow message - Add tests for image fetching and formatting - Enable Grafana datasources - Fix Sonarr/Radarr URL config bug
This commit is contained in:
parent
e07257e137
commit
100a218aed
9 changed files with 432 additions and 59 deletions
|
|
@ -73,16 +73,22 @@ func handleDownloadList(ctx *Context, client arrclient.Client, contentType arr.C
|
|||
return
|
||||
}
|
||||
|
||||
var builder strings.Builder
|
||||
builder.WriteString(fmt.Sprintf("Tracked %s:\n", contentType.Label()))
|
||||
count := len(items)
|
||||
if count > 12 {
|
||||
count = 12
|
||||
}
|
||||
ctx.Reply("Tracked %s (showing %d of %d):", contentType.Label(), count, len(items))
|
||||
for i, item := range items {
|
||||
if i == 10 {
|
||||
builder.WriteString("…\n")
|
||||
if i == 12 {
|
||||
break
|
||||
}
|
||||
builder.WriteString(fmt.Sprintf("- `%d` %s — monitored=%t\n", item.ID, formatManagedItem(item), item.Monitored))
|
||||
if err := replyWithManagedItem(ctx, client, item); err != nil {
|
||||
ctx.Log.Err(err).Int64("item_id", item.ID).Str("content_type", contentType.Label()).Msg("Failed to send Matrix-native image for download listing")
|
||||
}
|
||||
}
|
||||
if len(items) > 12 {
|
||||
ctx.Reply("…and %d more.", len(items)-12)
|
||||
}
|
||||
ctx.Reply(builder.String())
|
||||
}
|
||||
|
||||
func handleDownloadSearch(ctx *Context, client arrclient.Client, contentType arr.ContentType) {
|
||||
|
|
@ -200,10 +206,7 @@ func replyWithSearchResults(ctx *Context, contentType arr.ContentType, query str
|
|||
}
|
||||
|
||||
func formatManagedItem(item arrclient.ManagedItem) string {
|
||||
if item.Year != 0 {
|
||||
return fmt.Sprintf("%s (%d)", item.Title, item.Year)
|
||||
}
|
||||
return item.Title
|
||||
return arrclient.FormatManagedItem(item)
|
||||
}
|
||||
|
||||
func parseEnabled(value string) (bool, error) {
|
||||
|
|
@ -220,3 +223,38 @@ func parseEnabled(value string) (bool, error) {
|
|||
func userIDString(userID id.UserID) string {
|
||||
return userID.String()
|
||||
}
|
||||
|
||||
func replyWithManagedItem(ctx *Context, client arrclient.Client, item arrclient.ManagedItem) error {
|
||||
details := formatDownloadListCaption(item)
|
||||
if item.ImageURL != "" {
|
||||
asset, err := client.FetchImage(ctx.Ctx, item)
|
||||
if err != nil {
|
||||
ctx.Log.Err(err).Int64("item_id", item.ID).Msg("Failed to fetch poster for Matrix listing")
|
||||
} else if asset != nil {
|
||||
if err := ctx.SendImage(asset, details); err != nil {
|
||||
ctx.Log.Err(err).Int64("item_id", item.ID).Msg("Failed to upload poster for Matrix listing")
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
ctx.Log.Debug().Int64("item_id", item.ID).Msg("Poster was empty for Matrix listing")
|
||||
}
|
||||
}
|
||||
ctx.Reply(details)
|
||||
return nil
|
||||
}
|
||||
|
||||
func formatDownloadListCaption(item arrclient.ManagedItem) string {
|
||||
return fmt.Sprintf("%s %s", monitoredIcon(item.Monitored), arrclient.FormatManagedItem(item))
|
||||
}
|
||||
|
||||
func formatDownloadListFallbackCard(item arrclient.ManagedItem) string {
|
||||
return formatDownloadListCaption(item)
|
||||
}
|
||||
|
||||
func monitoredIcon(monitored bool) string {
|
||||
if monitored {
|
||||
return "👁"
|
||||
}
|
||||
return "🚫"
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue