From 0bf38e5c56a795301d540f4b0ce6e9bd9935b058 Mon Sep 17 00:00:00 2001 From: Dag Date: Wed, 20 Sep 2023 03:15:15 +0200 Subject: [PATCH] fix: small notice errors (#3677) * fix notice * fix notice * tweak * tweaks --- bridges/CodebergBridge.php | 7 +++++- bridges/TelegramBridge.php | 7 ++++-- bridges/ThePirateBayBridge.php | 1 + bridges/TwitchBridge.php | 41 ++++++++++++++-------------------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/bridges/CodebergBridge.php b/bridges/CodebergBridge.php index 83775885..c13ff004 100644 --- a/bridges/CodebergBridge.php +++ b/bridges/CodebergBridge.php @@ -181,7 +181,12 @@ class CodebergBridge extends BridgeAbstract $item['title'] = $message->find('span.message-wrapper', 0)->plaintext; $item['uri'] = $tr->find('td.sha', 0)->find('a', 0)->href; $item['author'] = $tr->find('td.author', 0)->plaintext; - $item['timestamp'] = $tr->find('td', 3)->find('span', 0)->title; + + $var = $tr->find('td', 3); + $var1 = $var->find('span', 0); + if ($var1) { + $item['timestamp'] = $var1->title; + } if ($message->find('pre.commit-body', 0)) { $message->find('pre.commit-body', 0)->style = ''; diff --git a/bridges/TelegramBridge.php b/bridges/TelegramBridge.php index 9d73e06e..a3c910e8 100644 --- a/bridges/TelegramBridge.php +++ b/bridges/TelegramBridge.php @@ -55,8 +55,11 @@ class TelegramBridge extends BridgeAbstract $item['title'] = $this->itemTitle; $item['timestamp'] = $messageDiv->find('span.tgme_widget_message_meta', 0)->find('time', 0)->datetime; $item['enclosures'] = $this->enclosures; - $author = trim($messageDiv->find('a.tgme_widget_message_owner_name', 0)->plaintext); - $item['author'] = html_entity_decode($author, ENT_QUOTES); + + $messageOwner = $messageDiv->find('a.tgme_widget_message_owner_name', 0); + if ($messageOwner) { + $item['author'] = html_entity_decode(trim($messageOwner->plaintext), ENT_QUOTES); + } $this->items[] = $item; } diff --git a/bridges/ThePirateBayBridge.php b/bridges/ThePirateBayBridge.php index 5b305c82..27732db5 100644 --- a/bridges/ThePirateBayBridge.php +++ b/bridges/ThePirateBayBridge.php @@ -65,6 +65,7 @@ class ThePirateBayBridge extends BridgeAbstract '207' => 'HD Movies', '208' => 'HD TV-Shows', '209' => '3D', + '211' => 'UHD/4k Movies', '212' => 'UHD/4k TV-Shows', '299' => 'Other', '301' => 'Windows', diff --git a/bridges/TwitchBridge.php b/bridges/TwitchBridge.php index 146fed3d..e4abaa60 100644 --- a/bridges/TwitchBridge.php +++ b/bridges/TwitchBridge.php @@ -90,7 +90,8 @@ EOD; 'channel' => $channel, 'types' => self::BROADCAST_TYPES[$type] ]; - $data = $this->apiRequest($query, $variables); + $response = $this->apiRequest($query, $variables); + $data = $response->data; if ($data->user === null) { throw new \Exception(sprintf('Unable to find channel `%s`', $channel)); } @@ -205,37 +206,29 @@ EOD; ); } - // GraphQL: https://graphql.org/ - // Tool for developing/testing queries: https://github.com/skevy/graphiql-app + /** + * GraphQL: https://graphql.org/ + * Tool for developing/testing queries: https://github.com/skevy/graphiql-app + * + * Official instructions for obtaining your own client ID can be found here: + * https://dev.twitch.tv/docs/v5/#getting-a-client-id + */ private function apiRequest($query, $variables) { $request = [ - 'query' => $query, - 'variables' => $variables + '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: kimne78kx3ncx6brgo4mv6wki5h1ko' + $headers = [ + 'Client-ID: kimne78kx3ncx6brgo4mv6wki5h1ko', ]; $opts = [ CURLOPT_CUSTOMREQUEST => 'POST', - CURLOPT_POSTFIELDS => json_encode($request) + CURLOPT_POSTFIELDS => json_encode($request), ]; - - Logger::debug("Sending GraphQL query:\n" . $query); - Logger::debug("Sending GraphQL variables:\n" . json_encode($variables, JSON_PRETTY_PRINT)); - $response = json_decode(getContents('https://gql.twitch.tv/gql', $header, $opts)); - Logger::debug("Got GraphQL response:\n" . json_encode($response, JSON_PRETTY_PRINT)); - - if (isset($response->errors)) { - $messages = array_column($response->errors, 'message'); - throw new \Exception(sprintf('twitch api: `%s`', implode("\n", $messages))); - } - - return $response->data; + $json = getContents('https://gql.twitch.tv/gql', $headers, $opts); + $result = Json::decode($json, false); + return $result; } public function getName()