diff options
author | Jesús <heckyel@hyperbola.info> | 2018-11-17 21:20:43 -0500 |
---|---|---|
committer | Jesús <heckyel@hyperbola.info> | 2018-11-17 21:20:43 -0500 |
commit | b56cfda34ffc4b3bc4beb291291584ad9bda7e3f (patch) | |
tree | 4da4196eb4eba4f586d146a2b12943ad76c88f85 | |
parent | c6c72ca42c197f0567ae4470d4b3592b5760650a (diff) | |
download | ytlibre-b56cfda34ffc4b3bc4beb291291584ad9bda7e3f.tar.lz ytlibre-b56cfda34ffc4b3bc4beb291291584ad9bda7e3f.tar.xz ytlibre-b56cfda34ffc4b3bc4beb291291584ad9bda7e3f.zip |
Added viewcount
-rw-r--r-- | index.php | 1 | ||||
-rw-r--r-- | templates/video.tpl | 2 | ||||
-rw-r--r-- | tools/processor.php | 27 |
3 files changed, 25 insertions, 5 deletions
@@ -27,6 +27,7 @@ if (empty($_GET['link'])){ $video_decode->assign("videoAuthor", $videoAuthor); $video_decode->assign("videoChannel", $videoChannel); $video_decode->assign("videoDuration", $videoDuration); + $video_decode->assign("videoViews", $videoViews); $video_decode->assign("librethumb", $librethumb); $video_decode->assign("cStreams", $cStreams); diff --git a/templates/video.tpl b/templates/video.tpl index f2527f1..4a2a2d1 100644 --- a/templates/video.tpl +++ b/templates/video.tpl @@ -65,6 +65,8 @@ <h6><a class="enlace" href="https://invidio.us/channel/{$videoChannel}" rel="noopener noreferrer" target="_blank">{$videoAuthor}</a></h6> <h6 class="yt-titulo">Duración</h6> <h6>{$videoDuration}</h6> + <h6 class="yt-titulo">Vistas</h6> + <h6>{$videoViews}</h6> </div> </div> </div> diff --git a/tools/processor.php b/tools/processor.php index 80461ba..f4e6d2b 100644 --- a/tools/processor.php +++ b/tools/processor.php @@ -16,9 +16,9 @@ if (strpos($baselink,$yturl) !== false){ } parse_str($link, $urlData); -$my_id = array_values($urlData)[0]; +$video_id = array_values($urlData)[0]; -$videoFetchURL = file_get_contents('https://www.youtube.com/get_video_info?html5=1&video_id='.$my_id); +$videoFetchURL = file_get_contents("https://www.youtube.com/get_video_info?html5=1&video_id={$video_id}"); parse_str($videoFetchURL, $video_info); $video_info = json_decode(json_encode($video_info)); @@ -29,12 +29,29 @@ $videoTitle = $video_info->title; $videoAuthor = $video_info->author; $videoDurationSecs = $video_info->length_seconds; $videoDuration = secToDuration($videoDurationSecs); -//$videoViews = $video_info->view_count; $videoChannel = $video_info->ucid; +// Begin_ViewCount +$api_key = 'AIzaSyB9TLn5HvT614SjzBv8ZOj3wL2tc7PM3M4'; // API KEY only view_count +$data_all = json_decode(file_get_contents("https://www.googleapis.com/youtube/v3/videos?part=snippet,contentDetails,statistics&id={$video_id}&key={$api_key}")); +$video_view = $data_all->items[0]->statistics->viewCount; + +function bytes($a) { + $unim = array("","K","M","G","T","P"); + $c = 0; + while ($a>=1000) { + $c++; + $a = $a/1000; + } + return number_format($a,($c ? 2 : 0),",",".")." ".$unim[$c]; +} + +$videoViews = bytes($video_view); +// End_ViewCount + //change hqdefault.jpg to default.jpg for downgrading the thumbnail quality -$videoThumbURL = "https://i1.ytimg.com/vi/{$my_id}/hqdefault.jpg"; -$librethumb = "https://i1.ytimg.com/vi/{$my_id}/maxresdefault.jpg"; +$videoThumbURL = "https://i1.ytimg.com/vi/{$video_id}/hqdefault.jpg"; +$librethumb = "https://i1.ytimg.com/vi/{$video_id}/maxresdefault.jpg"; if (!isset($video_info->url_encoded_fmt_stream_map)) { die('No data found'); |