forked from blallo/rss-bridge
[DailymotionBridge] simplify code
Signed-off-by: Pierre Mazière <pierre.maziere@gmx.com>
This commit is contained in:
parent
0d36ca21df
commit
ed0fd12193
1 changed files with 88 additions and 67 deletions
|
@ -1,25 +1,25 @@
|
||||||
<?php
|
<?php
|
||||||
class DailymotionBridge extends BridgeAbstract{
|
class DailymotionBridge extends BridgeAbstract{
|
||||||
|
|
||||||
private $request;
|
|
||||||
|
|
||||||
public function loadMetadatas() {
|
public function loadMetadatas() {
|
||||||
|
|
||||||
$this->maintainer = "mitsukarenai";
|
$this->maintainer = "mitsukarenai";
|
||||||
$this->name = "Dailymotion Bridge";
|
$this->name = "Dailymotion Bridge";
|
||||||
$this->uri = "https://www.dailymotion.com/";
|
$this->uri = "https://www.dailymotion.com/";
|
||||||
$this->description = "Returns the 5 newest videos by username/playlist or search";
|
$this->description = "Returns the 5 newest videos by username/playlist or search";
|
||||||
|
|
||||||
$this->parameters["By username"] = array(
|
$this->parameters["By username"] = array(
|
||||||
'u'=>array('name'=>'username')
|
'u'=>array(
|
||||||
|
'name'=>'username',
|
||||||
|
'required'=>true
|
||||||
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->parameters["By playlist id"] = array(
|
$this->parameters["By playlist id"] = array(
|
||||||
'p'=>array(
|
'p'=>array(
|
||||||
'name'=>'playlist id',
|
'name'=>'playlist id',
|
||||||
'type'=>'text',
|
'required'=>true
|
||||||
'required'=>true
|
)
|
||||||
)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
$this->parameters["From search results"] = array(
|
$this->parameters["From search results"] = array(
|
||||||
|
@ -27,66 +27,87 @@ class DailymotionBridge extends BridgeAbstract{
|
||||||
'name'=>'Search keyword',
|
'name'=>'Search keyword',
|
||||||
'required'=>true
|
'required'=>true
|
||||||
),
|
),
|
||||||
'pa'=>array(
|
'pa'=>array(
|
||||||
'name'=>'Page',
|
'name'=>'Page',
|
||||||
'type'=>'number'
|
'type'=>'number'
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
|
||||||
|
|
||||||
function getMetadata($id) {
|
|
||||||
$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(){
|
function getMetadata($id) {
|
||||||
|
$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;
|
||||||
|
|
||||||
|
$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++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName(){
|
||||||
$param=$this->parameters[$this->queriedContext];
|
$param=$this->parameters[$this->queriedContext];
|
||||||
$html = '';
|
switch($this->queriedContext){
|
||||||
$limit = 5;
|
case 'By username':
|
||||||
$count = 0;
|
$specific=$param['u']['value'];
|
||||||
|
break;
|
||||||
|
case 'By playlist id':
|
||||||
|
$specific=strtok($param['p']['value'], '_');
|
||||||
|
break;
|
||||||
|
case 'From search results':
|
||||||
|
$specific=$param['s']['value'];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($param['u']['value'])) { // user timeline mode
|
return $specific.' : Dailymotion Bridge';
|
||||||
$this->request = $param['u']['value'];
|
}
|
||||||
$html = $this->getSimpleHTMLDOM('http://www.dailymotion.com/user/'.urlencode($this->request).'/1') or $this->returnServerError('Could not request Dailymotion.');
|
|
||||||
}
|
|
||||||
else if (isset($param['p']['value'])) { // playlist mode
|
|
||||||
$this->request = strtok($param['p']['value'], '_');
|
|
||||||
$html = $this->getSimpleHTMLDOM('http://www.dailymotion.com/playlist/'.urlencode($this->request).'') or $this->returnServerError('Could not request Dailymotion.');
|
|
||||||
}
|
|
||||||
else if (isset($param['s']['value'])) { // search mode
|
|
||||||
$this->request = $param['s']['value']; $page = 1; if (isset($param['pa']['value'])) $page = (int)preg_replace("/[^0-9]/",'', $param['pa']['value']);
|
|
||||||
$html = $this->getSimpleHTMLDOM('http://www.dailymotion.com/search/'.urlencode($this->request).'/'.$page.'') or $this->returnServerError('Could not request Dailymotion.');
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$this->returnClientError('You must either specify a Dailymotion username (?u=...) or a playlist id (?p=...) or search (?s=...)');
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach($html->find('div.media a.preview_link') as $element) {
|
public function getURI(){
|
||||||
if($count < $limit) {
|
$param=$this->parameters[$this->queriedContext];
|
||||||
$item = array();
|
switch($this->queriedContext){
|
||||||
$item['id'] = str_replace('/video/', '', strtok($element->href, '_'));
|
case 'By username':
|
||||||
$metadata = $this->getMetadata($item['id']);
|
$uri='http://www.dailymotion.com/user/'
|
||||||
$item['uri'] = $metadata['uri'];
|
.urlencode($param['u']['value']).'/1';
|
||||||
$item['title'] = $metadata['title'];
|
break;
|
||||||
$item['timestamp'] = $metadata['timestamp'];
|
case 'By playlist id':
|
||||||
$item['content'] = '<a href="' . $item['uri'] . '"><img src="' . $metadata['thumbnailUri'] . '" /></a><br><a href="' . $item['uri'] . '">' . $item['title'] . '</a>';
|
$uri='http://www.dailymotion.com/playlist/'
|
||||||
$this->items[] = $item;
|
.urlencode(strtok($param['p']['value'], '_'));
|
||||||
$count++;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
public function getName(){
|
public function getCacheDuration(){
|
||||||
return (!empty($this->request) ? $this->request .' - ' : '') .'Dailymotion Bridge';
|
return 3600*3; // 3 hours
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getCacheDuration(){
|
|
||||||
return 3600*3; // 3 hours
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue