2014-11-18 20:02:04 +01:00
|
|
|
<?php
|
|
|
|
class DailymotionBridge extends BridgeAbstract{
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const MAINTAINER = "mitsukarenai";
|
|
|
|
const NAME = "Dailymotion Bridge";
|
|
|
|
const URI = "https://www.dailymotion.com/";
|
2016-09-25 17:04:28 +02:00
|
|
|
const CACHE_TIMEOUT = 10800; // 3h
|
2016-08-30 11:23:55 +02:00
|
|
|
const DESCRIPTION = "Returns the 5 newest videos by username/playlist or search";
|
2016-08-27 21:03:26 +02:00
|
|
|
|
2016-08-30 11:23:55 +02:00
|
|
|
const PARAMETERS = array (
|
2016-08-27 21:03:26 +02:00
|
|
|
'By username' => array(
|
|
|
|
'u'=>array(
|
|
|
|
'name'=>'username',
|
|
|
|
'required'=>true
|
|
|
|
)
|
|
|
|
),
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2016-08-27 21:03:26 +02:00
|
|
|
'By playlist id' => array(
|
|
|
|
'p'=>array(
|
|
|
|
'name'=>'playlist id',
|
|
|
|
'required'=>true
|
|
|
|
)
|
2016-08-25 00:19:41 +02:00
|
|
|
),
|
2016-08-27 21:03:26 +02:00
|
|
|
|
|
|
|
'From search results' => array(
|
|
|
|
's'=>array(
|
|
|
|
'name'=>'Search keyword',
|
|
|
|
'required'=>true
|
|
|
|
),
|
|
|
|
'pa'=>array(
|
|
|
|
'name'=>'Page',
|
|
|
|
'type'=>'number'
|
|
|
|
)
|
2016-08-27 11:55:58 +02:00
|
|
|
)
|
2016-08-22 01:25:56 +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();
|
2016-08-30 11:23:55 +02:00
|
|
|
$html2 = $this->getSimpleHTMLDOM(self::URI.'video/'.$id);
|
2016-08-28 13:38:01 +02:00
|
|
|
if(!$html2){
|
|
|
|
return $metadata;
|
|
|
|
}
|
|
|
|
|
2016-08-27 11:55:58 +02:00
|
|
|
$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']);
|
2016-08-28 13:38:01 +02:00
|
|
|
if(empty($metadata)){
|
|
|
|
continue;
|
|
|
|
}
|
2016-08-27 11:55:58 +02:00
|
|
|
$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(){
|
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username':
|
2016-08-28 01:25:33 +02:00
|
|
|
$specific=$this->getInput('u');
|
2016-08-27 11:55:58 +02:00
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
2016-08-28 01:25:33 +02:00
|
|
|
$specific=strtok($this->getInput('p'), '_');
|
2016-08-27 11:55:58 +02:00
|
|
|
break;
|
|
|
|
case 'From search results':
|
2016-08-28 01:25:33 +02:00
|
|
|
$specific=$this->getInput('s');
|
2016-08-27 11:55:58 +02:00
|
|
|
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(){
|
2016-08-30 11:23:55 +02:00
|
|
|
$uri=self::URI;
|
2016-08-27 11:55:58 +02:00
|
|
|
switch($this->queriedContext){
|
|
|
|
case 'By username':
|
2016-08-28 13:38:01 +02:00
|
|
|
$uri.='user/'
|
2016-08-28 01:25:33 +02:00
|
|
|
.urlencode($this->getInput('u')).'/1';
|
2016-08-27 11:55:58 +02:00
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
2016-08-28 13:38:01 +02:00
|
|
|
$uri.='playlist/'
|
2016-08-28 01:25:33 +02:00
|
|
|
.urlencode(strtok($this->getInput('p'), '_'));
|
2016-08-27 11:55:58 +02:00
|
|
|
break;
|
|
|
|
case 'From search results':
|
2016-08-28 13:38:01 +02:00
|
|
|
$uri.='search/'
|
2016-08-28 01:25:33 +02:00
|
|
|
.urlencode($this->getInput('s'));
|
2016-08-28 13:38:01 +02:00
|
|
|
if($this->getInput('pa')){
|
2016-08-28 01:25:33 +02:00
|
|
|
$uri.='/'.$this->getInput('pa');
|
2016-08-27 11:55:58 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
}
|