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:
@ -133,6 +133,37 @@
|
||||
.status-bar .success {
|
||||
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>
|
||||
</head>
|
||||
<body>
|
||||
@ -198,6 +229,13 @@
|
||||
99: { icon: '⛈️', text: 'Gewitter mit starkem Hagel' }
|
||||
};
|
||||
|
||||
// Medien-Typ Icons
|
||||
const mediaTypeIcons = {
|
||||
'podcast': '🎙️',
|
||||
'book': '📖',
|
||||
'item': '📚'
|
||||
};
|
||||
|
||||
// Uhrzeit und Datum aktualisieren
|
||||
function updateClock() {
|
||||
const now = new Date();
|
||||
@ -242,19 +280,46 @@
|
||||
return;
|
||||
}
|
||||
|
||||
let displayText = absData.title;
|
||||
if (absData.author) displayText = `${absData.title} – ${absData.author}`;
|
||||
const title = absData.title || 'Unbekannt';
|
||||
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');
|
||||
const progressPercent = absData.progress;
|
||||
const currentTime = absData.currentTime;
|
||||
const duration = absData.duration;
|
||||
let html = '';
|
||||
|
||||
document.getElementById('audiobook').innerHTML = `
|
||||
<div class="card-value" style="font-size: 1.25rem;">${displayText}</div>
|
||||
<div class="card-subvalue">${mediaType}</div>
|
||||
<div class="card-subvalue">Fortschritt: ${progressPercent}% (${currentTime}/${duration})</div>
|
||||
`;
|
||||
if (coverUrl) {
|
||||
html = `
|
||||
<div class="cover-container">
|
||||
<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
|
||||
|
||||
@ -90,7 +90,7 @@ def fetch_weather():
|
||||
|
||||
|
||||
def fetch_abs_data():
|
||||
"""Fetch ABS user data and latest audiobook"""
|
||||
"""Fetch ABS user data and latest audiobook with cover"""
|
||||
try:
|
||||
headers = {
|
||||
"Authorization": f"Bearer {ABS_TOKEN}",
|
||||
@ -125,11 +125,19 @@ def fetch_abs_data():
|
||||
title = metadata.get("title", "Unbekannt")
|
||||
author = metadata.get("author", "")
|
||||
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 {
|
||||
"title": title,
|
||||
"author": author,
|
||||
"mediaType": media_type,
|
||||
"coverUrl": cover_url,
|
||||
"progress": round(latest.get("progress", 0) * 100),
|
||||
"currentTime": format_duration(latest.get("currentTime", 0)),
|
||||
"duration": format_duration(latest.get("duration", 0)),
|
||||
|
||||
Reference in New Issue
Block a user