2014-11-18 22:02:04 +03:00
|
|
|
<?php
|
2017-02-11 18:16:56 +03:00
|
|
|
class DailymotionBridge extends BridgeAbstract {
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const MAINTAINER = 'mitsukarenai';
|
|
|
|
const NAME = 'Dailymotion Bridge';
|
|
|
|
const URI = 'https://www.dailymotion.com/';
|
2019-09-07 19:42:45 +03:00
|
|
|
const CACHE_TIMEOUT = 3600; // 1h
|
2017-02-11 18:16:56 +03:00
|
|
|
const DESCRIPTION = 'Returns the 5 newest videos by username/playlist or search';
|
2016-08-27 22:03:26 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
const PARAMETERS = array (
|
|
|
|
'By username' => array(
|
|
|
|
'u' => array(
|
|
|
|
'name' => 'username',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'moviepilot',
|
2017-02-11 18:16:56 +03:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'By playlist id' => array(
|
|
|
|
'p' => array(
|
|
|
|
'name' => 'playlist id',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'x6xyc6',
|
2017-02-11 18:16:56 +03:00
|
|
|
)
|
|
|
|
),
|
|
|
|
'From search results' => array(
|
|
|
|
's' => array(
|
|
|
|
'name' => 'Search keyword',
|
2022-03-24 13:59:34 +03:00
|
|
|
'required' => true,
|
|
|
|
'exampleValue' => 'matrix',
|
2017-02-11 18:16:56 +03:00
|
|
|
),
|
|
|
|
'pa' => array(
|
|
|
|
'name' => 'Page',
|
2019-09-07 19:42:45 +03:00
|
|
|
'type' => 'number',
|
|
|
|
'defaultValue' => 1,
|
2017-02-11 18:16:56 +03:00
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
private $feedName = '';
|
2016-08-27 22:03:26 +03:00
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
private $apiUrl = 'https://api.dailymotion.com';
|
|
|
|
private $apiFields = 'created_time,description,id,owner.screenname,tags,thumbnail_url,title,url';
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2018-10-26 19:07:34 +03:00
|
|
|
public function getIcon() {
|
|
|
|
return 'https://static1-ssl.dmcdn.net/images/neon/favicons/android-icon-36x36.png.vf806ca4ed0deed812';
|
|
|
|
}
|
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
public function collectData() {
|
|
|
|
|
|
|
|
if ($this->queriedContext === 'By username' || $this->queriedContext === 'By playlist id') {
|
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$apiJson = getContents($this->getApiUrl());
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
$apiData = json_decode($apiJson, true);
|
|
|
|
|
|
|
|
$this->feedName = $this->getPlaylistTitle($this->getInput('p'));
|
|
|
|
|
|
|
|
foreach ($apiData['list'] as $apiItem) {
|
|
|
|
$item = array();
|
|
|
|
|
|
|
|
$item['uri'] = $apiItem['url'];
|
|
|
|
$item['uid'] = $apiItem['id'];
|
|
|
|
$item['title'] = $apiItem['title'];
|
|
|
|
$item['timestamp'] = $apiItem['created_time'];
|
|
|
|
$item['author'] = $apiItem['owner.screenname'];
|
|
|
|
$item['content'] = '<p><a href="' . $apiItem['url'] . '">
|
|
|
|
<img src="' . $apiItem['thumbnail_url'] . '"></a></p><p>' . $apiItem['description'] . '</p>';
|
|
|
|
$item['categories'] = $apiItem['tags'];
|
|
|
|
$item['enclosures'][] = $apiItem['thumbnail_url'];
|
2016-08-28 14:38:01 +03:00
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
$this->items[] = $item;
|
|
|
|
}
|
|
|
|
}
|
2016-08-27 12:55:58 +03:00
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
if ($this->queriedContext === 'From search results') {
|
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI());
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
foreach($html->find('div.media a.preview_link') as $element) {
|
2017-02-11 18:16:56 +03:00
|
|
|
$item = array();
|
2019-09-07 19:42:45 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['id'] = str_replace('/video/', '', strtok($element->href, '_'));
|
|
|
|
$metadata = $this->getMetadata($item['id']);
|
2019-09-07 19:42:45 +03:00
|
|
|
|
2017-07-29 20:28:00 +03:00
|
|
|
if(empty($metadata)) {
|
2017-02-11 18:16:56 +03:00
|
|
|
continue;
|
|
|
|
}
|
2019-09-07 19:42:45 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['uri'] = $metadata['uri'];
|
|
|
|
$item['title'] = $metadata['title'];
|
|
|
|
$item['timestamp'] = $metadata['timestamp'];
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$item['content'] = '<a href="'
|
2019-09-07 19:42:45 +03:00
|
|
|
. $item['uri']
|
|
|
|
. '"><img src="'
|
|
|
|
. $metadata['thumbnailUri']
|
|
|
|
. '" /></a><br><a href="'
|
|
|
|
. $item['uri']
|
|
|
|
. '">'
|
|
|
|
. $item['title']
|
|
|
|
. '</a>';
|
2016-08-27 12:55:58 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
$this->items[] = $item;
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
if (count($this->items) >= 5) {
|
|
|
|
break;
|
|
|
|
}
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
public function getName() {
|
2017-07-29 20:28:00 +03:00
|
|
|
switch($this->queriedContext) {
|
2017-02-11 18:16:56 +03:00
|
|
|
case 'By username':
|
|
|
|
$specific = $this->getInput('u');
|
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
$specific = strtok($this->getInput('p'), '_');
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
if ($this->feedName) {
|
|
|
|
$specific = $this->feedName;
|
|
|
|
}
|
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$specific = $this->getInput('s');
|
|
|
|
break;
|
|
|
|
default: return parent::getName();
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2019-09-07 19:42:45 +03:00
|
|
|
return $specific . ' : Dailymotion';
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2017-02-11 18:16:56 +03:00
|
|
|
public function getURI(){
|
|
|
|
$uri = self::URI;
|
2017-07-29 20:28:00 +03:00
|
|
|
switch($this->queriedContext) {
|
2017-02-11 18:16:56 +03:00
|
|
|
case 'By username':
|
2019-09-07 19:42:45 +03:00
|
|
|
$uri .= 'user/' . urlencode($this->getInput('u'));
|
2017-02-11 18:16:56 +03:00
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
$uri .= 'playlist/' . urlencode(strtok($this->getInput('p'), '_'));
|
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$uri .= 'search/' . urlencode($this->getInput('s'));
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
if(!is_null($this->getInput('pa'))) {
|
|
|
|
$pa = $this->getInput('pa');
|
|
|
|
|
|
|
|
if ($this->getInput('pa') < 1) {
|
|
|
|
$pa = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
$uri .= '/' . $pa;
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
|
|
|
break;
|
2017-02-15 00:36:33 +03:00
|
|
|
default: return parent::getURI();
|
2017-02-11 18:16:56 +03:00
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
private function getMetadata($id) {
|
|
|
|
$metadata = array();
|
|
|
|
|
|
|
|
$html = getSimpleHTMLDOM(self::URI . 'video/' . $id);
|
|
|
|
|
|
|
|
if(!$html) {
|
|
|
|
return $metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
$metadata['title'] = $html->find('meta[property=og:title]', 0)->getAttribute('content');
|
|
|
|
$metadata['timestamp'] = strtotime(
|
|
|
|
$html->find('meta[property=video:release_date]', 0)->getAttribute('content')
|
|
|
|
);
|
|
|
|
$metadata['thumbnailUri'] = $html->find('meta[property=og:image]', 0)->getAttribute('content');
|
|
|
|
$metadata['uri'] = $html->find('meta[property=og:url]', 0)->getAttribute('content');
|
|
|
|
return $metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getPlaylistTitle($id) {
|
|
|
|
$title = '';
|
|
|
|
|
|
|
|
$url = self::URI . 'playlist/' . $id;
|
|
|
|
|
2022-01-02 12:36:09 +03:00
|
|
|
$html = getSimpleHTMLDOM($url);
|
2019-09-07 19:42:45 +03:00
|
|
|
|
|
|
|
$title = $html->find('meta[property=og:title]', 0)->getAttribute('content');
|
|
|
|
return $title;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getApiUrl() {
|
|
|
|
|
|
|
|
switch($this->queriedContext) {
|
|
|
|
case 'By username':
|
|
|
|
return $this->apiUrl . '/user/' . $this->getInput('u')
|
|
|
|
. '/videos?fields=' . urlencode($this->apiFields) . '&availability=1&sort=recent&limit=5';
|
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
return $this->apiUrl . '/playlist/' . $this->getInput('p')
|
|
|
|
. '/videos?fields=' . urlencode($this->apiFields) . '&limit=5';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
}
|