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