2020-10-31 20:05:13 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
class MallTvBridge extends BridgeAbstract
|
|
|
|
{
|
|
|
|
const NAME = 'MALL.TV Bridge';
|
|
|
|
const URI = 'https://www.mall.tv';
|
|
|
|
const CACHE_TIMEOUT = 3600;
|
|
|
|
const DESCRIPTION = 'Return newest videos';
|
|
|
|
const MAINTAINER = 'kolarcz';
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
const PARAMETERS = [
|
2022-07-01 16:10:30 +03:00
|
|
|
[
|
2020-10-31 20:05:13 +03:00
|
|
|
'url' => [
|
|
|
|
'name' => 'url to the show',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'https://www.mall.tv/zivot-je-hra'
|
2022-07-01 16:10:30 +03:00
|
|
|
]
|
|
|
|
]
|
2020-10-31 20:05:13 +03:00
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +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-31 20:05:13 +03:00
|
|
|
private function getUploadTimeFromUrl($url)
|
|
|
|
{
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
$scriptLdJson = $html->find('script[type="application/ld+json"]', 0)->innertext;
|
|
|
|
if (!preg_match('/[\'"]uploadDate[\'"]\s*:\s*[\'"](\d{4}-\d{2}-\d{2})[\'"]/', $scriptLdJson, $match)) {
|
|
|
|
returnServerError('Could not get date from MALL.TV detail page');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
return strtotime($match[1]);
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$url = $this->getInput('url');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
if (!preg_match('/^https:\/\/www\.mall\.tv\/[a-z0-9-]+(\/[a-z0-9-]+)?\/?$/', $url)) {
|
|
|
|
returnServerError('Invalid url');
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
$this->feedUri = $url;
|
|
|
|
$this->feedName = $this->fixChars($html->find('title', 0)->plaintext);
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
foreach ($html->find('section.isVideo .video-card') as $element) {
|
|
|
|
$itemTitle = $element->find('.video-card__details-link', 0);
|
|
|
|
$itemThumbnail = $element->find('.video-card__thumbnail', 0);
|
|
|
|
$itemUri = self::URI . $itemTitle->getAttribute('href');
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
$item = [
|
|
|
|
'title' => $this->fixChars($itemTitle->plaintext),
|
|
|
|
'uri' => $itemUri,
|
|
|
|
'content' => '<img src="' . $itemThumbnail->getAttribute('data-src') . '" />',
|
|
|
|
'timestamp' => $this->getUploadTimeFromUrl($itemUri)
|
|
|
|
];
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
$this->items[] = $item;
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-10-31 20:05:13 +03:00
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
public function getURI()
|
|
|
|
{
|
|
|
|
return $this->feedUri ?? parent::getURI();
|
|
|
|
}
|
2022-07-01 16:10:30 +03:00
|
|
|
|
2020-10-31 20:05:13 +03:00
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return $this->feedName ?? parent::getName();
|
|
|
|
}
|
|
|
|
}
|