1
0
Files
Bridges/AnimationDigitalNetworkBridge.php

153 lines
5.1 KiB
PHP

<?php
class AnimationDigitalNetworkBridge extends BridgeAbstract {
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';
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/)'
)
)
);
public function collectData() {
$show_id = $this->getInput('show_id');
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
$headers = [
'Accept-Language: de',
'x-target-distribution: de'
];
$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
$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'])) {
$categories[] = 'Staffel ' . $video['seasonNumber'];
}
if (!empty($categories)) {
$item['categories'] = $categories;
}
// Enclosures (Bild)
if (!empty($video['image'])) {
$item['enclosures'] = array($video['image']);
}
// Autor
if (isset($episodeDetails['show']['title'])) {
$item['author'] = $episodeDetails['show']['title'];
}
// 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 Items haben, können wir den Show-Titel verwenden
if (!empty($this->items) && !empty($this->items[0]['author'])) {
return $this->items[0]['author'] . ' - Animation Digital Network';
}
return 'Show ' . $this->getInput('show_id') . ' - Animation Digital Network';
}
return parent::getName();
}
}