From 816ebe168d12923944b81b3f10bb22baf58efd66 Mon Sep 17 00:00:00 2001 From: Pablo Ferreiro Date: Tue, 11 Jan 2022 19:09:08 +0100 Subject: [PATCH 3/4] Fixed getVideoByUrl --- lib/TikTok/Api.php | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/TikTok/Api.php b/lib/TikTok/Api.php index 8fd42ae..21ebff1 100644 --- a/lib/TikTok/Api.php +++ b/lib/TikTok/Api.php @@ -483,20 +483,27 @@ if (!\class_exists('\Sovit\TikTok\Api')) { throw new \Exception("Invalid VIDEO URL"); } $result = $this->remote_call($url, false); - $result = Helper::string_between($result, '{"props":{"initialProps":{', ""); + $result = Helper::string_between($result, "window['SIGI_STATE']=", ";window['SIGI_RETRY']="); if (!empty($result)) { - $jsonData = json_decode('{"props":{"initialProps":{' . $result); - if (isset($jsonData->props->pageProps->itemInfo->itemStruct)) { + $jsonData = json_decode($result); + if (isset($jsonData->ItemModule, $jsonData->ItemList, $jsonData->UserModule)) { + $id = $jsonData->ItemList->video->keyword; + $item = $jsonData->ItemModule->{$id}; + $username = $item->author; $result = (object) [ 'statusCode' => 0, 'info' => (object) [ 'type' => 'video', - 'detail' => $url, + 'detail' => (object) [ + "url" => $url, + "user" => $jsonData->UserModule->users->{$username}, + "stats" => $item->stats + ], ], - "items" => [$jsonData->props->pageProps->itemInfo->itemStruct], + "items" => [$item], "hasMore" => false, "minCursor" => '0', - "maxCursor" => ' 0', + "maxCursor" => '0' ]; if ($this->cacheEnabled) { $this->cacheEngine->set($cacheKey, $result, $this->_config['cache-timeout']); @@ -590,3 +597,4 @@ if (!\class_exists('\Sovit\TikTok\Api')) { } } } + -- 2.34.1