feat: add cover image display for ABS audiobooks

- Add coverUrl to ABS data from coverPath
- Update dashboard.html to display cover image with fallback placeholder
- Style cover images with rounded corners and shadow
- Add error handling for broken image URLs

Generated by Mistral Vibe.
Co-Authored-By: Mistral Vibe <vibe@mistral.ai>
This commit is contained in:
wralto-user-1
2026-11-02 22:53:15 +01:00
parent f33abdcc31
commit f4fe00d15b
2 changed files with 85 additions and 12 deletions

View File

@ -133,6 +133,37 @@
.status-bar .success { .status-bar .success {
color: #44ff44; color: #44ff44;
} }
/* Cover Image Styles */
.cover-container {
text-align: center;
}
.cover-image {
max-width: 100%;
max-height: 200px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
object-fit: contain;
background: rgba(0, 0, 0, 0.2);
}
.cover-placeholder {
width: 150px;
height: 150px;
margin: 0 auto;
background: rgba(255, 255, 255, 0.1);
border-radius: 8px;
display: flex;
align-items: center;
justify-content: center;
color: #666;
font-size: 1.5rem;
}
.audiobook-info {
margin-top: 0.75rem;
}
</style> </style>
</head> </head>
<body> <body>
@ -198,6 +229,13 @@
99: { icon: '⛈️', text: 'Gewitter mit starkem Hagel' } 99: { icon: '⛈️', text: 'Gewitter mit starkem Hagel' }
}; };
// Medien-Typ Icons
const mediaTypeIcons = {
'podcast': '🎙️',
'book': '📖',
'item': '📚'
};
// Uhrzeit und Datum aktualisieren // Uhrzeit und Datum aktualisieren
function updateClock() { function updateClock() {
const now = new Date(); const now = new Date();
@ -242,19 +280,46 @@
return; return;
} }
let displayText = absData.title; const title = absData.title || 'Unbekannt';
if (absData.author) displayText = `${absData.title} – ${absData.author}`; const author = absData.author || '';
const coverUrl = absData.coverUrl;
const mediaType = absData.mediaType || 'item';
const progressPercent = absData.progress || 0;
const currentTime = absData.currentTime || '0:00';
const duration = absData.duration || '0:00';
const mediaIcon = mediaTypeIcons[mediaType] || '📚';
const mediaType = absData.mediaType === 'podcast' ? '🎙️ Podcast' : (absData.mediaType === 'book' ? '📖 Hörbuch' : '📚 Medium'); let html = '';
const progressPercent = absData.progress;
const currentTime = absData.currentTime;
const duration = absData.duration;
document.getElementById('audiobook').innerHTML = ` if (coverUrl) {
<div class="card-value" style="font-size: 1.25rem;">${displayText}</div> html = `
<div class="card-subvalue">${mediaType}</div> <div class="cover-container">
<div class="card-subvalue">Fortschritt: ${progressPercent}% (${currentTime}/${duration})</div> <img src="${coverUrl}" alt="${title}" class="cover-image"
onerror="this.style.display='none'; document.getElementById('cover-fallback-${Date.now()}').style.display='block';">
<div id="cover-fallback-${Date.now()}" class="cover-placeholder" style="display: none;">
${mediaIcon}
</div>
</div>
<div class="audiobook-info">
<div class="card-value" style="font-size: 1.25rem; margin-top: 0.5rem;">${title}</div>
${author ? `<div class="card-subvalue">von ${author}</div>` : ''}
<div class="card-subvalue">${progressPercent}% (${currentTime}/${duration})</div>
</div>
`; `;
} else {
html = `
<div class="cover-container">
<div class="cover-placeholder">${mediaIcon}</div>
</div>
<div class="audiobook-info">
<div class="card-value" style="font-size: 1.25rem; margin-top: 0.5rem;">${title}</div>
${author ? `<div class="card-subvalue">von ${author}</div>` : ''}
<div class="card-subvalue">${progressPercent}% (${currentTime}/${duration})</div>
</div>
`;
}
document.getElementById('audiobook').innerHTML = html;
} }
// Alle Daten von der API holen // Alle Daten von der API holen

View File

@ -90,7 +90,7 @@ def fetch_weather():
def fetch_abs_data(): def fetch_abs_data():
"""Fetch ABS user data and latest audiobook""" """Fetch ABS user data and latest audiobook with cover"""
try: try:
headers = { headers = {
"Authorization": f"Bearer {ABS_TOKEN}", "Authorization": f"Bearer {ABS_TOKEN}",
@ -126,10 +126,18 @@ def fetch_abs_data():
author = metadata.get("author", "") author = metadata.get("author", "")
media_type = item_data.get("mediaType", "item") media_type = item_data.get("mediaType", "item")
# Get cover URL - construct full URL from coverPath
cover_path = item_data.get("coverPath", "")
cover_url = None
if cover_path:
# Remove leading slash if present and construct full URL
cover_url = f"{ABS_BASE_URL}{cover_path}" if cover_path.startswith("/") else f"{ABS_BASE_URL}/{cover_path}"
return { return {
"title": title, "title": title,
"author": author, "author": author,
"mediaType": media_type, "mediaType": media_type,
"coverUrl": cover_url,
"progress": round(latest.get("progress", 0) * 100), "progress": round(latest.get("progress", 0) * 100),
"currentTime": format_duration(latest.get("currentTime", 0)), "currentTime": format_duration(latest.get("currentTime", 0)),
"duration": format_duration(latest.get("duration", 0)), "duration": format_duration(latest.get("duration", 0)),