fix(tiktok): feed item link (#3511)

* fix(tiktok): feed item link

* fix(tiktok): support entire url, for convenience
This commit is contained in:
Dag 2023-07-08 17:07:20 +02:00 committed by GitHub
parent 341649a8a4
commit 61b307a9f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -26,18 +26,6 @@ class TikTokBridge extends BridgeAbstract
private $feedName = '';
public function detectParameters($url)
{
if (preg_match('/tiktok\.com\/(@[\w]+)/', $url, $matches) > 0) {
return [
'context' => 'By user',
'username' => $matches[1]
];
}
return null;
}
public function collectData()
{
$html = getSimpleHTMLDOM($this->getURI());
@ -48,10 +36,15 @@ class TikTokBridge extends BridgeAbstract
foreach ($html->find('div.tiktok-x6y88p-DivItemContainerV2') as $div) {
$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();
}
$item['uri'] = $link;
$a = $div->find('a', 1);
@ -93,10 +86,25 @@ EOD;
private function processUsername()
{
if (substr($this->getInput('username'), 0, 1) !== '@') {
return '@' . $this->getInput('username');
$username = trim($this->getInput('username'));
if (preg_match('#^https?://www\.tiktok\.com/@(.*)$#', $username, $m)) {
return '@' . $m[1];
}
if (substr($username, 0, 1) !== '@') {
return '@' . $username;
}
return $username;
}
public function detectParameters($url)
{
if (preg_match('/tiktok\.com\/(@[\w]+)/', $url, $matches) > 0) {
return [
'context' => 'By user',
'username' => $matches[1]
];
}
return $this->getInput('username');
return null;
}
}