From ace3b9c7be4b0b5f035867d40fda0d0c86352518 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs?= Date: Thu, 23 May 2019 16:41:39 -0500 Subject: update regex and organize functions --- tools/init.php | 49 ++++++++++++++++++++++++++++++++++++++++++------- tools/processor.php | 33 +++++++++++++++------------------ 2 files changed, 57 insertions(+), 25 deletions(-) diff --git a/tools/init.php b/tools/init.php index 2627811..162350c 100644 --- a/tools/init.php +++ b/tools/init.php @@ -1,12 +1,37 @@ =1000) { + $c++; + $a = $a/1000; + } + return number_format($a,($c ? 2 : 0),",",".")." ".$unim[$c]; +} diff --git a/tools/processor.php b/tools/processor.php index 89a37f6..6c42399 100644 --- a/tools/processor.php +++ b/tools/processor.php @@ -7,17 +7,25 @@ if (empty($_GET['link'])){ $baselink = htmlspecialchars($_GET['link']); -$yturl = 'youtu.be/'; +$urlexists = url_exists( $baselink ); +if ($urlexists == true) { + + // Regex - filter URL id is match[5] + // Testing into → https://regexr.com/4ej96 + $rx = '/^((?:https?:)?\/\/)?((?:www|m)\.)?((?:youtube\.com|youtu.be|invidio\.us|invidiou\.sh|invidious\.snopyta\.org))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$/'; + preg_match($rx, $baselink, $match); + + // Testing if id → 11 characters + if (strlen($match[5]) < 12) { + $video_id = $match[5]; + } else { + header('Location: index.php'); + } -if (strpos($baselink,$yturl) !== false){ - $link = preg_replace('~^https?://youtu\.be/([a-z\d]+)$~i', 'https://www.youtube.com/watch?v=$1', $baselink); } else { - $link = $baselink; + header('Location: index.php'); } -parse_str($link, $urlData); -$video_id = array_values($urlData)[0]; - $video_string = file_get_contents("https://invidio.us/api/v1/videos/{$video_id}"); $video_info = json_decode($video_string); @@ -30,17 +38,6 @@ $videoChannel = $video_info->author; // Begin_ViewCount $extract_video_view = $video_info->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($extract_video_view); // End_ViewCount -- cgit v1.2.3