function youtube_automusic($listas, $api_key, $resultados){ $nresultados = $resultados; $lista_reproduccion_random = $listas; $lista_reproduccion = $lista_reproduccion_random[array_rand($lista_reproduccion_random)]; $url_playlist = "https://www.googleapis.com/youtube/v3/playlistItems?part=snippet&fields=items(snippet(resourceId(videoId)))&type=video&videoCategoryId=10&maxResults=".$nresultados."&playlistId=".$lista_reproduccion."&key=".$api_key; $data = dlPage($url_playlist); $data_decode = json_decode($data, true); $number_song = 1; $respuesta = array(); foreach ($data_decode as $items){ foreach ($items as $item){ $lista_ids =$item['snippet']['resourceId']['videoId']; $url_video = "https://www.googleapis.com/youtube/v3/videos?id=".$lista_ids."&part=snippet,contentDetails&fields=items(etag,id,snippet(publishedAt,title,thumbnails(default(url)),tags),contentDetails(duration))&key=".$api_key; $data_video = dlPage($url_video); $data_video_decode = json_decode($data_video, true); foreach ($data_video_decode as $items_videos){ foreach ($items_videos as $item_video){ $data_final = array( 'etag' => $item_video['etag'], 'idvideo' => $item_video['id'], 'titulovideo' => $item_video['snippet']['title'], 'thumbnail' => $item_video['snippet']['thumbnails']['default']['url'], 'duracion' => $item_video['contentDetails']['duration'], 'videoplay' => $number_song++ ); array_push($respuesta, $data_final); } } } } return json_encode($respuesta); }