2014-11-18 20:02:04 +01:00
|
|
|
<?php
|
|
|
|
class DailymotionBridge extends BridgeAbstract{
|
2015-11-05 16:50:18 +01:00
|
|
|
|
|
|
|
public function loadMetadatas() {
|
|
|
|
|
2016-08-27 11:55:58 +02:00
|
|
|
$this->maintainer = "mitsukarenai";
|
|
|
|
$this->name = "Dailymotion Bridge";
|
|
|
|
$this->uri = "https://www.dailymotion.com/";
|
|
|
|
$this->description = "Returns the 5 newest videos by username/playlist or search";
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-22 01:25:56 +02:00
|
|
|
$this->parameters["By username"] = array(
|
2016-08-27 11:55:58 +02:00
|
|
|
'u'=>array(
|
|
|
|
'name'=>'username',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-22 01:25:56 +02:00
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-22 01:25:56 +02:00
|
|
|
$this->parameters["By playlist id"] = array(
|
2016-08-27 11:55:58 +02:00
|
|
|
'p'=>array(
|
|
|
|
'name'=>'playlist id',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-22 01:25:56 +02:00
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-22 01:25:56 +02:00
|
|
|
$this->parameters["From search results"] = array(
|
2016-08-25 00:19:41 +02:00
|
|
|
's'=>array(
|
|
|
|
'name'=>'Search keyword',
|
|
|
|
'required'=>true
|
|
|
|
),
|
2016-08-27 11:55:58 +02:00
|
|
|
'pa'=>array(
|
|
|
|
'name'=>'Page',
|
|
|
|
'type'=>'number'
|
|
|
|
)
|
2016-08-22 01:25:56 +02:00
|
|
|
);
|
2016-08-27 11:55:58 +02:00
|
|
|
}
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-21 11:46:23 +02:00
|
|
|
function getMetadata($id) {
|
2016-08-27 11:55:58 +02: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 16:50:18 +01:00
|
|
|
|
2016-08-27 11:55:58 +02: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 11:46:23 +02:00
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
|
2016-08-27 11:55:58 +02:00
|
|
|
public function getName(){
|
2016-08-25 01:24:53 +02:00
|
|
|
$param=$this->parameters[$this->queriedContext];
|
2016-08-27 11:55:58 +02:00
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username':
|
|
|
|
$specific=$param['u']['value'];
|
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
$specific=strtok($param['p']['value'], '_');
|
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$specific=$param['s']['value'];
|
|
|
|
break;
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
|
2016-08-27 11:55:58 +02:00
|
|
|
return $specific.' : Dailymotion Bridge';
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
|
2016-08-27 11:55:58 +02:00
|
|
|
public function getURI(){
|
|
|
|
$param=$this->parameters[$this->queriedContext];
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username':
|
|
|
|
$uri='http://www.dailymotion.com/user/'
|
|
|
|
.urlencode($param['u']['value']).'/1';
|
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
$uri='http://www.dailymotion.com/playlist/'
|
|
|
|
.urlencode(strtok($param['p']['value'], '_'));
|
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$uri='http://www.dailymotion.com/search/'
|
|
|
|
.urlencode($param['s']['value']);
|
|
|
|
if(isset($param['pa']['value'])){
|
|
|
|
$uri.='/'.$param['pa']['value'];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
|
2016-08-27 11:55:58 +02:00
|
|
|
public function getCacheDuration(){
|
|
|
|
return 3600*3; // 3 hours
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
}
|