$topViewVideoId = array('topViewVideoId' => '', 'viewCount' => 0, 'title' => '');
    for ($i = 0, $count = count($videoStatistic); $i < $count; $i++) {
        $sum += $videoStatistic[$i]['viewCount'];
        if ($videoStatistic[$i]['viewCount'] > $topViewVideoId['viewCount']) {
            $topViewVideoId['viewCount'] = $videoStatistic[$i]['viewCount'];
            $topViewVideoId['topViewVideoId'] = $videoStatistic[$i]['videoId'];
            $topViewVideoId['title'] = $videoStatistic[$i]['title'];
        }
    }
    array_push($videoFinalStat, array('totalView' => $sum, 'topVideoId' => $topViewVideoId['topViewVideoId'], 'title' => $topViewVideoId['title']));
    echo json_encode($videoFinalStat);
}
try {
    $videosIds = array();
    $videos = array();
    $artists = $model->selectEverythingFromArtists();
    for ($i = 0, $count = count($artists); $i < $count; $i++) {
        $searchResponse = $youtube->search->listSearch('snippet,id', array('type' => 'video', 'q' => $artists[$i]['name'], 'maxResults' => '5'));
        for ($j = 0, $count2 = count($searchResponse); $j < $count2; $j++) {
            array_push($videos, array('videoId' => $searchResponse['items'][$j]['id']['videoId'], 'title' => $searchResponse['items'][$j]['snippet']['title'], 'artistId' => $artists[$i]['id']));
            $videosIds[] = $searchResponse['items'][$j]['id']['videoId'];
        }
    }
} catch (Google_Service_Exception $e) {
    $htmlBody .= sprintf('<p>A service error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
} catch (Google_Exception $e) {
    $htmlBody .= sprintf('<p>An client error occurred: <code>%s</code></p>', htmlspecialchars($e->getMessage()));
}
?>