Quantcast
Channel: Active questions tagged youtube-api - Stack Overflow
Viewing all articles
Browse latest Browse all 3831

advice needed Youtube api fetch thumbnail code. Is this Correct? [closed]

$
0
0

Code from purchased third party script. Trying to fetch youtube thumbnails through API but changing the fetch order by replacing "maxresdefault" to "standard" first for lower file size prioritizing. so far It works but im not sure if the code is structured correctly. Attached original code vs my edit. please advise

ORIGINAL CODE

try {            require 'assets/libs/youtube-sdk/vendor/autoload.php';            $youtube = new Madcoda\Youtube\Youtube(array('key' => $pt->config->yt_api));            $get_videos = $youtube->getVideoInfo($re_data['youtube']);            if (!empty($get_videos)) {                if (!empty($get_videos->snippet)) {                    if (!empty($get_videos->snippet->thumbnails->maxres->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->maxres->url;                    } else if (!empty($get_videos->snippet->thumbnails->standard->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->standard->url;                    } else if (!empty($get_videos->snippet->thumbnails->high->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->high->url;                    } else if (!empty($get_videos->snippet->thumbnails->medium->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->medium->url;                    }                    $info = $get_videos->snippet;                    $title = $info->title;                    if (!empty(covtime($get_videos->contentDetails->duration))) {                        $duration = covtime($get_videos->contentDetails->duration);                    }                    $description = $info->description;                    if (!empty($get_videos->snippet->tags)) {                        if (is_array($get_videos->snippet->tags)) {                            foreach ($get_videos->snippet->tags as $key => $tag) {                                $tags_array[] = $tag;                            }                            $tags = implode(',', $tags_array);                        }

MY EDIT

            $get_videos = $youtube->getVideoInfo($re_data['youtube']);            if (!empty($get_videos)) {                if (!empty($get_videos->snippet)) {                    if (!empty($get_videos->snippet->thumbnails->standard->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->standard->url;                    } else if (!empty($get_videos->snippet->thumbnails->maxres->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->maxres->url;                    } else if (!empty($get_videos->snippet->thumbnails->high->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->high->url;                    } else if (!empty($get_videos->snippet->thumbnails->medium->url)) {                        $thumbnail = $get_videos->snippet->thumbnails->medium->url;                    }                    $info = $get_videos->snippet;                    $title = $info->title;                    if (!empty(covtime($get_videos->contentDetails->duration))) {                        $duration = covtime($get_videos->contentDetails->duration);                    }                    $description = $info->description;                    if (!empty($get_videos->snippet->tags)) {                        if (is_array($get_videos->snippet->tags)) {                            foreach ($get_videos->snippet->tags as $key => $tag) {                                $tags_array[] = $tag;                            }                            $tags = implode(',', $tags_array);                        }

Viewing all articles
Browse latest Browse all 3831

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>