rss-bridge/bridges/MallTvBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

77 lines
2.2 KiB
PHP
Raw Normal View History

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';
2020-10-31 20:05:13 +03:00
const PARAMETERS = [
[
2020-10-31 20:05:13 +03:00
'url' => [
'name' => 'url to the show',
'required' => true,
'exampleValue' => 'https://www.mall.tv/zivot-je-hra'
]
]
2020-10-31 20:05:13 +03:00
];
2020-10-31 20:05:13 +03:00
private function fixChars($text)
{
return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
}
2020-10-31 20:05:13 +03:00
private function getUploadTimeFromUrl($url)
{
$html = getSimpleHTMLDOM($url);
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');
}
2020-10-31 20:05:13 +03:00
return strtotime($match[1]);
}
2020-10-31 20:05:13 +03:00
public function collectData()
{
$url = $this->getInput('url');
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');
}
$html = getSimpleHTMLDOM($url);
2020-10-31 20:05:13 +03:00
$this->feedUri = $url;
$this->feedName = $this->fixChars($html->find('title', 0)->plaintext);
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');
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)
];
2020-10-31 20:05:13 +03:00
$this->items[] = $item;
}
2020-10-31 20:05:13 +03:00
}
2020-10-31 20:05:13 +03:00
public function getURI()
{
return $this->feedUri ?? parent::getURI();
}
2020-10-31 20:05:13 +03:00
public function getName()
{
return $this->feedName ?? parent::getName();
}
}