getCleanedUrl(); // album // http://www.jamendo.com/fr/album/3409 $type = null; $ref_id = null; if (preg_match("#^\/[a-zA-Z0-9_-]+\/album\/([0-9]+)#", $url_clean, $chaines)) { $type = 'album'; $ref_id = $chaines[1]; } // track // http://www.jamendo.com/fr/track/894974 else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)#", $url_clean, $chaines)) { $type = 'track'; $ref_id = $chaines[1]; } // album new ver // http://www.jamendo.com/fr/list/a45666/proceed-positron... else if (preg_match("#^\/[a-zA-Z0-9_-]+\/list\/a([0-9]+)\/.#", $url_clean, $chaines)) { $type = 'album'; $ref_id = $chaines[1]; } // track new ver // http://www.jamendo.com/fr/track/347602/come-come else if (preg_match("#^\/[a-zA-Z0-9_-]+\/track\/([0-9]+)\/.#", $url_clean, $chaines)) { $type = 'track'; $ref_id = $chaines[1]; } $this->element->setData(Element::DATA_TYPE , $type); $this->element->setData(Element::DATA_REF_ID, $ref_id); } public function getStreamData() { // On determine le type et l'url $this->proceedTypeAndId(); $type = $this->element->getData(Element::DATA_TYPE); $ref_id = $this->element->getData(Element::DATA_REF_ID); // Récupération de données avec l'API $api_url = null; switch ($type) { case 'track': $api_url = "http://api.jamendo.com/get2/name+stream/track/json/?track_id=".$ref_id; break; case 'album': $api_url = "http://api.jamendo.com/get2/name+stream/track/json/?album_id=".$ref_id; break; } if ($api_url) { $ch = curl_init($api_url); $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: text/plain') ); curl_setopt_array( $ch, $options ); $result = json_decode(curl_exec($ch), true); if (count($result)) { $data_return = array(); foreach ($result as $song) { $data_return[] = array( 'name' => $song['name'], 'url' => $song['stream'], ); } return $data_return; } } } /** * ALBUM = http://www.jamendo.com/fr/album/30661 * TRACK = http://www.jamendo.com/fr/track/207079 * * API: http://developer.jamendo.com/fr/wiki/Musiclist2ApiFields */ public function retrieveDatas() { // On determine le type et l'url $this->proceedTypeAndId(); $type = $this->element->getData(Element::DATA_TYPE); $ref_id = $this->element->getData(Element::DATA_REF_ID); // Récupération de données avec l'API $api_url = null; switch ($type) { case 'album': $api_url = "http://api.jamendo.com/get2/" ."id+name+url+image+artist_name+artist_url/album/json/?album_id=".$ref_id; $api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/album_tag/?album_id=".$ref_id; break; case 'track': $api_url = "http://api.jamendo.com/get2/" ."id+name+url+image+artist_name+artist_url+track_name/album/json/?track_id=".$ref_id; $api_tag_url = "http://api.jamendo.com/get2/name+weight/tag/json/track_tag/?track_id=".$ref_id; break; } if ($api_url) { $ch = curl_init($api_url); $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: text/plain') ); curl_setopt_array( $ch, $options ); $result = json_decode(curl_exec($ch), true); if (count($result)) { // Thumb if (array_key_exists('image', $result[0])) { $this->element->setData(Element::DATA_THUMB_URL, $result[0]['image']); } // Album name if (array_key_exists('name', $result[0]) && $type == 'album') { $this->element->setData(Element::DATA_TITLE, $result[0]['name']); } // Artist name if (array_key_exists('artist_name', $result[0])) { $this->element->setData(Element::DATA_ARTIST, $result[0]['artist_name']); } // track name if (array_key_exists('track_name', $result[0]) && $type == 'track') { $this->element->setData(Element::DATA_TITLE, $result[0]['track_name']); } // Maintenant au tour des tags (deuxième requete a l'api) $ch = curl_init($api_tag_url); $options = array( CURLOPT_RETURNTRANSFER => true, CURLOPT_HTTPHEADER => array('Content-type: text/plain') ); curl_setopt_array( $ch, $options ); $result = json_decode(curl_exec($ch), true); if (count($result)) { $tags = array(); foreach ($result as $tag) { $tags[] = $tag['name']; } $this->element->setData(Element::DATA_TAGS, $tags); } } } // Un contenu jamendo est toujours téléchargeable $this->element->setData(Element::DATA_DOWNLOAD, true); } public function proceedEmbedCode() { if (($ref_id = $this->element->getData(Element::DATA_REF_ID)) && ($type = $this->element->getData(Element::DATA_TYPE))) { $height = $this->container->getParameter('jamendo_player_height'); $width = $this->container->getParameter('jamendo_player_width'); $embed_url = "http://widgets.jamendo.com/fr/$type/?".$type."_id=$ref_id&playertype=2008"; $this->element->setEmbed( '     ' ); } } public function proceedThumbnailUrl() { if (($thumb = $this->element->getData(Element::DATA_THUMB_URL))) { $this->element->setThumbnailUrl($thumb); } } }