proxitok/patches/0003-Fixed-getVideoByUrl.patch

51 lines
2.4 KiB
Diff
Raw Normal View History

2022-01-08 15:03:57 +00:00
From c23e8dbf0bd722799cf19182142d4b177f8fd933 Mon Sep 17 00:00:00 2001
From: Pablo Ferreiro <pferreiromero@gmail.com>
Date: Sat, 8 Jan 2022 15:47:21 +0100
Subject: [PATCH 3/3] Fixed getVideoByUrl
---
lib/TikTok/Api.php | 19 +++++++++++++------
1 file changed, 13 insertions(+), 6 deletions(-)
diff --git a/lib/TikTok/Api.php b/lib/TikTok/Api.php
index 8fd42ae..f800555 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":{', "</script>");
+ $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']);
--
2.34.1