[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,8 +1,6 @@
|
|||
<?php
|
||||
class DailymotionBridge extends BridgeAbstract{
|
||||
|
||||
private $request;
|
||||
|
||||
public function loadMetadatas() {
|
||||
|
||||
$this->maintainer = "mitsukarenai";
|
||||
|
@ -11,13 +9,15 @@ class DailymotionBridge extends BridgeAbstract{
|
|||
$this->description = "Returns the 5 newest videos by username/playlist or search";
|
||||
|
||||
$this->parameters["By username"] = array(
|
||||
'u'=>array('name'=>'username')
|
||||
'u'=>array(
|
||||
'name'=>'username',
|
||||
'required'=>true
|
||||
)
|
||||
);
|
||||
|
||||
$this->parameters["By playlist id"] = array(
|
||||
'p'=>array(
|
||||
'name'=>'playlist id',
|
||||
'type'=>'text',
|
||||
'required'=>true
|
||||
)
|
||||
);
|
||||
|
@ -36,36 +36,22 @@ class DailymotionBridge extends BridgeAbstract{
|
|||
|
||||
function getMetadata($id) {
|
||||
$metadata=array();
|
||||
$html2 = $this->getSimpleHTMLDOM('http://www.dailymotion.com/video/'.$id) or $this->returnServerError('Could not request Dailymotion.');
|
||||
$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(){
|
||||
$param=$this->parameters[$this->queriedContext];
|
||||
$html = '';
|
||||
$limit = 5;
|
||||
$count = 0;
|
||||
|
||||
if (isset($param['u']['value'])) { // user timeline mode
|
||||
$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=...)');
|
||||
}
|
||||
$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) {
|
||||
|
@ -83,7 +69,42 @@ class DailymotionBridge extends BridgeAbstract{
|
|||
}
|
||||
|
||||
public function getName(){
|
||||
return (!empty($this->request) ? $this->request .' - ' : '') .'Dailymotion Bridge';
|
||||
$param=$this->parameters[$this->queriedContext];
|
||||
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;
|
||||
}
|
||||
|
||||
return $specific.' : Dailymotion Bridge';
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
public function getCacheDuration(){
|
||||
|
|
Loading…
Reference in a new issue