1
0
Files
Bridges/AnimationDigitalNetworkBridge.php
2025-11-26 21:16:33 +01:00

171 lines
5.9 KiB
PHP

<?php
class AnimationDigitalNetworkBridge extends BridgeAbstract {
private $showTitle = null;
const MAINTAINER = 'Akamaru';
const NAME = 'Animation Digital Network';
const URI = 'https://animationdigitalnetwork.com/';
const CACHE_TIMEOUT = 3600; // 1h
const DESCRIPTION = 'Holt die neuesten Episoden einer Serie von Animation Digital Network<br>Récupère les derniers épisodes d\'une série d\'Animation Digital Network';
public function getIcon()
{
return 'https://www.google.com/s2/favicons?domain=animationdigitalnetwork.com&sz=32';
}
const PARAMETERS = array(
array(
'show_id' => array(
'name' => 'Show-ID',
'type' => 'number',
'required' => true,
'exampleValue' => '1333',
'title' => 'Die ID der Serie (z.B. 1333 aus der URL /video/1333-serienname/)'
),
'region' => array(
'name' => 'Region/Sprache',
'type' => 'list',
'required' => false,
'defaultValue' => 'de',
'values' => array(
'Deutsch' => 'de',
'Français' => 'fr'
)
)
)
);
public function collectData() {
$show_id = $this->getInput('show_id');
$region = $this->getInput('region') ?? 'de';
if (empty($show_id)) {
returnClientError('Show-ID ist erforderlich');
}
// API-Aufruf zur Seasons-API
$seasonsUrl = 'https://gw.api.animationdigitalnetwork.com/video/show/' . $show_id . '/seasons?order=asc';
// Headers für API-Requests (dynamisch basierend auf Region)
$headers = [
'Accept-Language: ' . $region,
'x-target-distribution: ' . $region
];
$seasonsJson = getContents($seasonsUrl, $headers);
$seasonsData = json_decode($seasonsJson, true);
if (!isset($seasonsData['seasons']) || !is_array($seasonsData['seasons'])) {
returnServerError('Konnte Seasons-Daten nicht abrufen');
}
// Alle Videos aus allen Seasons sammeln
$allVideos = array();
foreach ($seasonsData['seasons'] as $season) {
if (isset($season['videos']) && is_array($season['videos'])) {
foreach ($season['videos'] as $video) {
// Staffel-Info hinzufügen
$video['seasonTitle'] = $season['title'];
$video['seasonNumber'] = $season['season'];
$allVideos[] = $video;
}
}
}
// Array umkehren, damit neueste Folge oben ist
$allVideos = array_reverse($allVideos);
// Auf maximal 20 Episoden limitieren (Performance)
$allVideos = array_slice($allVideos, 0, 20);
// Für jede Episode Details abrufen und Feed-Item erstellen
foreach ($allVideos as $video) {
$item = array();
$episodeId = $video['id'];
// Episode-Details abrufen
$episodeUrl = 'https://gw.api.animationdigitalnetwork.com/video/' . $episodeId . '/public';
$episodeJson = getContents($episodeUrl, $headers);
$episodeData = json_decode($episodeJson, true);
if (!isset($episodeData['video'])) {
// Wenn Details nicht verfügbar sind, mit Basis-Infos fortfahren
$episodeDetails = $video;
} else {
$episodeDetails = $episodeData['video'];
}
// Titel
$item['title'] = $video['title'];
// URI (die API liefert bereits den korrekten Pfad mit/ohne /de)
$item['uri'] = 'https://animationdigitalnetwork.com' . $video['urlPath'];
// UID
$item['uid'] = 'adn-' . $episodeId;
// Timestamp
if (isset($episodeDetails['releaseDate'])) {
$item['timestamp'] = strtotime($episodeDetails['releaseDate']);
}
// Kategorien
$categories = array();
if (!empty($video['seasonTitle'])) {
$categories[] = $video['seasonTitle'];
}
if (!empty($video['seasonNumber'])) {
// Lokalisierung: "Staffel" für de, "Saison" für fr
$seasonLabel = ($region === 'fr') ? 'Saison' : 'Staffel';
$categories[] = $seasonLabel . ' ' . $video['seasonNumber'];
}
if (!empty($categories)) {
$item['categories'] = $categories;
}
// Enclosures (Bild)
if (!empty($video['image'])) {
$item['enclosures'] = array($video['image']);
}
// Show-Titel für getName() speichern
if (isset($episodeDetails['show']['title']) && $this->showTitle === null) {
$this->showTitle = $episodeDetails['show']['title'];
}
// Autor
$item['author'] = 'ADN';
// Content: Bild + Beschreibung
$content = '';
// Bild
if (!empty($video['image'])) {
$content .= '<img src="' . $video['image'] . '" alt="' . htmlspecialchars($item['title']) . '"><br>';
}
// Beschreibung
if (isset($episodeDetails['summary']) && !empty($episodeDetails['summary'])) {
$content .= '<p>' . nl2br(htmlspecialchars($episodeDetails['summary'])) . '</p>';
}
$item['content'] = $content;
$this->items[] = $item;
}
}
public function getName() {
if ($this->getInput('show_id')) {
// Wenn wir den Show-Titel haben, verwenden wir ihn
if ($this->showTitle !== null) {
return $this->showTitle . ' - ADN';
}
return 'Show ' . $this->getInput('show_id') . ' - ADN';
}
return parent::getName();
}
}