2020-10-12 09:35:06 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class CeskaTelevizeBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'Česká televize Bridge';
|
|
|
|
const URI = 'https://www.ceskatelevize.cz';
|
|
|
|
const CACHE_TIMEOUT = 3600;
|
|
|
|
const DESCRIPTION = 'Return newest videos';
|
|
|
|
const MAINTAINER = 'kolarcz';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
const PARAMETERS = [
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2020-10-12 09:35:06 +03:00
|
|
|
'url' => [
|
|
|
|
'name' => 'url to the show',
|
|
|
|
'required' => true,
|
2022-01-16 05:54:20 +03:00
|
|
|
'exampleValue' => 'https://www.ceskatelevize.cz/porady/1097181328-udalosti/'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2020-10-12 09:35:06 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
private function fixChars($text)
|
|
|
|
{
|
|
|
|
return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
private function getUploadTimeFromString($string)
|
|
|
|
{
|
|
|
|
if (strpos($string, 'dnes') !== false) {
|
|
|
|
return strtotime('today');
|
|
|
|
} elseif (strpos($string, 'včera') !== false) {
|
|
|
|
return strtotime('yesterday');
|
|
|
|
} elseif (!preg_match('/(\d+).\s(\d+).(\s(\d+))?/', $string, $match)) {
|
|
|
|
returnServerError('Could not get date from Česká televize string');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
$date = sprintf('%04d-%02d-%02d', $match[3] ?? date('Y'), $match[2], $match[1]);
|
|
|
|
return strtotime($date);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$url = $this->getInput('url');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-16 05:54:20 +03:00
|
|
|
$validUrl = '/^(https:\/\/www\.ceskatelevize\.cz\/porady\/\d+-[a-z0-9-]+\/)(bonus\/)?$/';
|
2020-10-12 09:35:06 +03:00
|
|
|
if (!preg_match($validUrl, $url, $match)) {
|
|
|
|
returnServerError('Invalid url');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
$category = $match[4] ?? 'nove';
|
|
|
|
$fixedUrl = "{$match[1]}dily/{$category}/";
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($fixedUrl);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
$this->feedUri = $fixedUrl;
|
|
|
|
$this->feedName = str_replace('Přehled dílů — ', '', $this->fixChars($html->find('title', 0)->plaintext));
|
|
|
|
if ($category !== 'nove') {
|
|
|
|
$this->feedName .= " ({$category})";
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2024-01-02 18:23:13 +03:00
|
|
|
foreach ($html->find('#episodeListSection a[data-testid=card]') as $element) {
|
2022-01-16 05:54:20 +03:00
|
|
|
$itemTitle = $element->find('h3', 0);
|
2024-01-02 18:23:13 +03:00
|
|
|
$itemContent = $element->find('p[class^=content-]', 0);
|
2024-08-28 20:43:40 +03:00
|
|
|
$itemDate = $element->find('div[class^=playTime-] span, [data-testid=episode-item-broadcast] span', 0);
|
2020-10-12 09:35:06 +03:00
|
|
|
$itemThumbnail = $element->find('img', 0);
|
|
|
|
$itemUri = self::URI . $element->getAttribute('href');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
$item = [
|
|
|
|
'title' => $this->fixChars($itemTitle->plaintext),
|
|
|
|
'uri' => $itemUri,
|
2022-01-16 05:54:20 +03:00
|
|
|
'content' => '<img src="' . $itemThumbnail->getAttribute('src') . '" /><br />'
|
2020-10-12 09:35:06 +03:00
|
|
|
. $this->fixChars($itemContent->plaintext),
|
|
|
|
'timestamp' => $this->getUploadTimeFromString($itemDate->plaintext)
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-10-12 09:35:06 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-15 10:53:19 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
return $this->feedUri ?? parent::getURI();
|
2020-10-12 09:35:06 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-12 09:35:06 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->feedName ?? parent::getName();
|
|
|
|
}
|
|
|
|
}
|