Verbessere die Cover-Optimierung durch Anpassung der Größenprüfung und -anpassung für bessere Kompatibilität mit Apple Podcasts.

This commit is contained in:
2025-07-05 20:47:35 +02:00
parent c5abfa342b
commit 6172a898c3
2 changed files with 154 additions and 22 deletions

View File

@ -132,36 +132,59 @@ class LocalPodcastGenerator:
# Lade das Bild aus den Cover-Daten
image = Image.open(io.BytesIO(metadata['cover_data']))
width, height = image.size
original_width, original_height = image.size
print(f" 📐 Original Cover-Größe: {original_width}x{original_height}px")
# Apple Podcasts benötigt quadratische Cover zwischen 1400-3000px
if width < 1400 or height < 1400:
print(f" ⚠️ Cover zu klein ({width}x{height}px), skaliere auf 1400x1400px")
image = image.resize((1400, 1400), Image.Resampling.LANCZOS)
elif width > 3000 or height > 3000:
print(f" ⚠️ Cover zu groß ({width}x{height}px), skaliere auf 3000x3000px")
image = image.resize((3000, 3000), Image.Resampling.LANCZOS)
elif width != height:
print(f" ⚠️ Cover nicht quadratisch ({width}x{height}px), schneide zu")
size = min(width, height)
image = image.crop(((width-size)//2, (height-size)//2, (width+size)//2, (height+size)//2))
# Wähle Zielgröße basierend auf Originalgröße
if original_width < 1400 or original_height < 1400:
target_size = 1400
print(f" ⚠️ Cover zu klein, skaliere auf {target_size}x{target_size}px")
elif original_width > 3000 or original_height > 3000:
target_size = 3000
print(f" ⚠️ Cover zu groß, skaliere auf {target_size}x{target_size}px")
else:
# Cover ist in akzeptabler Größe, mache es quadratisch
target_size = min(original_width, original_height)
if target_size < 1400:
target_size = 1400
elif target_size > 3000:
target_size = 3000
print(f" ✓ Cover-Größe OK, mache quadratisch: {target_size}x{target_size}px")
# Mache das Bild quadratisch (schneide zu oder fülle auf)
if original_width != original_height:
size = min(original_width, original_height)
left = (original_width - size) // 2
top = (original_height - size) // 2
right = left + size
bottom = top + size
image = image.crop((left, top, right, bottom))
print(f" ✂️ Bild zugeschnitten auf quadratisch: {size}x{size}px")
# Skaliere auf Zielgröße
image = image.resize((target_size, target_size), Image.Resampling.LANCZOS)
# Konvertiere zu RGB falls nötig (für JPEG)
if image.mode in ('RGBA', 'LA', 'P'):
background = Image.new('RGB', image.size, (255, 255, 255))
if image.mode == 'P':
image = image.convert('RGBA')
background.paste(image, mask=image.split()[-1] if image.mode == 'RGBA' else None)
image = background
# Speichere das optimierte Cover
image.save(cover_path, 'JPEG', quality=95, optimize=True)
print(f" 🖼️ Cover optimiert und gespeichert: {cover_filename} ({image.size[0]}x{image.size[1]}px)")
final_width, final_height = image.size
print(f" 🖼️ Cover optimiert und gespeichert: {cover_filename} ({final_width}x{final_height}px)")
except ImportError:
print(" ⚠️ PIL/Pillow nicht installiert - Cover wird ohne Optimierung gespeichert")
# Fallback: Speichere Cover ohne Optimierung
with open(cover_path, 'wb') as f:
f.write(metadata['cover_data'])
print(f" 🖼️ Cover gespeichert: {cover_filename} (unoptimiert)")
print(" PIL/Pillow nicht installiert - kann Cover nicht optimieren!")
print(" 💡 Installiere mit: uv add pillow")
return None
except Exception as img_error:
print(f" ⚠️ Fehler bei Cover-Optimierung: {img_error}")
# Fallback: Speichere Cover ohne Optimierung
with open(cover_path, 'wb') as f:
f.write(metadata['cover_data'])
print(f" 🖼️ Cover gespeichert: {cover_filename} (unoptimiert)")
print(f" Fehler bei Cover-Optimierung: {img_error}")
return None
# Rückgabe der URL zum Cover (URL-encoded für korrekte Links)
cover_url = f"{self.base_url}/_audio/{urllib.parse.quote(cover_filename)}"