PHP Classes

File: YTAPI.php

Recommend this page to a friend!
  Classes of James Weisbrod   YTAPI   YTAPI.php   Download  
File: YTAPI.php
Role: Application script
Content type: text/plain
Description: Youtube API script
Class: YTAPI
Generate PHP scripts to browse YouTube videos
Author: By
Last change:
Date: 2 years ago
Size: 33,019 bytes
 

Contents

Class file image Download
<?php # AVC - ARTISTS - VIDEOS - COMMENTS - jamesweisbrod40@gmail.com - Born Baby Boy Liparttiti! # SHUFFLE TAG QUERY ON DATE TIME # TO DO : QUOTA EXCEEDED WARNING ON STATS PAGE # MISSING KEY WARNING TOO # # QUERY YOUTUBE DIRECTORS # QUERY YOUTUBE COMMENTS # PARSE # DB DUMP # # - artists - list - videos - comments # # MAKE DATABASE DUMP AND CREATE DATABASE INSTALLERS # QUERY DB # PARSE # FRONT PAGE # DIRECTORY # # SO. HOW DO I FIND THE CATEGORIES FOR THE CHANNELS? AND COLOUMNIZE THEM? ini_set('memory_limit', '256M'); set_time_limit(2000); ignore_user_abort(true); set_time_limit(0); header('Connection: Keep-Alive, Persist'); header('Keep-Alive: timeout=600, max=1400'); header('Content-Type: text/html; charset=UTF-8'); header("Cache-Control: no-cache, must-revalidate"); $TIME = time(); $PAGE_TITLE = ''; $CORE_NICHE_WORD = ""; $MINIMUM_COMMENTS = 50; $MINIMUM_VIDEOS = 8; $EMAIL = ''; $VERBOSE = (isset($_GET['v']))? 1: 0; $CRONLOG = (isset($_GET['c']))? 1: 0; $DOMAIN = ''; $dbuser = ""; $dbpass = ""; $dbname = ""; $dbhost = "localhost"; # EARLIER PHPS COMPILE FUNCTIONS ON FIRST INTERPRETER PASS $DBCINSERT = DB($dbhost,$dbuser,$dbpass,$dbname); $DBCSELECT = DB($dbhost,$dbuser,$dbpass,$dbname); $DBCDELETE = DB($dbhost,$dbuser,$dbpass,$dbname); $APIKEY = ""; # YOUTUBE $MR = array(50,0,50,0,50); $alphaBET = array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $ALPHAbet = array("-"); ############################################################################################# ####################### FUNCTION LIBRARY - REUSABLE CODES ################################### ############################################################################################# function J($url){$F = @file_get_contents($url);$J = json_decode($F,true);return array($J,$F);} function J2($url){ usleep(250000); // quarter second pause to lower throttling potential $file = @file_get_contents($url);$J = json_decode($file,true);$J = $J['items'];return $J;} function prr($a,$s='',$V=1){if(!$V){return;}print('<H3>'.$s.'</h3><pre>');print_r($a);print('</pre>');} function a($a,$b=null,$c=null,$d=null,$e=null){return array($a,$b,$c,$d,$e);} function fileSafeName($w){ // NEEDS LATIN AND CHINESE WHITELIST RATHER THAN BLACKLIST $a = array("/",".","[","]","#","`","}","*"); $w = trim($w);foreach($a as $b => $c){$w = str_replace($c," ",$w);} return str_replace(" ","-",strtolower($w));} function screenSafeText($w,$alphaBET,$ALPHAbet){ # returns text safe for html output from DB $x=strlen($w); $str=""; for($z=0;$z<$x;$z++){ $l=$w[$z]; if(in_array($l,$alphaBET) || in_array($l,$ALPHAbet)){$str.=$l;} } return $str; } function TC($time){ $time = trim($time,"Z"); $ex = explode("T",$time);$ex2 = explode("-",$ex[0]);$ex3 = explode(".",$ex[1]);$ex3 = explode(":",$ex3[0]); return mktime($ex3[0],$ex3[1],$ex3[2],$ex2[1],$ex2[2],$ex2[0]);} function DB($H,$U,$P,$N){ $L = mysqli_connect($H,$U,$P,$N); mysqli_options($L,MYSQLI_OPT_CONNECT_TIMEOUT,60); if(!$L){prr("NO CONNECTION");exit;}return $L;} // videoCreated viewCount likeCount dislikeCount favoriteCount commentCount function sortWordSectionBy($a,$b,$c){return ($a[$c] > $b[$c])? -1 : 1;} function D($A){ $D = array(); foreach($A as $x => $y){ $q = count($y);for($z = 1; $z < $q; $z++){ $v = $y[0][$y[$z][0]]; if($y[$z][1] == 'TC'){$v = TC($v);} $D[$y[$z][0]] = $v; }} return $D;} function ARRAYSTACK($A,$P){return $A[$P];} function getVMAP($A,$DBM,$DBP){ $VMAP = array();foreach($DBM[0] as $a => $b){if(!$a){continue;}$VMAP[$b[0]] = $b;} foreach($A as $B => $C){$G = array(); foreach($VMAP as $D => $E){ if(!isset($A[$B])){ prr($b,"THROWING ERROR HERE ADD MAIL TO.... !isset(".$a."[".$C."])"); prr($VMAP,"ERROR THROWN VMAP");return array();}}} return $VMAP; } function stackJSON($A,$DBM,$DBP){ # A IS A FLAT STACK 0 THROUGH 50 COMMENT ARRAY WITH NESTED ELEMENTS # prr($A[0],"A");prr($DBM,"COMDBMAP");prr($DBP,"COMDPATHS");prr($VMAP,"VMAP"); $P = array();foreach($DBP as $B => $C){$P[$B] = explode('.',$C);} # PATH $LINEAR_STACK = array(); # prr($P,"FULL P STACK PATHS"); foreach($A as $B => $C){ // COMDBMAP $B = (varKey), $C = (ARR/OBJ) $D = array();$K = $P; foreach($K as $G => $H){ # prr($C,"C ARR OBJ BEFORE STACK KEY"); $D[$G] = $C;foreach($H as $E => $F){$D[$G] = @ARRAYSTACK($D[$G],$F);} # prr($D,"D ARR OBJ AFTER STACK KEY"); } # INSERT NEW VALUES INTO STACK... $I = array();$I = $D['PCR'];unset($K['PCR']); foreach($K as $X => $Y){$I[$X] = $D[$X];} $LINEAR_STACK[$B] = $I; } # prr($LINEAR_STACK,"LINEAR STACK");prr($VMAP,"STACK COMMENTS COMDBMAP");exit; return $LINEAR_STACK;} function validateLINEARSTACK($LINEAR_STACK,$VMAP){ # prr($LINEAR_STACK,"LINEAR STACK"); foreach($LINEAR_STACK as $C => $D){ # prr($D,"D LINEAR STACK"); $LINEAR_STACK[$C] = array(); foreach($D as $F => $H){ $G = array(); foreach($VMAP as $A => $B){ if($F !== $A){continue;} if(($B[1] == 'C' || $B[1] == 'VC')){ $G = substr(strip_tags($H),0,$B[2]); }elseif($B[1] == 'TC'){ $G = TC($H); }elseif($B[1] == 'I' && is_numeric($B[2])){ $G = $H; }else{ continue; } $LINEAR_STACK[$C][$F] = $G; } } } return $LINEAR_STACK; } function qCol($DB,$COL,$TBL,$VERBOSE){ $S = "SELECT `".$COL."` FROM `".$TBL."` WHERE 1 LIMIT 1"; $Q = mysqli_real_query($DB,$S); prr($S,"QCOL Q=(".$Q.")",$VERBOSE); return ($Q)? 1: 0; } function cCol($DB,$COL,$TBL,$VERBOSE){ $S = "ALTER TABLE `".$TBL."` ADD `".$COL."` INT(2) UNSIGNED DEFAULT NULL;"; $Q = mysqli_real_query($DB,$S) or die(mysqli_error($DB)."<h1>".$S."</h1>"); prr($S,"CCOL Q=(".$Q.")",$VERBOSE); return ($Q)? 1: 0; } function CTQ($t,$C){ $s = "CREATE TABLE IF NOT EXISTS `".$t."`"."\n (";$PKS = "";$KS = ""; foreach($C as $a => $b){ foreach($b as $c => $d){ if(!isset($d[0])){continue;} $NN = (isset($d[3]) && $d[3] == 'NN')? " NOT NULL": " NULL"; $AI = (isset($d[3]) && $d[3] == 'PK')? " AUTO_INCREMENT": ""; $PKS .= (isset($d[3]) && $d[3] == 'PK')? " PRIMARY KEY (`".$d[0]."`),": ""; $KS .= (isset($d[3]) && $d[3] == 'IND')? " KEY `".$d[0]."` (`".$d[0]."`),": ""; if($d[1] == 'VC'){$s .= "`".$d[0]."` VARCHAR(".$d[2].") COLLATE utf8_unicode_ci ".$NN.",\n"; }elseif($d[1] == 'C'){$s .= "`".$d[0]."` CHAR(".$d[2].") COLLATE utf8_unicode_ci ".$NN.",\n"; }elseif($d[1] == 'TC'){$s .= "`".$d[0]."` INTEGER(10) UNSIGNED".$NN.$AI.",\n"; }elseif($d[1] == 'UI'){$s .= "`".$d[0]."` INTEGER(".$d[2].") UNSIGNED".$NN.$AI.",\n";} }} return substr($s,0,-1).substr($PKS,0,-1).") ENGINE=MyISAM AUTO_INCREMENT=0 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;";} function arrDump($arrDUMP,$DB){ foreach($arrDUMP as $a => $b){ if(empty($b)){continue;} $qStr = "INSERT INTO `".$a."` "; $varA = array(); $vals = ""; $vars = ""; foreach($b as $c => $d){ $vals .= " ("; foreach($d as $e => $f){ $varA[$e] = 1; if($f === NULL){ $vals .= "NULL,"; }else{ $vals .= "'".mysqli_real_escape_string($DB,$f)."',"; } } $vals = substr($vals,0,-1); $vals .= "),"; } foreach($varA as $c => $d){ $vars .= "`".$c."`,"; } $vars = substr($vars,0,-1); $vals = substr($vals,0,-1); $qStr .= " (" . $vars . ") VALUES " . $vals ." ON DUPLICATE KEY UPDATE "; foreach($varA as $c => $d){ $qStr .= " ".$c." = VALUES(".$c."),"; } $qStr = substr($qStr,0,-1); return $qStr; } } function getArtistKeys($A){ $E=array();foreach($A as $B => $C){$D = $C['snippet']['channelId'];$E[]['id'] = $D;} $F = array(); $F['artists'] = $E;return $F;} function getVideoKeys($A){ $E=array();foreach($A as $B => $C){$D = $C['id'];$E[]['id'] = $D;} $F = array(); $F['videos'] = $E;return $F;} function getListKeys($A){ $E=array();foreach($A as $B => $C){$D = $C['contentDetails']['videoId']; $E[$D] = $D;}return $E;} function getCommentKeys($A){ $E=array();foreach($A as $B => $C){$D = $C['snippet']['topLevelComment']['id']; $E[$D] = $D;}return $E;} function qDB($DB,$TBL){ $qStr = "SELECT `id` FROM `".$TBL."` WHERE `publishedAt` IS NULL"; $q = mysqli_query($DB,$qStr); return mysqli_fetch_row($q); } ############################################################################################# ####################### HTML PROCESSING AND CACHING OUTPUT ################################## ############################################################################################# function qDBALLFP($DB,$TBL,$COMMENTS_LEFT_JOIN=0,$VERBOSE=0){ $qStr = "SELECT * FROM `".$TBL."` WHERE `publishedAt` IS NOT NULL"; $q = mysqli_query($DB,$qStr); $ARR = array(); $COMMENTS_ID = array(); while($row = mysqli_fetch_assoc($q)){ $id = $row['id']; $ARR[$id] = $row; $COMMENTS_ID[$id] = true; } # SOME TIMES JOINS ARE SLOW SO, COUNT / QUERIES AND STACK if(!$COMMENTS_LEFT_JOIN){ prr(count($COMMENTS_ID)," COMMENTS_IDS COUNT",$VERBOSE); $m = 10; $c = count($COMMENTS_ID); $cycles = ceil($c/$m); for($y=0;$y<$cycles;$y++){ $qStr = "SELECT `id`,`videoId`,`textDisplay`,`authorDisplayName` ,`authorChannelId`,`publishedAt` FROM `comments` WHERE "; for($x = 0;$x<$m;$x++){ $A = key($COMMENTS_ID);$qStr .= "`authorChannelId` = '".$A."' OR ";next($COMMENTS_ID); } $qStr = substr($qStr,0,-3); prr($qStr," COMMENT QUERY ",$VERBOSE); $q = mysqli_query($DB,$qStr) or die(mysqli_error($DB)); while($row = mysqli_fetch_assoc($q)){ $id = $row['id']; $authorChannelId = $row['authorChannelId']; $ARR[$authorChannelId]['comments'][] = $row; } } } return $ARR; } function printHTML($HTML,$I,$PAGE_TITLE){ return '<!DOCTYPE html> <html lang="en"> <html> <head> <meta charset="utf-8"/> <title>'.$PAGE_TITLE.'</title> <style type="text/css"> body{margin:0;padding:0;} #dC1{padding:10px 7px 20px 5px;} #dC2{padding:10px 6px 20px 5px;} #dC3{padding:10px 0px 20px 7px;} #TitleBar{background:#000;color:#fff;display:block;overflow:hidden;width:100%;} #TitleBar h1{color:#fff;font-size:16px;float:left;} #tCol1{padding:0px;margin:0px;width:325px;overflow:hidden;float:left;} #tCol2{padding:0px;margin:0px;width:325px;overflow:hidden;float:left;font-size:1px;text-align:center;line-height:3;} #tCol3{padding:0px;margin:0px;width:325px;overflow:hidden;float:left;} #tCol3{width:auto;float:right;} #topColR{float:left;text-align:left;color:#FFF;display:block;height:18px;width:40px;overflow:hidden;border:1px solid #fff;display:none;} #hAC1{float:left;display:block;width:23px;padding:2px 4px 0px 4px;} #hAC1 img{border:none;} #h1C1{color:#fff;margin:2px 0px 0px 0px;padding:2px 0px 0px 8px;display:block;float:left;} #imgBar1{float:right;padding:0px;} #imgBar2{float:right;padding:0px;} #TitleBar .tCon{background:#111;} .tCon{max-width:1005px;margin:auto;} .tCon{clear:both;max-width:1005px;margin:auto;} .crumbTrail{clear:both;color:#fff;margin:2px 0px 0px 3px;} .crumbTrail a{color:#fff;} .dC{padding:0% 0% 0% 0%;clear:left;max-width:1005px;margin:auto;} .dCL{float:left;width:325px;margin:0%;font-size:x-small;overflow:hidden;} </style> </head> <body> '.$HTML[$I].' </body> </html>'; } function printHtmlHEADER(){ return '<div id="TitleBar"> <div class="tCon"> <div id="tCol1"> <a id="hAC1" title="ASMR Studio" href="http://www.asmrstudio.com/"><img src="images/asmr.png" alt="ASMR Studio" width="23"></a> <h1 id="h1C1"><a title="ASMR STUDIO" href="http://www.asmrstudio.com/">ASMR STUDIO</a> : Autonomous</h1> <div class="crumbTrail"></div> </div> <div id="tCol2"><div style="color:#000;">.</div></div> <div id="tCol3"> <div id="topColR"> <div style="font-weight:900;font-size:16px;">&#9711;</div> <div style="font-weight:100;font-size:20px;">&#9651;</div> <div style="font-weight:900;font-size:18px;">&#9633;</div> <div style="font-weight:900;font-size:16px;">&#9747;</div> </div> <span id="imgBar2"><img alt="comet" id="img2" src="/favicon-32x32.png" height="32" /></span> <span id="imgBar1"><img alt="3star" id="img1" src="/3latint.png" width="60" /></span> </div> </div> </div>'; } function printHTMLS($htmls){ return '<div class="dC"> <div class="dCL" id="dC1">'.$htmls[0].'</div> <div class="dCL" id="dC2">'.$htmls[1].'</div> <div class="dCL" id="dC3">'.$htmls[2].'</div> </div>'; } ############################################################################################# ####################### DATA MAPS OBJECT MAPS AND DATA ###################################### ############################################################################################# # ADDS # $B = explode(",","UCr6vWe5goPw6-4YknmrZioQ,UCDtAY4AB4OgAZh9Sxovx2lA,UCp5oSl262QFMOsjKj_kYILA, UCd0niLuvSNQnyOMlVuG-XyA,UC4eO8gplCQQqD8yvuey1TxQ,UCgh1498DodqqKvZ-FO5bRFg, UCoviXqo4b1MAAkjRWEPJrBg,UCExp9y-lrASQjmSfr5Uz8qQ"); # 24 TAGS 1 EVERY HOUR # $M = explode(",","HUMMING,NURSE,EAR,EATING,SUESS,ENGLISH WHISPERING,SPACE,NOODLES,WEREWOLF,WATER,MONSTER,ECHO,BINAURAL,MELTING,JOI,SCINTILLATING,MUKBANG,EXPERIMENT"); # GOOGLE YOUTUBE API CALLS # $vURL = "https://www.googleapis.com/youtube/v3/"; // urlencode($b['q']) $URLA = array( "search?part=snippet&order=date&maxResults=".$MR[0]."&key=".$APIKEY."&q=", "channels?part=snippet,contentDetails,statistics&key=".$APIKEY."&id=", "playlistItems?part=contentDetails&key=".$APIKEY."&maxResults=".$MR[2]."&playlistId=", "videos?part=snippet,statistics,status&key=".$APIKEY."&id=", "commentThreads?part=snippet&key=".$APIKEY."&maxResults=".$MR[4]."&videoId="); # DATABASE STRUCTURES $DBP[1] = array('PCR' => 'snippet', 'url' => 'snippet.thumbnails.default.url', 'viewCount' => 'statistics.viewCount', 'subscriberCount' => 'statistics.subscriberCount', 'videoCount' => 'statistics.videoCount', 'uploads' => 'contentDetails.relatedPlaylists.uploads', 'id' => 'id'); $DBP[2] = array('PCR' => 'contentDetails', 'id' => 'contentDetails.videoId', 'publishedAt' => 'contentDetails.videoPublishedAt'); $DBP[3] = array('PCR' => 'snippet', 'id' => 'id', 'url' => 'snippet.thumbnails.default.url', 'privacyStatus' => 'status.privacyStatus', 'embeddable' => 'status.embeddable', 'viewCount' => 'statistics.viewCount', 'likeCount' => 'statistics.likeCount', 'dislikeCount' => 'statistics.dislikeCount', 'favoriteCount' => 'statistics.favoriteCount', 'commentCount' => 'statistics.commentCount'); $DBP[4] = array('PCR' => 'snippet.topLevelComment.snippet', 'authorChannelId' => 'snippet.topLevelComment.snippet.authorChannelId.value', 'id' => 'snippet.topLevelComment.id'); $DBM[0] = array(); $DBM[1] = array( # CHANNELS 0 => array(array(),a('id','C','24','PK'),a('title','VC','128','NN'),a('description','VC','256'),a('uploads','C','24'),a('url','VC','128','IURL'),a('viewCount','UI','11'),a('subscriberCount','UI','11'),a('videoCount','UI','11'),a('publishedAt','TC'),a('coreCommentCount','UI','11'),a('coreVideoCount','UI','11'))); $DBM[2] = array( # VIDEOS? 0 => array(array(),a('id','C','11','NN','PK'),a('publishedAt','TC'))); $DBM[3] = array( # VIDEOS 0 => array(array(),a('id','C','24','PK'),a('title','VC','128','NN'),a('description','VC','256'),a('channelId','C','24','IND'),a('url','VC','128','IURL'),a('viewCount','UI','24'),a('likeCount','UI','11'),a('dislikeCount','UI','11'),a('favoriteCount','UI','11'),a('commentCount','UI','11'),a('publishedAt','TC'))); $DBM[4] = array( # COMMENTS 0 => array(array(),a('id','C','26','PK'),a('videoId','C','11','NN','IND'),a('channelId','C','24','NN','IND'),a('textDisplay','VC','256'),a('authorDisplayName','VC','128'),a('authorProfileImageUrl','VC','128','IURL'),a('authorChannelId','C','24'),a('publishedAt','TC'),a('updatedAt','TC'))); if($CRONLOG){file_put_contents('cronlog.txt',$TIME.' START '."\n",FILE_APPEND); }elseif(!$VERBOSE){header("HTTP/1.0 404 Not Found");exit;} # CRON MUST BE SET TO RUN ONCE EVERY FIVE MINUTES / 24 HOURS / 12 intervals per hour # 12 per hour x 2 x 12 hours # $COUNT = count($M); if($COUNT > 128){echo "<h1>TAGS EXCEED THE CRON INTERVALS</h1>";} prr($M,"LISTING SEARCH TAG CATEGORIES COUNT(".$COUNT.")",$VERBOSE=0); // 19 $TIME_ZONE = -5; $H = intval($TIME_ZONE) + intval(date("H",$TIME)) - 1; $H = ($H > $COUNT)? $H - $COUNT: $H; $SEARCH_TAG = urlencode($M[$H]." ".$CORE_NICHE_WORD); prr(array($SEARCH_TAG)," SEARCH TAGS ", $VERBOSE=1); ############################################################################################# ####################### FILESYSTEM AND DATABASE INITIALIZATION ############################## ############################################################################################# $i = (1)? 1: 0;$w = ""; if($i){ $a = array('asmrtists/*','icons/*');$w .= ($i)? "(ON)": "(OFF)";$w .= "<h1>FILE RESET ".$w."</h1>"; foreach($a as $e => $d){ $f = glob($d); foreach($f as $n){ if(!(is_file($n) && $n != 'asmrtists/index' && $n != '.htaccess')){continue;} unlink($n);$w .= "<br>FILE UNLINKED: (".$n.")</br>"; } }if($VERBOSE){print($w);} } # IMAGE FOLDER $IMAGE_PROCESSING = '<?php $i=$_GET["i"];$i=trim($i,"/"); if(file_exists($i)){readfile($i); }elseif(strlen($i) > 1){ $img=file_get_contents("https://yt3.ggpht.com/ytc/".$i); file_put_contents("./1".$i,$img);$t = @exif_imagetype("./1".$img); if($t==2){$img = imagecreatefromjpeg("./1".$i); }elseif($t==1){$img = imagecreatefromgif("./1".$i); }elseif($t==3){$img = imagecreatefrompng("./1".$i); }else{readfile("1default-user");exit;} $img = imagescale($img,80);imagejpeg($img,$i);imagedestroy($img); } ?>'; $IMAGE_HTACCESS = "<Files>ForceType jpeg/jpg</Files>"; $HTML_HTACCESS = "<Files>ForceType html/htm</Files>"; if(!is_dir('./img')){mkdir('./img',0755);}chmod('./img',0755); if(!is_dir('./artists')){mkdir('./artists',0755);}chmod('./artists',0755); file_put_contents("./img/index.php",$IMAGE_PROCESSING); file_put_contents("./img/.htaccess",$IMAGE_HTACCESS); file_put_contents("./artists/.htaccess",$HTML_HTACCESS,LOCK_EX); if(1==2){ # RUN PRIMARY KEY CHECK # }elseif(1==2){ # CHECK EVERY SINGLE COLUMN # foreach($DBM[1] as $A => $B){if(!$B){continue;} foreach($B as $C => $D){if(!isset($D[0])){continue;} $TBL = 'artists'; $QCOL = qCol($DBCINSERT,$D[0],$TBL,$VERBOSE); if(!$QCOL){ prr("QCOL = (".$QCOL.") CREATING COLOUMB `".$TBL."` ".$D[0]); cCol($DBCINSERT,$D[0],$TBL,$VERBOSE); } } } } $CTQ = CTQ('artists',$DBM[1]); prr($CTQ,"DATABASE INSTALL ARTISTS",$VERBOSE); mysqli_real_query($DBCINSERT,$CTQ) or die(mysqli_error($DBCINSERT)); $CTQ = CTQ('videos',$DBM[3]); prr($CTQ,"DATABASE INSTALL VIDEOS",$VERBOSE); mysqli_real_query($DBCINSERT,$CTQ) or die(mysqli_error($DBCINSERT)); $CTQ = CTQ('comments',$DBM[4]); prr($CTQ,"DATABASE INSTALL COMMENTS",$VERBOSE); mysqli_real_query($DBCINSERT,$CTQ) or die(mysqli_error($DBCINSERT)); ############################################################################################# ####################### RUNTIME LINEAR PROCEDURAL DATA PROCESSING ########################### ############################################################################################# # DO WHILES AND ERROR HANDLING. THESE CHUNKS OBJECTIVE IS TO RETURN A CODE FOR FURTHER USE # THEY NEED TO LOOP # QUERY API FOR NEW CHANNELS IF NONE IN QUE # THIS IS A SEARCH BY TAG QUERY SO I NEED TO DIVIDE THE CALL ACROSS A CRON $qDB = qDB($DBCSELECT,'artists'); if(!(strlen($qDB[0]) == 24)){ # DO SEARCH AND RETURN CHANNEL KEYS # LIMIT TO ONE CHANNEL AT A TIME $url = $vURL.$URLA[0].$SEARCH_TAG;prr(array(),'QUERY YOUTUBE API : '.$url,$VERBOSE); $J2 = J2($url);if(empty($J2)){prr($J2,'EMPTY JSON ARTIST (404?) : '.$url,$VERBOSE);} # prr($J,"API SEARCH - url(".$url.")"); $ARTIST_KEYS = getArtistKeys($J2);prr($ARTIST_KEYS,"ARTIST KEYS ARRAY",$VERBOSE); $AK[0] = $ARTIST_KEYS['artists'][0]['id']; $arrDUMP = arrDump($ARTIST_KEYS,$DBCINSERT);prr($arrDUMP,"ARTIST KEY INSERT 3",$VERBOSE); mysqli_real_query($DBCINSERT,$arrDUMP) or die(mysqli_error($DBCINSERT)); } $CHANNELKEY = (strlen($qDB[0]) == 24)? $qDB[0]: $AK[0]; # prr($qDB,"QBC SELECT RESULT"); # PROCESS ONE CHANNEL $url = $vURL.$URLA[1].$CHANNELKEY;prr(array(),'QUERY YOUTUBE API : '.$url,$VERBOSE); $J = J($url); $I0 = (isset($J[0]['items']))? $J[0]['items'][0]: array(); if(empty($I0) && isset($J[0]['pageInfo']['totalResults']) && $J[0]['pageInfo']['totalResults'] == 0){ prr($J[0],'EMPTY CHANNEL (404?)',$VERBOSE); $CK = mysqli_real_escape_string($DBCDELETE,$CHANNELKEY); $qStr = 'DELETE FROM `artists` WHERE `id` = "'.$CK.'"'; mysqli_query($DBCDELETE,$qStr) or die(mysqli_error($DBCDELETE)); $qStr = 'DELETE FROM `videos` WHERE `channelId` = "'.$CK.'"'; mysqli_query($DBCDELETE,$qStr) or die(mysqli_error($DBCDELETE)); $qStr = 'DELETE FROM `comments` WHERE `authorChannelId` = "'.$CK.'"'; mysqli_query($DBCDELETE,$qStr) or die(mysqli_error($DBCDELETE)); }elseif(empty($I0)){ mail($EMAIL,"UNEXPECTED ERROR 1",json_encode($J)); // MAYBE CONSIDER ERASING THIS ONE???? }elseif(!empty($I0)){ // channel has results to process prr($I0,"API CHANNEL - url(".$url.")"); #$VIDEO_KEYS = getVideoKeys(array($I0));#prr($VIDEO_KEYS,"VIDEO KEYS ARRAY"); #$arrDUMP = arrDump($VIDEO_KEYS,$DBCINSERT);prr($arrDUMP,"ARTIST KEY INSERT 1",$VERBOSE); #mysqli_real_query($DBCINSERT,$arrDUMP) or die(mysqli_error($DBCINSERT)); $VMAP = @getVMAP(array($I0),$DBM[1],$DBP[1]);#prr($VMAP,"VIDEO VMAP"); $LINEAR_STACK = stackJSON(array($I0),$DBM[1],$DBP[1]); # prr($LINEAR_STACK,"LINEAR_STACK"); $VLS = validateLINEARSTACK($LINEAR_STACK,$VMAP);prr($VLS,"LINEAR_STACK (VALIDATED)",$VERBOSE); $A = array(); $A['artists'] = $VLS; $arrDUMP = arrDump($A,$DBCINSERT);prr($arrDUMP,"VALIDATED ARTIST KEY INSERT 2",$VERBOSE); mysqli_real_query($DBCINSERT,$arrDUMP) or die(mysqli_error($DBCINSERT)); # LIST ALL VIDEOS FOR A CHANNEL $url = $vURL.$URLA[2].$VLS[0]['uploads']; $J2 = J2($url);if(empty($J2)){prr($J2,'EMPTY JSON UPLOADS (404?) : '.$url);}#prr($J2,"API LISTS - (".$url.")"); $VMAP = @getVMAP($J2,$DBM[2],$DBP[2]);#prr($VMAP,"COMMENT VMAP"); $LINEAR_STACK = stackJSON($J2,$DBM[2],$DBP[2]);#prr($LINEAR_STACK,"LINEAR_STACK"); $VLS = validateLINEARSTACK($LINEAR_STACK,$VMAP);#prr($VLS,"STACK (VALIDATED)"); $A = array(); $A['videos'] = $VLS; $arrDUMP = arrDump($A,$DBCINSERT);#prr($arrDUMP,"VALIDATED SINGLE VIDEO KEY INSERT"); mysqli_real_query($DBCINSERT,$arrDUMP) or die(mysqli_error($DBCINSERT)); $LIST_KEYS = getListKeys($J2);#prr($LIST_KEYS,"LIST KEYS RESULT FROM GET VIDEO KEYS",$VERBOSE); prr($LIST_KEYS," COUNT VIDEO LISTS ",$VERBOSE); $x=0; # VIDEO CALL AND PROCESS ALL VIDEOS IN LIST foreach($LIST_KEYS as $A => $B){ $videoId = trim($A); if(strlen($videoId) != 11){prr($LIST_KEYS,"LIST KEYS",$VERBOSE);continue;} $url = $vURL.$URLA[3].$videoId; $J2 = J2($url);if(empty($J2)){prr($J2,'EMPTY JSON (404?) VIDEO : '.$url);} #prr($J2,"API VIDEO (".$url.")"); $VMAP = @getVMAP($J2,$DBM[3],$DBP[3]);#prr($VMAP,"VIDEO VMAP"); $LINEAR_STACK = stackJSON($J2,$DBM[3],$DBP[3]);#prr($LINEAR_STACK,"LINEAR_STACK"); $VLS = validateLINEARSTACK($LINEAR_STACK,$VMAP);#prr($VLS,"STACK (VALIDATED)"); $A = array(); $A['videos'] = $VLS; $arrDUMP = arrDump($A,$DBCINSERT);#prr($arrDUMP,"VALIDATED VIDEOS KEY INSERT"); mysqli_real_query($DBCINSERT,$arrDUMP) or die(mysqli_error($DBCINSERT)); # COMMENTS CALL # GET ALL COMMENTS OR FIRST PAGE COMMENTS OR TOP COMMENTS # MAYBE 10 $url = $vURL.$URLA[4].$videoId;#prr($url,"GOOGLE YOUTUBE COMMENTS CALL"); $J2 = J2($url); if(empty($J2)){ prr($J2,'EMPTY JSON ON COMMENTS (404?) : '.$url,$VERBOSE); }else{ # prr($J2,"API COM (".$url.")"); $COMMENT_KEYS = @getCommentKeys($J2); $VMAP = @getVMAP($J2,$DBM[4],$DBP[4]);#prr($VMAP,"COMMENT VMAP"); $LS = stackJSON($J2,$DBM[4],$DBP[4]);prr($LS[key($LS)],"COM QUERY COUNT(".count($LS).")",$VERBOSE); #prr($LS," LINEAR STACK ",$VERBOSE); foreach($LS as $A => $B){ $LS[$A]['channelId'] = $CHANNELKEY; } $VLS = validateLINEARSTACK($LS,$VMAP);#prr($VLS,"LS (VALIDATED)"); $A = array(); $A['comments'] = $VLS; $arrDUMP = arrDump($A,$DBCINSERT);#prr($arrDUMP,"VALIDATED COMMENTS KEY INSERT"); mysqli_real_query($DBCINSERT,$arrDUMP) or die(mysqli_error($DBCINSERT)); } $x++;if($x > $MINIMUM_VIDEOS){break;} } } # THIS IS REFERENCING CROSS POSTS! IT HAS NOTHING TO DO WITH THE CORRECT COMMENT COUNT # 2 Second Query at least prr(array($TIME-time()),'STARTING STATISTICS QUERY',$VERBOSE); $qStr = "UPDATE `artists` SET `coreVideoCount` = (SELECT count(*) FROM `videos` WHERE `videos`.`channelId` = `artists`.`id`)"; mysqli_real_query($DBCINSERT,$qStr) or die(mysqli_error($DBCINSERT)); prr(array($TIME-time()),'VIDEO TALLY QUERY FINISHED',$VERBOSE); $qStr = "UPDATE `artists` SET `coreCommentCount` = (SELECT count(*) FROM `comments` WHERE `comments`.`channelId` = `artists`.`id`)"; mysqli_real_query($DBCINSERT,$qStr) or die(mysqli_error($DBCINSERT)); prr(array($TIME-time()),'COMMENT TALLY QUERY FINISHED',$VERBOSE); # STATS PAGES FOR VIDEOS WITH PAGINATION ASMR'TISTS DIRECTORY # #################################################################################################### ############## # ARTIST INDIVIDUAL PAGES WITH COMMENTS #################################################################################################### # DETERMINE MINIMUM REQUIREMENT FOR FRONT PAGE AND DIRECTORY STATS # MUST HAVE AT LEAST 25 COMMENTS # MUST HAVE AT LEAST 5 VIDEOS $CORE_NICHE_WORD; $MINIMUM_COMMENTS; $MINIMUM_VIDEOS; $qDB = qDBALLFP($DBCSELECT,'artists',0,$VERBOSE=0); prr($qDB[key($qDB)],"SELECT ALL ARTISTS",$VERBOSE=1); # compile the queries to select the videos and the comments for those videos. # FOR EACH CYCLE MAKE ARTIST PAGES # $I = 0; $HTML = array(); foreach($qDB as $a => $b){ $HTML[$a] = '<h1>'.screenSafeText($b['title'],$alphaBET,$ALPHAbet).'</h1>'; $HTML[$a] .= '<p>'.$b['description'].'</p>'; $HTML[$a] .= '<p>Published At:'.date('H:i:s Y/M/D',$b['publishedAt']).'</p>'; $c1 = (isset($b['viewCount']))? $b['viewCount']: null; $c2 = (isset($b['subscriberCount']))? $b['subscriberCount']: null; $c3 = (isset($b['videoCount']))? $b['videoCount']: null; $HTML[$a] .= (is_numeric($c1))? '<p>View Count:'.$c1.'</p>' : ''; $HTML[$a] .= (is_numeric($c2))? '<p>Subscriber Count:'.$c2.'</p>' : ''; $HTML[$a] .= (is_numeric($c3))? '<p>Video Count:'.$c3.'</p>' : ''; if(!isset($b['comments'])){continue;} foreach($b['comments'] as $c => $d){ # prr(array(),"PRINTING COMMENTS NO.(".$c.")"); $COMMENT = '<div style="overflow:hidden;border:1px solid #000;"> <div style="float:right;font-size:x-small;">'.date('M Y',$d['publishedAt']).'</div> <div style="float:left;font-size:x-small;">'.$d['authorDisplayName'].'</div> <div style="clear:both;font-size:normal;">'.$d['textDisplay'].'</div> </div>'; $HTML[$a] .= $COMMENT; } } $c=count($qDB);$x=0;$htmls=array("","",""); foreach($qDB as $a => $b){ $HTML[$a] = printHtmlHEADER() . $HTML[$a]; $HTML[$a] = printHTML($HTML,$a,$PAGE_TITLE); $path = "./artists/".fileSafeName($b['title']); file_put_contents($path,$HTML[$a]); } #################################################################################################### # FRONT PAGE # A COLOUM FOR THE "TRIGGERS AND CATEGORIES" # THE MOST POPULAR OVERALL CURRENT VIDEO # #################################################################################################### $c=count($qDB);$x=0;$htmls=array("","",""); foreach($qDB as $a => $b){ $ex = explode("=",$b['url']); $ex = explode("/",$ex[0]); $c3 = (isset($b['videoCount']))? $b['videoCount']: null; $htmls[$x] .= '<div style="clear:both;cursor:default;overflow:hidden;padding:0px 0px 10px 0px;">'; $htmls[$x] .= '<h1 style="padding:0;margin:0;">'.$b['title'].'</h1>'; $imgSRC = (isset($ex[4]))? "index.php?i=".$ex[4]: '1default-user'; $href = "http://".$DOMAIN."/artists/".fileSafeName($b['title']); $htmls[$x] .= '<div style="float:left;width:40px;margin:0px 4px 4px 0px;overflow:hidden;">'; $htmls[$x] .= '<a href="'.$href.'"><img width="40" src="/img/'.$imgSRC.'"></a>'; $htmls[$x] .= '</div>'; $htmls[$x] .= '<div>Since:('.date('M Y',$b['publishedAt']).')'; $htmls[$x] .= (is_numeric($c3))? 'Video Count:'.$c3 : ''; $htmls[$x] .= '</div>'; $htmls[$x] .= '<div style="">'.$b['description'].'</div>'; $htmls[$x] .= '</div>'; $x++;if($x>2){$x=0;} } $I = 0; $HTML = array(); $HTML[$I] = printHtmlHEADER(); $HTML[$I] .= printHTMLS($htmls,$I); $HTML[$I] = printHTML($HTML,$I,$PAGE_TITLE); $HTML[1] = 'DirectoryIndex index.html'; $PATHS = array( 0 => './artists/index.html', 1 => './artists/.htaccess'); foreach($HTML as $A => $B){ file_put_contents($PATHS[$A],$HTML[$A]); print($HTML[$A]); } mysqli_close($DBCSELECT); mysqli_close($DBCINSERT); mysqli_close($DBCDELETE); if($CRONLOG){ $str = "<pre>SCRIPT SINISHED RUNNING ".$TIME." ON SERVER ".json_encode($_SERVER)."</pre>"; mail($EMAIL,"SCRIPT SINISHED",$str); } ?>