[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
This commit is contained in:
Predä 2023-07-20 05:50:45 +02:00 committed by GitHub
parent 2ffb54c7c2
commit 663729cf19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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 .= '<a href="https://www.tiktok.com/tag/' . $tag . '">#' . $tag . '</a> ';
}
$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'] = <<<EOD
<a href="{$link}"><img src="{$image}"/></a>
<p>{$views} views<p>
<p>{$views} views<p><br/>Hashtags: {$hastags_str}
EOD;
$this->items[] = $item;