2020-10-12 09:35:06 +03:00
|
|
|
<?php
|
|
|
|
|
2022-07-01 16:10:30 +03:00
|
|
|
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';
|
|
|
|
|
|
|
|
const PARAMETERS = [
|
|
|
|
[
|
|
|
|
'url' => [
|
|
|
|
'name' => 'url to the show',
|
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'https://www.ceskatelevize.cz/porady/1097181328-udalosti/'
|
|
|
|
]
|
|
|
|
]
|
|
|
|
];
|
|
|
|
|
|
|
|
private function fixChars($text)
|
|
|
|
{
|
|
|
|
return html_entity_decode($text, ENT_QUOTES, 'UTF-8');
|
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
|
|
|
}
|
|
|
|
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
$date = sprintf('%04d-%02d-%02d', $match[3] ?? date('Y'), $match[2], $match[1]);
|
2022-07-01 16:10:30 +03:00
|
|
|
return strtotime($date);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData()
|
|
|
|
{
|
|
|
|
$url = $this->getInput('url');
|
|
|
|
|
|
|
|
$validUrl = '/^(https:\/\/www\.ceskatelevize\.cz\/porady\/\d+-[a-z0-9-]+\/)(bonus\/)?$/';
|
|
|
|
if (!preg_match($validUrl, $url, $match)) {
|
|
|
|
returnServerError('Invalid url');
|
|
|
|
}
|
|
|
|
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
$category = $match[4] ?? 'nove';
|
2022-07-01 16:10:30 +03:00
|
|
|
$fixedUrl = "{$match[1]}dily/{$category}/";
|
|
|
|
|
|
|
|
$html = getSimpleHTMLDOM($fixedUrl);
|
|
|
|
|
|
|
|
$this->feedUri = $fixedUrl;
|
|
|
|
$this->feedName = str_replace('Přehled dílů — ', '', $this->fixChars($html->find('title', 0)->plaintext));
|
|
|
|
if ($category !== 'nove') {
|
|
|
|
$this->feedName .= " ({$category})";
|
|
|
|
}
|
|
|
|
|
2024-01-02 18:23:13 +03:00
|
|
|
foreach ($html->find('#episodeListSection a[data-testid=card]') as $element) {
|
2022-07-01 16:10:30 +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);
|
2022-07-01 16:10:30 +03:00
|
|
|
$itemThumbnail = $element->find('img', 0);
|
|
|
|
$itemUri = self::URI . $element->getAttribute('href');
|
|
|
|
|
|
|
|
$item = [
|
|
|
|
'title' => $this->fixChars($itemTitle->plaintext),
|
|
|
|
'uri' => $itemUri,
|
|
|
|
'content' => '<img src="' . $itemThumbnail->getAttribute('src') . '" /><br />'
|
|
|
|
. $this->fixChars($itemContent->plaintext),
|
|
|
|
'timestamp' => $this->getUploadTimeFromString($itemDate->plaintext)
|
|
|
|
];
|
|
|
|
|
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getURI()
|
|
|
|
{
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
return $this->feedUri ?? parent::getURI();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getName()
|
|
|
|
{
|
Fix coding style missed by phpbcf (#2901)
$ composer require --dev friendsofphp/php-cs-fixer
$ echo >.php-cs-fixer.dist.php "<?php
$finder = PhpCsFixer\Finder::create()
->in(__DIR__);
$rules = [
'@PSR12' => true,
// '@PSR12:risky' => true,
'@PHP74Migration' => true,
// '@PHP74Migration:risky' => true,
// buggy, duplicates existing comment sometimes
'no_break_comment' => false,
'array_syntax' => true,
'lowercase_static_reference' => true,
'visibility_required' => false,
// Too much noise
'binary_operator_spaces' => false,
'heredoc_indentation' => false,
'trailing_comma_in_multiline' => false,
];
$config = new PhpCsFixer\Config();
return $config
->setRules($rules)
// ->setRiskyAllowed(true)
->setFinder($finder);
"
$ vendor/bin/php-cs-fixer --version
PHP CS Fixer 3.8.0 BerSzcz against war! by Fabien Potencier and Dariusz Ruminski.
PHP runtime: 8.1.7
$ vendor/bin/php-cs-fixer fix
$ rm .php-cs-fixer.cache
$ vendor/bin/php-cs-fixer fix
2022-07-08 14:00:52 +03:00
|
|
|
return $this->feedName ?? parent::getName();
|
2022-07-01 16:10:30 +03:00
|
|
|
}
|
2020-10-12 09:35:06 +03:00
|
|
|
}
|