aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Dag <me@dvikan.no> 2022-09-09 20:18:50 +0200
committerGravatar GitHub <noreply@github.com> 2022-09-09 20:18:50 +0200
commit94ae098ef5687f6cc128a0fb7bd33443e40e3e55 (patch)
tree7fa2d0792b1f5df84660d3d29c07f07b0b5c6063
parent6ac347d5ac36733d3199f1769626924613d4daa3 (diff)
downloadrss-bridge-94ae098ef5687f6cc128a0fb7bd33443e40e3e55.tar.gz
rss-bridge-94ae098ef5687f6cc128a0fb7bd33443e40e3e55.tar.zst
rss-bridge-94ae098ef5687f6cc128a0fb7bd33443e40e3e55.zip
fix: various fixes (#3023)
* improve twitch error message * fix worldcosplay notice * fix: add new video image to telegram * fix: reuters * fix: formula1 * twitter
-rw-r--r--bridges/Formula1Bridge.php5
-rw-r--r--bridges/ReutersBridge.php2
-rw-r--r--bridges/TelegramBridge.php2
-rw-r--r--bridges/TwitchBridge.php25
-rw-r--r--bridges/TwitterBridge.php13
-rw-r--r--bridges/WorldCosplayBridge.php5
-rw-r--r--lib/Logger.php1
7 files changed, 21 insertions, 32 deletions
diff --git a/bridges/Formula1Bridge.php b/bridges/Formula1Bridge.php
index 2adce583..f84b1ca7 100644
--- a/bridges/Formula1Bridge.php
+++ b/bridges/Formula1Bridge.php
@@ -11,7 +11,6 @@ class Formula1Bridge extends BridgeAbstract
const API_URL = 'https://api.formula1.com/v1/editorial/articles?limit=%u';
const ARTICLE_AUTHOR = 'Formula 1';
- const ARTICLE_HTML = '<p>%s</p><a href="%s" target="_blank"><img src="%s" alt="%s" title="%s"></a>';
const ARTICLE_URL = 'https://formula1.com/en/latest/article.%s.%s.html';
const LIMIT_MIN = 1;
@@ -58,8 +57,8 @@ class Formula1Bridge extends BridgeAbstract
$item['enclosures'] = [$article->thumbnail->image->url];
$item['uid'] = $article->id;
$item['content'] = sprintf(
- self::ARTICLE_HTML,
- $article->metaDescription,
+ '<p>%s</p><a href="%s" target="_blank"><img src="%s" alt="%s" title="%s"></a>',
+ $article->metaDescription ?? $article->title,
$item['uri'],
$item['enclosures'][0],
$caption,
diff --git a/bridges/ReutersBridge.php b/bridges/ReutersBridge.php
index 2f13d6b5..17f6a705 100644
--- a/bridges/ReutersBridge.php
+++ b/bridges/ReutersBridge.php
@@ -612,7 +612,7 @@ EOD;
// Some article cause unexpected behaviour like redirect to another site not API.
// Attempt to check article source type to avoid this.
if (!$this->useWireAPI && $source_type != 'Package') { // Only Reuters PF api have this, Wire don't.
- $author = $this->handleAuthorName($story['authors']);
+ $author = $this->handleAuthorName($story['authors'] ?? []);
$timestamp = $story['published_time'];
$image_placeholder = '';
if (isset($story['thumbnail'])) {
diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php
index 7daeeea3..d650cb31 100644
--- a/bridges/TelegramBridge.php
+++ b/bridges/TelegramBridge.php
@@ -280,6 +280,8 @@ EOD;
preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_video_thumb', 0)->style, $photo);
} elseif ($messageDiv->find('i.link_preview_video_thumb')) {
preg_match($this->backgroundImageRegex, $messageDiv->find('i.link_preview_video_thumb', 0)->style, $photo);
+ } elseif ($messageDiv->find('i.tgme_widget_message_roundvideo_thumb')) {
+ preg_match($this->backgroundImageRegex, $messageDiv->find('i.tgme_widget_message_roundvideo_thumb', 0)->style, $photo);
}
$this->enclosures[] = $photo[1];
diff --git a/bridges/TwitchBridge.php b/bridges/TwitchBridge.php
index c26dafc6..f7e44d1e 100644
--- a/bridges/TwitchBridge.php
+++ b/bridges/TwitchBridge.php
@@ -30,13 +30,6 @@ class TwitchBridge extends BridgeAbstract
]
]];
- /*
- * Official instructions for obtaining your own client ID can be found here:
- * https://dev.twitch.tv/docs/v5/#getting-a-client-id
- */
- const CLIENT_ID = 'kimne78kx3ncx6brgo4mv6wki5h1ko';
-
- const API_ENDPOINT = 'https://gql.twitch.tv/gql';
const BROADCAST_TYPES = [
'all' => [
'ARCHIVE',
@@ -214,8 +207,12 @@ EOD;
'query' => $query,
'variables' => $variables
];
+ /**
+ * Official instructions for obtaining your own client ID can be found here:
+ * https://dev.twitch.tv/docs/v5/#getting-a-client-id
+ */
$header = [
- 'Client-ID: ' . self::CLIENT_ID
+ 'Client-ID: kimne78kx3ncx6brgo4mv6wki5h1ko'
];
$opts = [
CURLOPT_CUSTOMREQUEST => 'POST',
@@ -223,17 +220,13 @@ EOD;
];
Debug::log("Sending GraphQL query:\n" . $query);
- Debug::log("Sending GraphQL variables:\n"
- . json_encode($variables, JSON_PRETTY_PRINT));
-
- $response = json_decode(getContents(self::API_ENDPOINT, $header, $opts));
-
- Debug::log("Got GraphQL response:\n"
- . json_encode($response, JSON_PRETTY_PRINT));
+ Debug::log("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT));
+ $response = json_decode(getContents('https://gql.twitch.tv/gql', $header, $opts));
+ Debug::log("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT));
if (isset($response->errors)) {
$messages = array_column($response->errors, 'message');
- returnServerError('API error(s): ' . implode("\n", $messages));
+ throw new \Exception(sprintf('twitch api: `%s`', implode("\n", $messages)));
}
return $response->data;
diff --git a/bridges/TwitterBridge.php b/bridges/TwitterBridge.php
index cc87743a..36f67def 100644
--- a/bridges/TwitterBridge.php
+++ b/bridges/TwitterBridge.php
@@ -273,7 +273,7 @@ EOD
if (!$data) {
switch ($this->queriedContext) {
case 'By keyword or hashtag':
- returnServerError('No results for this query.');
+ returnServerError('twitter: No results for this query.');
// fall-through
case 'By username':
returnServerError('Requested username can\'t be found.');
@@ -645,16 +645,7 @@ EOD;
}
// fall-through
default:
- $code = $e->getCode();
- $data = $e->getMessage();
- returnServerError(
- <<<EOD
-Failed to make api call: $api
-HTTP Status: $code
-Errormessage: $data
-EOD
- );
- break;
+ throw $e;
}
}
} while ($retry);
diff --git a/bridges/WorldCosplayBridge.php b/bridges/WorldCosplayBridge.php
index 8995aa70..721c545f 100644
--- a/bridges/WorldCosplayBridge.php
+++ b/bridges/WorldCosplayBridge.php
@@ -107,11 +107,14 @@ class WorldCosplayBridge extends BridgeAbstract
$item = [
'uri' => self::URI . substr($image->url, 1),
'title' => $image->subject,
- 'timestamp' => $image->created_at,
'author' => $img->member->global_name,
'enclosures' => [$image->large_url],
'uid' => $image->id,
];
+ // Context cosplayer don't have created_at
+ if (isset($image->created_at)) {
+ $item['timestamp'] = $image->created_at;
+ }
$item['content'] = sprintf(
self::CONTENT_HTML,
$item['uri'],
diff --git a/lib/Logger.php b/lib/Logger.php
index dcd945e3..740364af 100644
--- a/lib/Logger.php
+++ b/lib/Logger.php
@@ -34,6 +34,7 @@ final class Logger
'Exception InvalidArgumentException: Format name invalid!',
'Exception InvalidArgumentException: Unknown format given!',
'Exception InvalidArgumentException: Bridge name invalid!',
+ 'Exception Exception: twitter: No results for this query',
];
foreach ($ignoredExceptions as $ignoredException) {
if (str_starts_with($context['message'], $ignoredException)) {