[
'show' => [
'name' => 'Sendungs-Slug (z.B. "112-feuerwehr-im-einsatz")',
'type' => 'text',
'required' => true
],
'realm' => [
'name' => 'Plattform',
'type' => 'list',
'values' => [
'DMAX' => 'dmax',
'HGTV' => 'hgtv',
'TLC' => 'tlc'
],
'defaultValue' => 'dmax'
],
'limit' => [
'name' => 'Maximale Anzahl an Episoden',
'type' => 'number',
'required' => false,
'defaultValue' => 20
]
]
];
const PLATFORM_URLS = [
'dmax' => 'https://www.dmax.de/',
'hgtv' => 'https://de.hgtv.com/',
'tlc' => 'https://tlc.de/'
];
const PLATFORM_NAMES = [
'dmax' => 'DMAX',
'hgtv' => 'HGTV',
'tlc' => 'TLC'
];
private $showName = '';
public function getName() {
if (!empty($this->showName)) {
return $this->showName;
}
return parent::getName();
}
public function collectData() {
$show = $this->getInput('show');
$realm = $this->getInput('realm');
if (empty($show)) {
returnClientError('Ungültiger Sendungs-Slug.');
}
$apiUrl = self::API_URI . '?environment=' . $realm . '&v=2&filter[show.slug]=' . urlencode($show);
$json = json_decode(getContents($apiUrl), true);
if (!$json) {
returnServerError('Keine Daten von der API erhalten.');
}
// Extrahiere den Sendungsnamen aus dem JSON
$this->showName = $json['title'] ?? '';
// Die Episoden befinden sich in blocks[1]['items']
if (!isset($json['blocks'][1]['items']) || !is_array($json['blocks'][1]['items'])) {
returnServerError('Keine Episoden gefunden.');
}
$limit = $this->getInput('limit') ?? 20;
$episodes = array_slice($json['blocks'][1]['items'], 0, (int)$limit);
foreach ($episodes as $element) {
$item = [];
// Erstelle den Episodentitel
$episodeTitle = $element['title'] ?? '';
if (isset($element['seasonNumber']) && isset($element['episodeNumber'])) {
$item['title'] = sprintf(
'%s S%02dE%02d %s',
$this->showName,
$element['seasonNumber'],
$element['episodeNumber'],
$episodeTitle
);
} else {
$item['title'] = sprintf('%s %s', $this->showName, $episodeTitle);
}
// Content: Bild + Beschreibung
$content = '';
if (isset($element['poster']['src'])) {
$content .= '
';
}
$description = $element['description'] ?? '';
if (!empty($description)) {
$content .= '
' . htmlspecialchars($description) . '
'; } $item['content'] = $content; // Erstelle die Episode-URL $episodeSlug = $element['alternateId'] ?? ''; $item['uri'] = self::PLATFORM_URLS[$realm] . 'sendungen/' . $show . '/' . $episodeSlug; // Setze das Veröffentlichungsdatum if (isset($element['publishStart'])) { $item['timestamp'] = strtotime($element['publishStart']); } // Setze die eindeutige ID $item['uid'] = $element['id'] ?? ''; // Füge das Vorschaubild hinzu, falls vorhanden if (isset($element['poster']['src'])) { $item['enclosures'] = [$element['poster']['src']]; } // Setze den Sender als Autor $item['author'] = self::PLATFORM_NAMES[$realm]; $this->items[] = $item; } } public function getIcon() { $realm = $this->getInput('realm'); return self::PLATFORM_URLS[$realm] . 'favicon.ico'; } public function getURI() { $realm = $this->getInput('realm'); $show = $this->getInput('show'); if (empty($show)) { return self::PLATFORM_URLS[$realm]; } return self::PLATFORM_URLS[$realm] . 'sendungen/' . $show; } }