135 lines
4.0 KiB
PHP
135 lines
4.0 KiB
PHP
<?php
|
|
|
|
class DMAXBridge extends BridgeAbstract
|
|
{
|
|
const NAME = 'DMAX, HGTV, TLC Bridge';
|
|
const URI = '';
|
|
const API_URI = 'https://de-api.loma-cms.com/feloma/videos/';
|
|
const DESCRIPTION = 'Gibt die neuesten Episoden einer DMAX, HGTV oder TLC Sendung zurück.';
|
|
const MAINTAINER = 'Brawl, Akamaru';
|
|
|
|
const PARAMETERS = [
|
|
'Sendung' => [
|
|
'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'
|
|
]
|
|
]
|
|
];
|
|
|
|
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.');
|
|
}
|
|
|
|
foreach ($json['blocks'][1]['items'] 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);
|
|
}
|
|
|
|
// Setze die Beschreibung
|
|
$item['content'] = $element['description'] ?? '';
|
|
|
|
// 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;
|
|
}
|
|
}
|