rss-bridge/bridges/UrlebirdBridge.php

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

98 lines
3.1 KiB
PHP
Raw Normal View History

2021-06-25 22:55:13 +03:00
<?php
class UrlebirdBridge extends BridgeAbstract
{
2021-06-25 22:55:13 +03:00
const MAINTAINER = 'dotter-ak';
const NAME = 'urlebird.com';
const URI = 'https://urlebird.com/';
const DESCRIPTION = 'Bridge for urlebird.com';
2023-10-14 00:14:08 +03:00
const CACHE_TIMEOUT = 60 * 5;
2021-06-25 22:55:13 +03:00
const PARAMETERS = [
[
2021-06-25 22:55:13 +03:00
'query' => [
'name' => '@username or #hashtag',
'type' => 'text',
'required' => true,
'exampleValue' => '@willsmith',
2021-06-25 22:55:13 +03:00
'title' => '@username or #hashtag'
]
]
2021-06-25 22:55:13 +03:00
];
private $title;
public function collectData()
{
switch ($this->getInput('query')[0]) {
case '@':
$url = 'https://urlebird.com/user/' . substr($this->getInput('query'), 1) . '/';
break;
case '#':
$url = 'https://urlebird.com/hash/' . substr($this->getInput('query'), 1) . '/';
break;
2023-10-14 00:14:08 +03:00
default:
returnServerError('Please, enter valid username or hashtag!');
break;
2021-06-25 22:55:13 +03:00
}
$html = getSimpleHTMLDOM($url);
2023-10-14 00:14:08 +03:00
$limit = 10;
2021-06-25 22:55:13 +03:00
$this->title = $html->find('title', 0)->innertext;
$articles = $html->find('div.thumb');
2023-10-14 00:14:08 +03:00
$articles = array_slice($articles, 0, $limit);
2021-06-25 22:55:13 +03:00
foreach ($articles as $article) {
$item = [];
2023-10-14 00:14:08 +03:00
$itemUrl = $article->find('a', 2)->href;
$item['uri'] = $this->encodePathSegments($itemUrl);
$dom = getSimpleHTMLDOM($item['uri']);
$videoDiv = $dom->find('div.video', 0);
// timestamp
$timestampH6 = $videoDiv->find('h6', 0);
$datetimeString = str_replace('Posted ', '', $timestampH6->plaintext);
$item['timestamp'] = $datetimeString;
$innertext = $dom->find('a.user-video', 1)->innertext;
$alt = $article->find('img', 0)->alt;
$item['author'] = $alt . ' (' . $innertext . ')';
$item['title'] = $dom->find('title', 0)->innertext;
$item['enclosures'][] = $dom->find('video', 0)->poster;
$video = $dom->find('video', 0);
2021-06-25 22:55:13 +03:00
$video->autoplay = null;
2023-10-14 00:14:08 +03:00
2021-06-25 22:55:13 +03:00
$item['content'] = $video->outertext . '<br>' .
2023-10-14 00:14:08 +03:00
$dom->find('div.music', 0) . '<br>' .
$dom->find('div.info2', 0)->innertext .
'<br><br><a href="' . $dom->find('video', 0)->src .
'">Direct video link</a><br><br><a href="' . $item['uri'] .
'">Post link</a><br><br>';
2023-10-14 00:14:08 +03:00
2021-06-25 22:55:13 +03:00
$this->items[] = $item;
}
}
2023-10-14 00:14:08 +03:00
private function encodePathSegments($url)
{
$path = parse_url($url, PHP_URL_PATH);
$pathSegments = explode('/', $path);
$encodedPathSegments = array_map('urlencode', $pathSegments);
$encodedPath = implode('/', $encodedPathSegments);
$result = str_replace($path, $encodedPath, $url);
return $result;
}
2021-06-25 22:55:13 +03:00
public function getName()
{
return $this->title ?: parent::getName();
}
public function getIcon()
{
return 'https://urlebird.com/favicon.ico';
}
}