195 lines
7.2 KiB
PHP
195 lines
7.2 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';
|
|
|
|
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 getIcon(){
|
|
return 'https://animationdigitalnetwork.com/images/favicon/apple-touch-icon.webp';
|
|
}
|
|
|
|
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 aufbauen
|
|
$content = '';
|
|
|
|
// Bild
|
|
if (!empty($video['image'])) {
|
|
$content .= '<img src="' . $video['image'] . '" alt="' . htmlspecialchars($item['title']) . '" style="max-width: 100%;"><br><br>';
|
|
}
|
|
|
|
// Summary/Beschreibung
|
|
if (isset($episodeDetails['summary']) && !empty($episodeDetails['summary'])) {
|
|
$content .= '<p><strong>Beschreibung:</strong><br>' . nl2br(htmlspecialchars($episodeDetails['summary'])) . '</p>';
|
|
}
|
|
|
|
// Episode-Infos
|
|
$content .= '<p>';
|
|
if (!empty($video['number'])) {
|
|
$content .= '<strong>Episode:</strong> ' . htmlspecialchars($video['number']) . '<br>';
|
|
}
|
|
if (!empty($video['name'])) {
|
|
$content .= '<strong>Titel:</strong> ' . htmlspecialchars($video['name']) . '<br>';
|
|
}
|
|
if (!empty($video['seasonTitle'])) {
|
|
$content .= '<strong>Staffel/Abschnitt:</strong> ' . htmlspecialchars($video['seasonTitle']) . '<br>';
|
|
}
|
|
if (isset($video['duration'])) {
|
|
$minutes = floor($video['duration'] / 60);
|
|
$seconds = $video['duration'] % 60;
|
|
$content .= '<strong>Dauer:</strong> ' . $minutes . ':' . sprintf('%02d', $seconds) . ' Min.<br>';
|
|
}
|
|
if (isset($episodeDetails['rating'])) {
|
|
$content .= '<strong>Bewertung:</strong> ' . $episodeDetails['rating'] . '/5';
|
|
if (isset($episodeDetails['ratingsCount'])) {
|
|
$content .= ' (' . $episodeDetails['ratingsCount'] . ' Bewertungen)';
|
|
}
|
|
$content .= '<br>';
|
|
}
|
|
$content .= '</p>';
|
|
|
|
// Verfügbarkeit
|
|
if (isset($video['free']) || isset($video['freeWithAds'])) {
|
|
$content .= '<p><strong>Verfügbarkeit:</strong> ';
|
|
if (!empty($video['free'])) {
|
|
$content .= 'Kostenlos';
|
|
} elseif (!empty($video['freeWithAds'])) {
|
|
$content .= 'Kostenlos mit Werbung';
|
|
} else {
|
|
$content .= 'Premium';
|
|
}
|
|
$content .= '</p>';
|
|
}
|
|
|
|
// Show-Info (falls verfügbar)
|
|
if (isset($episodeDetails['show']['summary']) && !empty($episodeDetails['show']['summary'])) {
|
|
$content .= '<hr><p><strong>Über die Serie:</strong><br>' . nl2br(htmlspecialchars($episodeDetails['show']['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();
|
|
}
|
|
}
|