Exemplo n.º 1
0
 public function getListSongs($search)
 {
     $data = array('q' => $search, 'limit' => "20");
     $url = "http://api.deezer.com/search/track";
     $deezerResults = json_decode($this->curl->curl_get($url, $data), true);
     foreach ($deezerResults['data'] as $subarray) {
         $song = new Song();
         $song->setTitle($subarray['title_short'])->setReference($subarray['id'])->setProvider('deezer')->setArtist($subarray['artist']['name'])->setDuration($subarray['duration'])->setAlbumCover($subarray['album']['cover_small'])->setPreview($subarray['preview']);
         $listSongs[] = $song;
     }
     return $listSongs;
 }
Exemplo n.º 2
0
 public function getListSongs($search)
 {
     $youtubeResults = $this->getResponse($search, 'search');
     foreach ($youtubeResults['items'] as $subarray) {
         $youtubeResult = $this->getResponse($subarray['id']['videoId'], 'video');
         //pour obtenir la durée de la vidéo on exécute une requête sur les détails de la vidéo référencée par la videoId
         $duration = new \DateInterval($youtubeResult['items'][0]['contentDetails']['duration']);
         if ((int) $duration->format('%h') < 1 && (int) $duration->format('%d') < 1) {
             $duration = ((int) $duration->format('%h') * 3600 + (int) $duration->format('%i')) * 60 + (int) $duration->format('%s');
             //on récupère la durée en secondes
             $song = new Song();
             $song->setTitle($subarray['snippet']['title'])->setReference($subarray['id']['videoId'])->setProvider('youtube')->setAlbumCover($subarray['snippet']['thumbnails']['default']['url'])->setPreview('https://www.youtube.com/watch?v=' . $subarray['id']['videoId'])->setDuration($duration);
             $listSongs[] = $song;
             //return $listSongs;
         }
     }
     return $listSongs;
 }
Exemplo n.º 3
0
 public function getListSongs($search)
 {
     $data = array('q' => $search, 'limit' => "20", 'client_id' => '209c8985680f7b729bc8100f80e223bc');
     $url = "http://api.soundcloud.com/search";
     $soundcloudResults = json_decode($this->curl->curl_get($url, $data), true);
     foreach ($soundcloudResults['collection'] as $subarray) {
         $song = new Song();
         if ($subarray['kind'] === 'track' && preg_match('#-#', $subarray['title'])) {
             $titleArtist = explode("-", $subarray['title']);
             $song->setTitle($titleArtist[1])->setReference($subarray['id'])->setProvider('soundcloud')->setArtist($titleArtist[0])->setDuration($subarray['duration'] / 1000);
             empty($subarray['artwork_url']) ? $song->setAlbumCover($subarray['user']['avatar_url']) : $song->setAlbumCover($subarray['artwork_url']);
             $subarray['streamable'] == true ? $song->setPreview($subarray['stream_url'] . '?client_id=209c8985680f7b729bc8100f80e223bc') : $song->setPreview(null);
             /*if($subarray['streamable'] == true)
                 $song->setPreview($subarray['stream_url'].'?client_id=209c8985680f7b729bc8100f80e223bc');
               */
             $listSongs[] = $song;
         }
     }
     return $listSongs;
 }