mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2024-11-22 17:45:40 +03:00
[TikTokBridge] Add bridge (#2828)
This commit is contained in:
parent
c78c1254a8
commit
192dc4dae2
1 changed files with 87 additions and 0 deletions
87
bridges/TikTokBridge.php
Normal file
87
bridges/TikTokBridge.php
Normal file
|
@ -0,0 +1,87 @@
|
|||
<?php
|
||||
class TikTokBridge extends BridgeAbstract {
|
||||
const NAME = 'TikTok Bridge';
|
||||
const URI = 'https://www.tiktok.com';
|
||||
const DESCRIPTION = 'Returns posts';
|
||||
const MAINTAINER = 'VerifiedJoseph';
|
||||
const PARAMETERS = array(
|
||||
'By user' => array(
|
||||
'username' => array(
|
||||
'name' => 'Username',
|
||||
'type' => 'text',
|
||||
'required' => true,
|
||||
'exampleValue' => '@tiktok',
|
||||
)
|
||||
));
|
||||
|
||||
const TEST_DETECT_PARAMETERS = array(
|
||||
'https://www.tiktok.com/@tiktok' => array(
|
||||
'context' => 'By user', 'username' => '@tiktok'
|
||||
)
|
||||
);
|
||||
|
||||
const CACHE_TIMEOUT = 900; // 15 minutes
|
||||
|
||||
private $feedName = '';
|
||||
|
||||
public function detectParameters($url) {
|
||||
|
||||
if(preg_match('/tiktok\.com\/(@[\w]+)/', $url, $matches) > 0) {
|
||||
return array(
|
||||
'context' => 'By user',
|
||||
'username' => $matches[1]
|
||||
);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function collectData() {
|
||||
$html = getSimpleHTMLDOM($this->getURI());
|
||||
|
||||
$this->feedName = htmlspecialchars_decode($html->find('h1', 0)->plaintext);
|
||||
|
||||
foreach ($html->find('div.tiktok-x6y88p-DivItemContainerV2') as $div) {
|
||||
$item = [];
|
||||
|
||||
$link = $div->find('a', 0)->href;
|
||||
$image = $div->find('img', 0)->src;
|
||||
$views = $div->find('strong.video-count', 0)->plaintext;
|
||||
|
||||
$item['uri'] = $link;
|
||||
$item['title'] = $div->find('a', 1)->plaintext;
|
||||
$item['enclosures'][] = $image;
|
||||
|
||||
$item['content'] = <<<EOD
|
||||
<a href="{$link}"><img src="{$image}"/></a>
|
||||
<p>{$views} views<p>
|
||||
EOD;
|
||||
|
||||
$this->items[] = $item;
|
||||
}
|
||||
}
|
||||
|
||||
public function getURI() {
|
||||
switch($this->queriedContext) {
|
||||
case 'By user':
|
||||
return self::URI . '/' . $this->processUsername();
|
||||
default: return parent::getURI();
|
||||
}
|
||||
}
|
||||
|
||||
public function getName() {
|
||||
switch($this->queriedContext) {
|
||||
case 'By user':
|
||||
return $this->feedName . ' (' . $this->processUsername() . ') - TikTok';
|
||||
default: return parent::getName();
|
||||
}
|
||||
}
|
||||
|
||||
private function processUsername() {
|
||||
if (substr($this->getInput('username'), 0, 1) !== '@') {
|
||||
return '@' . $this->getInput('username');
|
||||
}
|
||||
|
||||
return $this->getInput('username');
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue