From c8540e5dfaf8ec807cafd4ab45982163f2a47c74 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Tue, 20 Aug 2024 23:49:33 +0200 Subject: [PATCH] get video feed from cache and better attribute check --- VERSION | 2 +- src/Items/Hashtag.php | 9 +++++++-- src/Items/Music.php | 9 +++++++-- src/Items/User.php | 14 +++++++++++--- src/Items/Video.php | 18 ++++++++++-------- 5 files changed, 36 insertions(+), 16 deletions(-) diff --git a/VERSION b/VERSION index 1ed771e..f5383cf 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.6.0.2 +2.6.0.3 diff --git a/src/Items/Hashtag.php b/src/Items/Hashtag.php index 00c03ce..ad74992 100644 --- a/src/Items/Hashtag.php +++ b/src/Items/Hashtag.php @@ -21,8 +21,13 @@ public function info(): self { $info = Info::fromReq($req); if ($info->meta->success && isset($req->jsonBody->challengeInfo)) { - $info->setDetail($req->jsonBody->challengeInfo->challenge); - $info->setStats($req->jsonBody->challengeInfo->stats); + if (isset($req->jsonBody->challengeInfo->challenge)) { + $info->setDetail($req->jsonBody->challengeInfo->challenge); + } + + if (isset($req->jsonBody->challengeInfo->stats)) { + $info->setStats($req->jsonBody->challengeInfo->stats); + } } $this->info = $info; diff --git a/src/Items/Music.php b/src/Items/Music.php index bc100cd..5f5f2d2 100644 --- a/src/Items/Music.php +++ b/src/Items/Music.php @@ -22,8 +22,13 @@ public function info(): self { $info = Info::fromReq($req); if ($info->meta->success && isset($req->jsonBody->musicInfo)) { - $info->setDetail($req->jsonBody->musicInfo->music); - $info->setStats($req->jsonBody->musicInfo->stats); + if (isset($req->jsonBody->musicInfo->music)) { + $info->setDetail($req->jsonBody->musicInfo->music); + } + + if (isset($req->jsonBody->musicInfo->stats)) { + $info->setStats($req->jsonBody->musicInfo->stats); + } } $this->info = $info; diff --git a/src/Items/User.php b/src/Items/User.php index e50769a..d094996 100644 --- a/src/Items/User.php +++ b/src/Items/User.php @@ -24,9 +24,17 @@ public function info(): self { $info = Info::fromReq($req); if ($info->meta->success) { - if (isset($req->jsonBody->userInfo)) { - $info->setDetail($req->jsonBody->userInfo->user); - $info->setStats($req->jsonBody->userInfo->stats); + if (isset($req->jsonBody->userInfo, $req->jsonBody->userInfo->user)) { + // userInfo is available + if (isset($req->jsonBody->userInfo->user)) { + // Set details + $info->setDetail($req->jsonBody->userInfo->user); + } + + if (isset($req->jsonBody->userInfo->stats)) { + // Set stats + $info->setStats($req->jsonBody->userInfo->stats); + } } } $this->info = $info; diff --git a/src/Items/Video.php b/src/Items/Video.php index 73ea50d..0a65aca 100644 --- a/src/Items/Video.php +++ b/src/Items/Video.php @@ -2,7 +2,6 @@ namespace TikScraper\Items; use TikScraper\Cache; -use TikScraper\Constants\Responses; use TikScraper\Models\Feed; use TikScraper\Models\Info; use TikScraper\Sender; @@ -47,13 +46,16 @@ public function info(): self { public function feed(): self { $this->cursor = 0; - if ($this->item !== null) { - $this->feed = Feed::fromCache((object) [ - "items" => [$this->item], - "hasMore" => false, - "minCursor" => 0, - "maxCursor" => "" - ]); + if ($this->infoOk()) { + $preloaded = $this->handleFeedCache(); + if (!$preloaded && $this->item !== null) { + $this->feed = Feed::fromCache((object) [ + "items" => [$this->item], + "hasMore" => false, + "minCursor" => 0, + "maxCursor" => "" + ]); + } } return $this; }