aboutsummaryrefslogtreecommitdiffstats
path: root/tools/processor.php
diff options
context:
space:
mode:
Diffstat (limited to 'tools/processor.php')
-rw-r--r--tools/processor.php33
1 files changed, 15 insertions, 18 deletions
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