2014-11-18 22:02:04 +03:00
|
|
|
<?php
|
|
|
|
class DailymotionBridge extends BridgeAbstract{
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
public $maintainer = "mitsukarenai";
|
|
|
|
public $name = "Dailymotion Bridge";
|
|
|
|
public $uri = "https://www.dailymotion.com/";
|
|
|
|
public $description = "Returns the 5 newest videos by username/playlist or search";
|
|
|
|
|
|
|
|
public $parameters = array (
|
|
|
|
'By username' => array(
|
|
|
|
'u'=>array(
|
|
|
|
'name'=>'username',
|
|
|
|
'required'=>true
|
|
|
|
)
|
|
|
|
),
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-27 22:03:26 +03:00
|
|
|
'By playlist id' => array(
|
|
|
|
'p'=>array(
|
|
|
|
'name'=>'playlist id',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-25 01:19:41 +03:00
|
|
|
),
|
2016-08-27 22:03:26 +03:00
|
|
|
|
|
|
|
'From search results' => array(
|
|
|
|
's'=>array(
|
|
|
|
'name'=>'Search keyword',
|
|
|
|
'required'=>true
|
|
|
|
),
|
|
|
|
'pa'=>array(
|
|
|
|
'name'=>'Page',
|
|
|
|
'type'=>'number'
|
|
|
|
)
|
2016-08-27 12:55:58 +03:00
|
|
|
)
|
2016-08-22 02:25:56 +03:00
|
|
|
);
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-21 12:46:23 +03:00
|
|
|
function getMetadata($id) {
|
2016-08-27 12:55:58 +03:00
|
|
|
$metadata=array();
|
|
|
|
$html2 = $this->getSimpleHTMLDOM('http://www.dailymotion.com/video/'.$id)
|
|
|
|
or $this->returnServerError('Could not request Dailymotion.');
|
|
|
|
$metadata['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
|
|
|
|
$metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 0)->getAttribute('content') );
|
|
|
|
$metadata['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
|
|
|
|
$metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
|
|
|
|
return $metadata;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function collectData(){
|
|
|
|
$html = '';
|
|
|
|
$limit = 5;
|
|
|
|
$count = 0;
|
2015-11-05 18:50:18 +03:00
|
|
|
|
2016-08-27 12:55:58 +03:00
|
|
|
$html = $this->getSimpleHTMLDOM($this->getURI())
|
|
|
|
or $this->returnServerError('Could not request Dailymotion.');
|
|
|
|
|
|
|
|
foreach($html->find('div.media a.preview_link') as $element) {
|
|
|
|
if($count < $limit) {
|
|
|
|
$item = array();
|
|
|
|
$item['id'] = str_replace('/video/', '', strtok($element->href, '_'));
|
|
|
|
$metadata = $this->getMetadata($item['id']);
|
|
|
|
$item['uri'] = $metadata['uri'];
|
|
|
|
$item['title'] = $metadata['title'];
|
|
|
|
$item['timestamp'] = $metadata['timestamp'];
|
|
|
|
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $metadata['thumbnailUri'] . '" /></a><br><a href="' . $item['uri'] . '">' . $item['title'] . '</a>';
|
|
|
|
$this->items[] = $item;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
2016-08-21 12:46:23 +03:00
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2016-08-27 12:55:58 +03:00
|
|
|
public function getName(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username':
|
2016-08-28 02:25:33 +03:00
|
|
|
$specific=$this->getInput('u');
|
2016-08-27 12:55:58 +03:00
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
2016-08-28 02:25:33 +03:00
|
|
|
$specific=strtok($this->getInput('p'), '_');
|
2016-08-27 12:55:58 +03:00
|
|
|
break;
|
|
|
|
case 'From search results':
|
2016-08-28 02:25:33 +03:00
|
|
|
$specific=$this->getInput('s');
|
2016-08-27 12:55:58 +03:00
|
|
|
break;
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2016-08-27 12:55:58 +03:00
|
|
|
return $specific.' : Dailymotion Bridge';
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2016-08-27 12:55:58 +03:00
|
|
|
public function getURI(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username':
|
|
|
|
$uri='http://www.dailymotion.com/user/'
|
2016-08-28 02:25:33 +03:00
|
|
|
.urlencode($this->getInput('u')).'/1';
|
2016-08-27 12:55:58 +03:00
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
$uri='http://www.dailymotion.com/playlist/'
|
2016-08-28 02:25:33 +03:00
|
|
|
.urlencode(strtok($this->getInput('p'), '_'));
|
2016-08-27 12:55:58 +03:00
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$uri='http://www.dailymotion.com/search/'
|
2016-08-28 02:25:33 +03:00
|
|
|
.urlencode($this->getInput('s'));
|
|
|
|
if(isset($this->getInput('pa'))){
|
|
|
|
$uri.='/'.$this->getInput('pa');
|
2016-08-27 12:55:58 +03:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
|
2016-08-27 12:55:58 +03:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 3600*3; // 3 hours
|
|
|
|
}
|
2014-11-18 22:02:04 +03:00
|
|
|
}
|