<?php 
    require_once( __DIR__ . '/include/incl.php' );
    if (!empty($_GET['video'])) {
    $id = htmlspecialchars($_GET['video']);
    $query = "https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&id=$id&key=$key";
    $video = json_decode(file_get_contents($query), 1);
    head($video['items'][0]['snippet']['title']);
?>
<div class="content-wrapper">
    <div class="container">
        <div class="row">
            <div class="col-lg-8 col-xs-12 col-sm-12">
                <div class="sv-video">
                    <?php 
                    $data = file_get_contents("https://www.youtube.com/get_video_info?video_id={$id}");

                    parse_str($data);

                    $exp = explode(',', $url_encoded_fmt_stream_map);

                    $player = parse_str($exp[0], $arr);

                    $channel_q = "https://www.googleapis.com/youtube/v3/channels?part=snippet%2CcontentDetails%2Cstatistics&id=".$video['items'][0]['snippet']['channelId']."&key=$key";
                    $channel = json_decode(file_get_contents($channel_q), 1);
                    ?>
                    <video poster="<?= $video['items'][0]['snippet']['thumbnails']['high']['url'] ?>" style="width:100%;height:100%;" controls="controls" width="100%" height="100%">
                        <source src="<?= $arr['url'] ?>" type='video/mp4; codecs="avc1.42E01E, mp4a.40.2"'></source>
                    </video>
                </div>
                <h1><a href="#"><?= $video['items'][0]['snippet']['title'] ?></a></h1>
                <div class="author">
                    <a href="/channel.php?c_id=<?= $channel['items'][0]['id'] ?>"><img src="<?= $channel['items'][0]['snippet']['thumbnails']['medium']['url'] ?>" alt="" class="sv-avatar"></a>
                    <div class="sv-name">
                        <div><a href="/channel.php?c_id=<?= $channel['items'][0]['id'] ?>"><?= $channel['items'][0]['snippet']['title'] ?></a> .</div>
                        <div class="c-sub">
                            <div class="c-f">
                                Фанатов
                            </div>
                            <div class="c-s">
                                <?= $channel['items'][0]['statistics']['subscriberCount'] ?>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>
                    <div class="sv-views">
                        <div class="sv-views-count">
                            <?= $video['items'][0]['statistics']['viewCount'] ?> Просмотров
                        </div>
                        <div class="sv-views-progress">
                            <div class="sv-views-progress-bar"></div>
                        </div>
                        <div class="sv-views-stats">
                            <span class="green"><span class="circle"></span> <?= $video['items'][0]['statistics']['likeCount'] ?></span>
                            <span class="grey"><span class="circle"></span> <?= $video['items'][0]['statistics']['dislikeCount'] ?></span>
                        </div>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="info">
                    <h4>Поделитесь в соц. сетях</h4>
                    <p>
                         <a target="_target" class="fb-share-button" href="https://vk.com/share.php?url=http://<?= $_SERVER['SERVER_NAME'] ?>/video.php?video=<?=$video['items'][0]['id']?>&title=<?= $sitename . " | " . $video['items'][0]['snippet']['title'] ?>&image=<?= $video['items'][0]['snippet']['thumbnails']['default']['url'] ?>"><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMgAAADICAMAAACahl6sAAAAYFBMVEVRgbj///+ivNmvxd5Ug7ldib3i6vPR3eyzyOBoksGduNf6/P2VstSowNxtlcOJqs/x9fl3nMfq8PZkj8C9z+TG1uh/osvt8veZtdbZ5PB5nsjT3+2BpMzK2Ond5vHB0uaKWUqIAAAIQ0lEQVR4nN2daaOqIBCGtcDjluZ2s8XO//+XVy2PGzNgIgbv5yyeZBmGmcGylylI70V+PPlh/Egiz/NoLWKtFGm+pf6yKHnEoX865sU9DRY2zBL9YFq5fpxka9ssriyJfbdKZYI4eZis/tc/FUnK3JEA4rgx3YuhF41dHgwKcj14eyP08g7Xz0Aux2jvtk8VHS+LQRx/t1GBiYRQF2ODOPHeLYYVs1FYIOfyK99GJ1KexUAqhYvFZ8oqAZAg3LuZIipnC/8UJE32bqOYkumSPwFxvr5bdcqeGMj1C1ZxUdErDOJoxFGTPCGQVJt+9VKWskECTcZ5ryRggmgx745VskCqvVv1iao5yFmzAfJSdp6BlHu36TP5UxDnq+1EWMSZgHyx3Y4rHoM4e7fnczkjEA2n3k7hEOSi6QhpRC4DkOPerVmj4wDk6/wlSxT1INe927JOzz8Qf++mrNPhD+SL/ImfyOtANF5EXnLeIO7eDVkr9w2irXnSKX6DaLVTZ4m+QJ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vnOt0JCKOcPAqn38cev861ELhwdDYPUeoqERapSdEAj71GQWo7LvyFoe9HY5aWR8kBamLxMdqOhSZmLlMoQAWmVVq4f39QtMSS7xb77I5y8JQzyB3Qtcvfkh/EjiTzPyyilq+c3Un9JVn9ZlDzi0D+5eXEVBuj0HzHaVJIDMCU3AAAAAElFTkSuQmCC" width="32" alt=""></a>
                        <div id="ok_shareWidget"></div>
                        <script>
                        !function (d, id, did, st, title, description, image) {
                          var js = d.createElement("script");
                          js.src = "https://connect.ok.ru/connect.js";
                          js.onload = js.onreadystatechange = function () {
                          if (!this.readyState || this.readyState == "loaded" || this.readyState == "complete") {
                            if (!this.executed) {
                              this.executed = true;
                              setTimeout(function () {
                                OK.CONNECT.insertShareWidget(id,did,st, title, description, image);
                              }, 0);
                            }
                          }};
                          d.documentElement.appendChild(js);
                        }(document,"ok_shareWidget",document.URL,'{"sz":30,"st":"oval","nc":1,"nt":1}',"<?= $video['items'][0]['snippet']['title'] ?>","<?= str_replace("\n", " ", $video['items'][0]['snippet']['description']) ?>...", "<?= $video['items'][0]['snippet']['thumbnails']['default']['url'] ?>");
                        </script>
                         <div class="fb-share-button" data-href="http://<?= $_SERVER['SERVER_NAME'] ?>/video.php?video=<?=$video['items'][0]['id']?>" data-layout="button" data-size="large" data-mobile-iframe="true"><a class="fb-xfbml-parse-ignore" target="_blank" href="https://www.facebook.com/sharer/sharer.php?u=http://<?= $_SERVER['SERVER_NAME'] ?>/video.php?video=<?=$videos['id']['videoId']?>&amp;src=sdkpreparse">Поделиться</a></div>
                    </p>
                    <h4>Описание :</h4>
                    <p>
                        <?php 
                            if (!empty($video['items'][0]['snippet']['localized']['description'])) {
                                echo urldecode(str_replace("\n", "<br />", $video['items'][0]['snippet']['description']));
                            }
                        ?> 
                    </p>
                        <h4><a href="#">Скачать:</a></h4>
                            <?php foreach ($exp as $src):
                                parse_str($src, $arr);
                                $title = rep($arr['itag']);
                            ?>
                                <a href="<?= $arr['url'] ?>" stlye="style:none" class="dow" download><?= $title ?></a> <br />
                            <?php endforeach; ?>
                    <hr>
                            <?php 
                                $qc = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=4&q=".urlencode($video['items'][0]['snippet']['title'])."&type=video&key=$key";
                                $items = json_decode(file_get_contents($qc), 1);
                                $tok = $items['nextPageToken'];
                            ?>
                    <div class="comments">
                        <div class="reply-comment">
                            <div class="rc-header"><i class="cv cvicon-cv-comment"></i>Коментарии</div>
                        </div>
                        <div class="comments-list">
                            <div id="disqus_thread"></div>
                            <script>

                            /**
                            *  RECOMMENDED CONFIGURATION VARIABLES: EDIT AND UNCOMMENT THE SECTION BELOW TO INSERT DYNAMIC VALUES FROM YOUR PLATFORM OR CMS.
                            *  LEARN WHY DEFINING THESE VARIABLES IS IMPORTANT: https://disqus.com/admin/universalcode/#configuration-variables*/
                            
                            var disqus_config = function () {
                            this.page.url = '<?= $_SERVER['HTTP_X_FORWARDED_PROTO'] . "://" . $_SERVER['HTTP_HOST'] . "/video.php?video=" . $id ?>';  // Replace PAGE_URL with your page's canonical URL variable
                            this.page.identifier = PAGE_IDENTIFIER; // Replace PAGE_IDENTIFIER with your page's unique identifier variable
                            };
                            
                            (function() { // DON'T EDIT BELOW THIS LINE
                            var d = document, s = d.createElement('script');
                            s.src = 'https://http-ataev-info.disqus.com/embed.js';
                            s.setAttribute('data-timestamp', +new Date());
                            (d.head || d.body).appendChild(s);
                            })();
                            </script>
                            <noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>
                        </div>
                    </div>
                </div>
            </div>

            <div class="col-lg-4 col-xs-12 col-sm-12">

                <div class="caption">
                    <div class="left">
                        <a href="#">Следуйшее</a>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list">
                            <?php 
                                $qd = "https://www.googleapis.com/youtube/v3/search?part=snippet&maxResults=4&q=".urlencode($video['items'][0]['snippet']['title'])."&type=video&key=$key&pageToken=$tok";
                                $next = json_decode(file_get_contents($qc), 1);
                                foreach ($next['items'] as $row):
                                if ($row['snippet']['title'] != $video['items'][0]['snippet']['title'] ) {

                            ?>
                    <div class="h-video row">
                        <div class="col-lg-6 col-sm-6">
                            <div class="v-img">
                                <a href="/video.php?video=<?= $row['id']['videoId'] ?>"><img width="170" title="<?= $row['snippet']['title'] ?>" src="<?= $row['snippet']['thumbnails']['medium']['url'] ?>" alt=""></a>
                            </div>
                        </div>
                        <div class="col-lg-6 col-sm-6">
                            <div class="v-desc">
                                <a href="/video.php?video=<?= $row['id']['videoId'] ?>" title="<?= $row['snippet']['title'] ?>"><?= mb_substr($row['snippet']['title'], 0, 44, 'utf-8') ?></a>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>

                        <?php
                        }
                        endforeach; ?>
                </div>

                <div class="adblock">
                    <img src="http://larinstore.ru/images/art/3.jpg" width="100%" alt="">
                </div>

                <div class="caption">
                    <div class="left">
                        <a href="#">Популярное</a>
                    </div>
                    <div class="clearfix"></div>
                </div>
                <div class="list">
                    <?php 
                        $query = "https://www.googleapis.com/youtube/v3/videos?part=snippet%2CcontentDetails%2Cstatistics&chart=mostPopular&maxResults=11&regionCode=RU&key=$key";
                        $videos = json_decode(file_get_contents($query), 1);
                        foreach ($videos['items'] as $video):
                    ?>
                    <div class="h-video row">
                        <div class="col-lg-6 col-sm-6">
                            <div class="v-img">
                                <a href="/video.php?video=<?= $video['id'] ?>" title="<?= $video['snippet']['title'] ?>"><img width="170px" src="<?= $video['snippet']['thumbnails']['medium']['url'] ?>" alt=""></a>
                            </div>
                        </div>
                        <div class="col-lg-6 col-sm-6">
                            <div class="v-desc">
                                <a href="/video.php?video=<?= $video['id'] ?>" title="<?= $video['snippet']['title'] ?>"><?= mb_substr($video['snippet']['title'], 0, 24, 'utf-8') ?></a>
                            </div>
                            <div class="v-views">
                                <?= $video['statistics']['viewCount'] ?> просмотров.
                            </div>
                        </div>
                        <div class="clearfix"></div>
                    </div>
                    <?php 
                    endforeach;
                    ?>
            </div>
        </div>
    </div>
</div>
<?php 
footer();
} else {
    echo "Отказано в доступе!";
}
?>