fix: various small fixes (#3519)

This commit is contained in:
Dag 2023-07-09 10:08:30 +02:00 committed by GitHub
parent f0a504bb9a
commit dfe78fb379
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 14 deletions

View File

@ -23,7 +23,10 @@ class CuriousCatBridge extends BridgeAbstract
$apiJson = getContents($url);
$apiData = json_decode($apiJson, true);
$apiData = Json::decode($apiJson);
if (isset($apiData['error'])) {
throw new \Exception($apiData['error_code']);
}
foreach ($apiData['posts'] as $post) {
$item = [];

View File

@ -47,7 +47,7 @@ class EtsyBridge extends BridgeAbstract
$item['title'] = $result->find('a', 0)->title;
$item['uri'] = $result->find('a', 0)->href;
$item['author'] = $result->find('p.wt-text-gray > span', 2)->plaintext;
$item['author'] = $result->find('p.wt-text-gray > span', 2)->plaintext ?? '';
$item['content'] = '<p>'
. ($result->find('span.currency-symbol', 0)->plaintext ?? '')

View File

@ -66,8 +66,7 @@ class SoundCloudBridge extends BridgeAbstract
$item['author'] = $apiItem->user->username;
$item['title'] = $apiItem->user->username . ' - ' . $apiItem->title;
$item['timestamp'] = strtotime($apiItem->created_at);
$description = nl2br($apiItem->description);
$description = nl2br($apiItem->description ?? '');
$item['content'] = <<<HTML
<p>{$description}</p>

View File

@ -233,7 +233,11 @@ class YoutubeBridge extends BridgeAbstract
private function getJSONData($html)
{
$scriptRegex = '/var ytInitialData = (.*?);<\/script>/';
preg_match($scriptRegex, $html, $matches) or returnServerError('Could not find ytInitialData');
$result = preg_match($scriptRegex, $html, $matches);
if (! $result) {
Logger::debug('Could not find ytInitialData');
return null;
}
return json_decode($matches[1]);
}
@ -292,15 +296,17 @@ class YoutubeBridge extends BridgeAbstract
}
}
if (preg_match('/([\d]{1,2})\:([\d]{1,2})\:([\d]{2})/', $durationText)) {
$durationText = preg_replace('/([\d]{1,2})\:([\d]{1,2})\:([\d]{2})/', '$1:$2:$3', $durationText);
} else {
$durationText = preg_replace('/([\d]{1,2})\:([\d]{2})/', '00:$1:$2', $durationText);
}
sscanf($durationText, '%d:%d:%d', $hours, $minutes, $seconds);
$duration = $hours * 3600 + $minutes * 60 + $seconds;
if ($duration < $duration_min || $duration > $duration_max) {
continue;
if (is_string($durationText)) {
if (preg_match('/([\d]{1,2})\:([\d]{1,2})\:([\d]{2})/', $durationText)) {
$durationText = preg_replace('/([\d]{1,2})\:([\d]{1,2})\:([\d]{2})/', '$1:$2:$3', $durationText);
} else {
$durationText = preg_replace('/([\d]{1,2})\:([\d]{2})/', '00:$1:$2', $durationText);
}
sscanf($durationText, '%d:%d:%d', $hours, $minutes, $seconds);
$duration = $hours * 3600 + $minutes * 60 + $seconds;
if ($duration < $duration_min || $duration > $duration_max) {
continue;
}
}
// $vid_list .= $vid . ',';

View File

@ -55,6 +55,8 @@ final class Logger
'Unable to find channel. The channel is non-existing or non-public',
// fb
'This group is not public! RSS-Bridge only supports public groups!',
// tiktok 404
'https://www.tiktok.com/@',
];
foreach ($ignoredExceptions as $ignoredException) {
if (str_starts_with($e->getMessage(), $ignoredException)) {