From 663729cf19da206e62cb65ddc4fdb151c66b3498 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pred=C3=A4?= <46051820+PredaaA@users.noreply.github.com> Date: Thu, 20 Jul 2023 05:50:45 +0200 Subject: [PATCH] [TikTokBridge] Use another way to get videos infos to include video link (#3557) * [TikTokBridge] Use another way to get videos infos to include video link * [TikTokBridge] Use cover if dynamicCover is empty * [TikTokBridge] Add support for the rest of item params --- bridges/TikTokBridge.php | 42 ++++++++++++++++++++++------------------ 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/bridges/TikTokBridge.php b/bridges/TikTokBridge.php index 1a30570d..e7cac825 100644 --- a/bridges/TikTokBridge.php +++ b/bridges/TikTokBridge.php @@ -33,32 +33,36 @@ class TikTokBridge extends BridgeAbstract $title = $html->find('h1', 0)->plaintext ?? self::NAME; $this->feedName = htmlspecialchars_decode($title); - foreach ($html->find('div.tiktok-x6y88p-DivItemContainerV2') as $div) { + $SIGI_STATE_RAW = $html->find('script[id=SIGI_STATE]', 0)->innertext; + $SIGI_STATE = json_decode($SIGI_STATE_RAW); + + foreach ($SIGI_STATE->ItemModule as $key => $value) { $item = []; - // todo: find proper link to tiktok item - $link = $div->find('a', 0)->href; - - $image = $div->find('img', 0)->src ?? ''; - - $views = $div->find('strong.video-count', 0)->plaintext; - - if ($link === 'https://www.tiktok.com/') { - $link = $this->getURI(); + $link = 'https://www.tiktok.com/@' . $value->author . '/video/' . $value->id; + $image = $value->video->dynamicCover; + if (empty($image)) { + $image = $value->video->cover; } + $views = $value->stats->playCount; + $hastags = []; + foreach ($value->textExtra as $tag) { + $hastags[] = $tag->hashtagName; + } + $hastags_str = ''; + foreach ($hastags as $tag) { + $hastags_str .= '#' . $tag . ' '; + } + $item['uri'] = $link; - - $a = $div->find('a', 1); - if ($a) { - $item['title'] = $a->plaintext; - } else { - $item['title'] = $this->getName(); - } + $item['title'] = $value->desc; + $item['timestamp'] = $value->createTime; + $item['author'] = '@' . $value->author; $item['enclosures'][] = $image; - + $item['categories'] = $hastags; $item['content'] = << -{$views} views +{$views} viewsHashtags: {$hastags_str} EOD; $this->items[] = $item;
{$views} views
+
Hashtags: {$hastags_str} EOD; $this->items[] = $item;