2014-07-24 13:51:42 +02:00
< ? php
/**
* SoundcloudBridge
* Returns the newest music from user
*
* @ name Soundcloud Bridge
* @ homepage http :// www . soundcloud . com /
2015-09-09 00:13:56 +02:00
* @ description Returns 10 newest music from user profile
2014-07-24 13:51:42 +02:00
* @ maintainer kranack
2015-09-09 00:13:56 +02:00
* @ update 2015 - 09 - 08
2014-07-24 13:51:42 +02:00
* @ use1 ( u = " username " )
*
*/
class SoundCloudBridge extends BridgeAbstract {
2015-09-09 00:13:56 +02:00
2014-07-24 13:51:42 +02:00
private $request ;
2015-11-04 00:05:10 +01:00
public $name ;
2015-11-05 16:50:18 +01:00
public function loadMetadatas () {
$this -> maintainer = " kranack " ;
$this -> name = " Soundcloud Bridge " ;
$this -> uri = " http://www.soundcloud.com/ " ;
$this -> description = " Returns 10 newest music from user profile " ;
$this -> update = " 2015-09-08 " ;
$this -> parameters [] =
' [
{
" name " : " username " ,
" identifier " : " u "
}
] ' ;
}
const CLIENT_ID = '0aca19eae3843844e4053c6d8fdb7875' ;
2015-09-09 00:13:56 +02:00
2014-07-24 13:51:42 +02:00
public function collectData ( array $param ){
2015-09-09 00:13:56 +02:00
2014-07-24 13:51:42 +02:00
if ( isset ( $param [ 'u' ]) && ! empty ( $param [ 'u' ]))
{
$this -> request = $param [ 'u' ];
2015-09-09 00:13:56 +02:00
$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 );
}
2014-07-24 13:51:42 +02:00
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 ;
2015-09-09 00:13:56 +02:00
$item -> content = '<audio src="' . $tracks [ $i ] -> uri . '/stream?client_id=' . self :: CLIENT_ID . '">' ;
2014-07-24 13:51:42 +02:00
$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 ;
}
2015-09-09 00:13:56 +02:00
2014-07-24 13:51:42 +02:00
}
public function getName (){
return ( ! empty ( $this -> name ) ? $this -> name . ' - ' : '' ) . 'Soundcloud Bridge' ;
}
public function getURI (){
2015-09-09 00:13:56 +02:00
return 'https://www.soundcloud.com/' ;
2014-07-24 13:51:42 +02:00
}
public function getCacheDuration (){
2015-09-10 00:00:29 +02:00
return 600 ; // 10 minutes
2014-07-24 13:51:42 +02:00
}
}