[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
|
<?php
|
||||||
class DailymotionBridge extends BridgeAbstract{
|
class DailymotionBridge extends BridgeAbstract{
|
||||||
|
|
||||||
private $request;
|
|
||||||
|
|
||||||
public function loadMetadatas() {
|
public function loadMetadatas() {
|
||||||
|
|
||||||
$this->maintainer = "mitsukarenai";
|
$this->maintainer = "mitsukarenai";
|
||||||
|
@ -11,13 +9,15 @@ class DailymotionBridge extends BridgeAbstract{
|
||||||
$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
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
@ -36,36 +36,22 @@ class DailymotionBridge extends BridgeAbstract{
|
||||||
|
|
||||||
function getMetadata($id) {
|
function getMetadata($id) {
|
||||||
$metadata=array();
|
$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['title'] = $html2->find('meta[property=og:title]', 0)->getAttribute('content');
|
||||||
$metadata['timestamp'] = strtotime($html2->find('meta[property=video:release_date]', 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['thumbnailUri'] = $html2->find('meta[property=og:image]', 0)->getAttribute('content');
|
||||||
$metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
|
$metadata['uri'] = $html2->find('meta[property=og:url]', 0)->getAttribute('content');
|
||||||
|
|
||||||
return $metadata;
|
return $metadata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function collectData(){
|
public function collectData(){
|
||||||
$param=$this->parameters[$this->queriedContext];
|
|
||||||
$html = '';
|
$html = '';
|
||||||
$limit = 5;
|
$limit = 5;
|
||||||
$count = 0;
|
$count = 0;
|
||||||
|
|
||||||
if (isset($param['u']['value'])) { // user timeline mode
|
$html = $this->getSimpleHTMLDOM($this->getURI())
|
||||||
$this->request = $param['u']['value'];
|
or $this->returnServerError('Could not request Dailymotion.');
|
||||||
$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) {
|
foreach($html->find('div.media a.preview_link') as $element) {
|
||||||
if($count < $limit) {
|
if($count < $limit) {
|
||||||
|
@ -83,7 +69,42 @@ class DailymotionBridge extends BridgeAbstract{
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getName(){
|
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(){
|
public function getCacheDuration(){
|
||||||
|
|
Loading…
Reference in a new issue