Implement code changes to enhance functionality and improve performance
This commit is contained in:
@ -125,13 +125,46 @@ class LocalPodcastGenerator:
|
||||
print(f" 🖼️ Cover bereits vorhanden: {cover_filename}")
|
||||
return cover_url
|
||||
|
||||
# Cover existiert noch nicht - extrahiere es
|
||||
with open(cover_path, 'wb') as f:
|
||||
f.write(metadata['cover_data'])
|
||||
# Cover existiert noch nicht - extrahiere und validiere es
|
||||
try:
|
||||
from PIL import Image
|
||||
import io
|
||||
|
||||
# Lade das Bild aus den Cover-Daten
|
||||
image = Image.open(io.BytesIO(metadata['cover_data']))
|
||||
width, height = image.size
|
||||
|
||||
# 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))
|
||||
|
||||
# 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)")
|
||||
|
||||
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)")
|
||||
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)")
|
||||
|
||||
# Rückgabe der URL zum Cover (URL-encoded für korrekte Links)
|
||||
cover_url = f"{self.base_url}/_audio/{urllib.parse.quote(cover_filename)}"
|
||||
print(f" 🖼️ Cover neu extrahiert: {cover_filename}")
|
||||
return cover_url
|
||||
|
||||
except Exception as e:
|
||||
@ -361,6 +394,11 @@ Ich spezialisiere mich auf House Music, die mehr als nur Beats bietet – sie er
|
||||
# Für alle anderen Pfade normale Verarbeitung
|
||||
super().do_GET()
|
||||
|
||||
def do_HEAD(self):
|
||||
"""HTTP HEAD Requests für Apple Podcasts Kompatibilität."""
|
||||
# HEAD-Requests sind für Apple Podcasts erforderlich
|
||||
super().do_HEAD()
|
||||
|
||||
def list_directory(self, path):
|
||||
"""Deaktiviert Directory-Listing - zeigt 403 Forbidden."""
|
||||
self.send_error(403, "Directory listing disabled")
|
||||
@ -369,8 +407,11 @@ Ich spezialisiere mich auf House Music, die mehr als nur Beats bietet – sie er
|
||||
def end_headers(self):
|
||||
# CORS-Header hinzufügen für bessere Kompatibilität
|
||||
self.send_header('Access-Control-Allow-Origin', '*')
|
||||
self.send_header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
|
||||
self.send_header('Access-Control-Allow-Methods', 'GET, HEAD, POST, OPTIONS')
|
||||
self.send_header('Access-Control-Allow-Headers', 'Content-Type')
|
||||
# Cache-Control für bessere Performance
|
||||
if self.path.endswith(('.mp3', '.jpg', '.png')):
|
||||
self.send_header('Cache-Control', 'public, max-age=3600')
|
||||
super().end_headers()
|
||||
|
||||
handler = CustomHandler
|
||||
|
Reference in New Issue
Block a user