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/';
|
|
|
|
const CACHE_TIMEOUT = 10800; // 3h
|
|
|
|
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',
|
|
|
|
'type' => 'number'
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
protected function getMetadata($id){
|
|
|
|
$metadata = array();
|
|
|
|
$html2 = getSimpleHTMLDOM(self::URI . 'video/' . $id);
|
2017-07-29 19:28:00 +02:00
|
|
|
if(!$html2) {
|
2017-02-11 16:16:56 +01:00
|
|
|
return $metadata;
|
|
|
|
}
|
2016-08-27 21:03:26 +02:00
|
|
|
|
2017-02-11 16:16:56 +01: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;
|
|
|
|
}
|
2015-11-05 16:50:18 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
public function collectData(){
|
|
|
|
$html = '';
|
|
|
|
$limit = 5;
|
|
|
|
$count = 0;
|
2016-08-28 13:38:01 +02:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
$html = getSimpleHTMLDOM($this->getURI())
|
|
|
|
or returnServerError('Could not request Dailymotion.');
|
2016-08-27 11:55:58 +02:00
|
|
|
|
2017-07-29 19:28:00 +02:00
|
|
|
foreach($html->find('div.media a.preview_link') as $element) {
|
|
|
|
if($count < $limit) {
|
2017-02-11 16:16:56 +01:00
|
|
|
$item = array();
|
|
|
|
$item['id'] = str_replace('/video/', '', strtok($element->href, '_'));
|
|
|
|
$metadata = $this->getMetadata($item['id']);
|
2017-07-29 19:28:00 +02:00
|
|
|
if(empty($metadata)) {
|
2017-02-11 16:16:56 +01:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$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="'
|
|
|
|
. $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;
|
|
|
|
$count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
|
2017-02-11 16:16:56 +01: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'), '_');
|
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$specific = $this->getInput('s');
|
|
|
|
break;
|
|
|
|
default: return parent::getName();
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
|
2017-02-11 16:16:56 +01:00
|
|
|
return $specific . ' : Dailymotion Bridge';
|
|
|
|
}
|
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':
|
|
|
|
$uri .= 'user/' . urlencode($this->getInput('u')) . '/1';
|
|
|
|
break;
|
|
|
|
case 'By playlist id':
|
|
|
|
$uri .= 'playlist/' . urlencode(strtok($this->getInput('p'), '_'));
|
|
|
|
break;
|
|
|
|
case 'From search results':
|
|
|
|
$uri .= 'search/' . urlencode($this->getInput('s'));
|
2017-07-29 19:28:00 +02:00
|
|
|
if($this->getInput('pa')) {
|
2017-02-11 16:16:56 +01:00
|
|
|
$uri .= '/' . $this->getInput('pa');
|
|
|
|
}
|
|
|
|
break;
|
2017-02-14 22:36:33 +01:00
|
|
|
default: return parent::getURI();
|
2017-02-11 16:16:56 +01:00
|
|
|
}
|
|
|
|
return $uri;
|
|
|
|
}
|
2014-11-18 20:02:04 +01:00
|
|
|
}
|