fix(binance): plus some other tweaks (#3753)

This commit is contained in:
Dag 2023-10-13 20:48:08 +02:00 committed by GitHub
parent fd52b9b9a4
commit 5f37c72be0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 46 additions and 53 deletions

View file

@ -8,48 +8,27 @@ class BinanceBridge extends BridgeAbstract
const MAINTAINER = 'thefranke';
const CACHE_TIMEOUT = 3600; // 1h
public function collectData()
{
$url = 'https://www.binance.com/bapi/composite/v1/public/content/blog/list?category=&tag=&page=1&size=12';
$json = getContents($url);
$data = Json::decode($json, false);
foreach ($data->data->blogList as $post) {
$item = [];
$item['title'] = $post->title;
// Url slug not in json
//$item['uri'] = $uri;
$item['timestamp'] = $post->postTimeUTC / 1000;
$item['author'] = 'Binance';
$item['content'] = $post->brief;
//$item['categories'] = $category;
$item['uid'] = $post->idStr;
$this->items[] = $item;
}
}
public function getIcon()
{
return 'https://bin.bnbstatic.com/static/images/common/favicon.ico';
}
public function collectData()
{
$html = getSimpleHTMLDOM(self::URI)
or returnServerError('Could not fetch Binance blog data.');
$appData = $html->find('script[id="__APP_DATA"]');
$appDataJson = json_decode($appData[0]->innertext);
$allposts = $appDataJson->routeProps->f3ac->blogListRes->list;
foreach ($allposts as $element) {
$date = $element->releasedTime;
$title = $element->title;
$category = $element->category->name;
$suburl = strtolower($category);
$suburl = str_replace(' ', '_', $suburl);
$uri = self::URI . '/' . $suburl . '/' . $element->idStr;
$contentHTML = getSimpleHTMLDOMCached($uri);
$contentAppData = $contentHTML->find('script[id="__APP_DATA"]');
$contentAppDataJson = json_decode($contentAppData[0]->innertext);
$content = $contentAppDataJson->routeProps->a106->blogDetail->content;
$item = [];
$item['title'] = $title;
$item['uri'] = $uri;
$item['timestamp'] = substr($date, 0, -3);
$item['author'] = 'Binance';
$item['content'] = $content;
$item['categories'] = $category;
$this->items[] = $item;
if (count($this->items) >= 10) {
break;
}
}
}
}

View file

@ -224,7 +224,7 @@ class CssSelectorComplexBridge extends BridgeAbstract
{
if (!empty($url_pattern)) {
$url_pattern = '/' . str_replace('/', '\/', $url_pattern) . '/';
$links = array_filter($links, function ($url) {
$links = array_filter($links, function ($url) use ($url_pattern) {
return preg_match($url_pattern, $url) === 1;
});
}
@ -359,7 +359,7 @@ class CssSelectorComplexBridge extends BridgeAbstract
$article_content = $entry_html->find($content_selector, 0);
if (is_null($article_content)) {
returnClientError('Could not article content at URL: ' . $entry_url);
returnClientError('Could not get article content at URL: ' . $entry_url);
}
$article_content = defaultLinkTo($article_content, $entry_url);

View file

@ -85,7 +85,7 @@ class FallGuysBridge extends BridgeAbstract
for ($i = 0; $i < count($mediaOptions); $i++) {
if (property_exists($mediaOptions[$i], 'youtubeVideo')) {
$videoUrl = 'https://youtu.be/' . $mediaOptions[$i]->youtubeVideo->contentId;
$image = $mainContentOptions[$i]->image->src;
$image = $mainContentOptions[$i]->image->src ?? '';
$content .= '<p>';

View file

@ -121,6 +121,9 @@ class InstagramBridge extends BridgeAbstract
$directLink = !is_null($this->getInput('direct_links')) && $this->getInput('direct_links');
$data = $this->getInstagramJSON($this->getURI());
if (!$data) {
return;
}
if (!is_null($this->getInput('u'))) {
$userMedia = $data->data->user->edge_owner_to_timeline_media->edges;
@ -286,9 +289,11 @@ class InstagramBridge extends BridgeAbstract
$html = getContents($uri);
$scriptRegex = '/window\._sharedData = (.*);<\/script>/';
preg_match($scriptRegex, $html, $matches, PREG_OFFSET_CAPTURE, 0);
return json_decode($matches[1][0]);
$ret = preg_match($scriptRegex, $html, $matches, PREG_OFFSET_CAPTURE);
if ($ret) {
return json_decode($matches[1][0]);
}
return null;
}
}

View file

@ -193,7 +193,7 @@ class MastodonBridge extends BridgeAbstract
&& preg_match('/^http(s|):\/\//', $attachment['url'], $match)
) {
$item['content'] = $item['content'] . '<br /><img ';
if ($attachment['name']) {
if (isset($attachment['name'])) {
$item['content'] .= sprintf('alt="%s" ', $attachment['name']);
}
$item['content'] .= sprintf('src="%s" />', $attachment['url']);

View file

@ -64,15 +64,20 @@ class PokemonTVBridge extends BridgeAbstract
continue;
}
}
switch ($element->{'media_type'}) {
switch ($element->media_type) {
case 'movie':
$itemtitle = $element->{'channel_name'};
case 'junior':
case 'original':
case 'non-animation':
$itemtitle = $element->channel_name;
break;
case 'episode':
$season = str_pad($mediaelement->{'season'}, 2, '0', STR_PAD_LEFT);
$episode = str_pad($mediaelement->{'episode'}, 2, '0', STR_PAD_LEFT);
$itemtitle = $element->{'channel_name'} . ' - S' . $season . 'E' . $episode;
break;
default:
$itemtitle = '';
}
$streamurl = 'https://watch.pokemon.com/' . $this->getCountryCode() . '/#/player?id=' . $mediaelement->{'id'};
$item = [];

View file

@ -24,6 +24,7 @@ abstract class FeedExpander extends BridgeAbstract
}
// prepare/massage the xml to make it more acceptable
$badStrings = [
'&nbsp;',
'&raquo;',
];
$xmlString = str_replace($badStrings, '', $xmlString);

View file

@ -260,13 +260,15 @@ class FeedItem
return $this->uid;
}
public function setUid($uid)
public function setUid($uid): void
{
$this->uid = null;
if (!is_string($uid)) {
Debug::log('Unique id must be a string!');
} elseif (preg_match('/^[a-f0-9]{40}$/', $uid)) {
// keep id if it already is SHA-1 hash
Debug::log(sprintf('uid must be string: %s (%s)', (string) $uid, var_export($uid, true)));
return;
}
if (preg_match('/^[a-f0-9]{40}$/', $uid)) {
// Preserve sha1 hash
$this->uid = $uid;
} else {
$this->uid = sha1($uid);

View file

@ -149,6 +149,7 @@ final class StreamHandler
);
error_log($text);
if ($record['level'] < Logger::ERROR && Debug::isEnabled()) {
// Not a good idea to print here because http headers might not have been sent
print sprintf("<pre>%s</pre>\n", e($text));
}
//$bytes = file_put_contents('/tmp/rss-bridge.log', $text, FILE_APPEND | LOCK_EX);