Rss-Bridge/bridges/SoundcloudBridge.php
teromene 2d526f4e0a Correction de quelques bugs dans les bridges, qui apparaissent à cause du fait qu'ils sont tous instanciés lors du chargement de tout les bridges.
Ré-ajout et ré-utilisation de getName et getURI, qui permettent d'avoir des élements dynamiques.
Changement en public de certaines valeurs.
Changement du nom de certaines constantes, déja utilisés.

Signed-off-by: teromene <teromene@teromene.fr>
2015-12-06 15:56:39 +01:00

56 lines
1.8 KiB
PHP

<?php
/**
* SoundcloudBridge
* Returns the newest music from user
*
* @name Soundcloud Bridge
* @homepage http://www.soundcloud.com/
* @description Returns 10 newest music from user profile
* @maintainer kranack
* @update 2015-09-08
* @use1(u="username")
*
*/
class SoundCloudBridge extends BridgeAbstract{
private $request;
public $name;
const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875';
public function collectData(array $param){
if (isset($param['u']) && !empty($param['u']))
{
$this->request = $param['u'];
$res = json_decode(file_get_contents('https://api.soundcloud.com/resolve?url=http://www.soundcloud.com/'. urlencode($this->request) .'&client_id=' . self::CLIENT_ID)) or $this->returnError('No results for this query', 404);
$tracks = json_decode(file_get_contents('https://api.soundcloud.com/users/'. urlencode($res->id) .'/tracks?client_id=' . self::CLIENT_ID)) or $this->returnError('No results for this user', 404);
}
else
{
$this->returnError('You must specify username', 400);
}
for ($i=0; $i < 10; $i++) {
$item = new \Item();
$item->name = $tracks[$i]->user->username .' - '. $tracks[$i]->title;
$item->title = $tracks[$i]->user->username .' - '. $tracks[$i]->title;
$item->content = '<audio src="'. $tracks[$i]->uri .'/stream?client_id='. self::CLIENT_ID .'">';
$item->id = 'https://soundcloud.com/'. urlencode($this->request) .'/'. urlencode($tracks[$i]->permalink);
$item->uri = 'https://soundcloud.com/'. urlencode($this->request) .'/'. urlencode($tracks[$i]->permalink);
$this->items[] = $item;
}
}
public function getName(){
return (!empty($this->name) ? $this->name .' - ' : '') .'Soundcloud Bridge';
}
public function getURI(){
return 'https://www.soundcloud.com/';
}
public function getCacheDuration(){
return 600; // 10 minutes
}
}