PHP Script for Extending Vbtube: Mass Deletion and Correction Utility
I have written this PHP script as an extension to the Vbtube script. If you don’t have Vbtube installed, this script won’t be useful unless you want to learn how I code (which might not be the best idea).
This script is useful for mass deletion of invalid YouTube links, saving you time and avoiding the manual hassle. Additionally, it can correct the title of any videos that did not have the correct title when retrieved. Alternatively, you can even correct the path of broken links and images by using action=3
. I still use this script on my personal site, and it saves me a lot of time and effort.
Please note that usage is explained in the source code, and it is crucial to read it carefully before using actions 2 and 3.
The code:
Download zip
PHP
<?php
#!!!!!***************!!!!!!!!!******************!!!!!!!!!!!!**********!
#Please read before making use of this code!
#Disclaimer: This is illegal if executed on real victims and could land you in prison for sure.
#This is intended for educational purposes only. We take no responsibility at all for your actions.
#This code is provided by EEEDS Eagle Eye Digital Security (Oman) for education purpose only.
#For more educational source codes please visit us https://www.digi77.com
#Author of this code W. Al Maawali Founder of Eagle Eye Digital Solutions and om77.net can be reached via warith@digi77.com .
#Sharing knowledge is not about giving people something, or getting something from them.
#That is only valid for information sharing.
#Sharing knowledge occurs when people are genuinely interested in helping one another develop new capacities for action;
#it is about creating learning processes.
#Peter Senge
#!!!!!***************!!!!!!!!!******************!!!!!!!!!!!!**********!
// This script is an extension to the vbtube script--> http://www.vbtube.com/ if you don't have vbtube then it wont be
// useful unless you want to learn how I code which is a bad idea :p
// You can use this to mass delete invalid tubes I wrote this to save me the headache of fetching and deleting
// one by one which took me ages to complete.It can also correct the title of any tubes that did not have the correct title while retrieved.
// Or even correct the path of broken links if action=3 is used
// usage to delete all invalid tubes use this : http://www.yoursite.com/vbtube_delete.php?action=0 or
// http://www.yoursite.com/vbtube_delete.php
// usage to correct invalid titles of the tubes use this : http://www.yoursite.com/vbtube_delete.php?action=1
// usage to correct invalid links of the tubes use this : http://www.yoursite.com/vbtube_delete.php?action=2
// I normally run it in ssh Linux by typing $php vbtube_delete.php then I sit back and watch :p
require_once('./global.php');
//variables to change
$mysiteadress="http://www.oman0.net/media/"; //set this to you site path do not forget the slash / at the end
$youtubethumbsig="da39a3ee5e6b4b0d3255bfef95601890afd80709"; //$sha1.$md5 of youtube non available tube thumb
//on youtube do not change this at all unless u are sure thnumbail has changed on youtube
// example of non valid thumbnail on youtube is here https://img.youtube.com/vi/sdldjfsdkssskdjksd/default.jpg
//get action value
$action =$_REQUEST['action'];
//check if var is passed or not
if (!isset($action)) {
$action =0;
}
else
{
//clean the Integer
$action=(filter_var($action, FILTER_SANITIZE_NUMBER_INT));
}
//For Sql query variable use
function mysqlCleaner($data)
{
$data= mysql_real_escape_string($data);
$data= stripslashes($data);
return $data;
}
if ($action==0)
{
echo "Processing";
$counter =0;
$query4 = "Select * from vbtube_tubes where tubeid > 0";
$query4= mysqlCleaner($query4);
$result4 = mysql_query($query4);
while ($row4 = mysql_fetch_row($result4))
{
$imagevarpath2="<br ?--><a target="blank" rel="noopener"><img src="$row4[12]" alt="\"$row4[6]\"" width="80" height="60/"></a><br>";
//echo "before " . $imagevarpath2;
$filename=$row4[12];
$sha1 = @sha1(file_get_contents($filename));
$md5 = @md5_file($filename);
$sign = $sha1.$md5;
//echo "<br>da39a3ee5e6b4b0d3255bfef95601890afd80709";
//echo "<br>sha1 and md5 code of tube thumbnail: " . $sign;
if ($sign==$youtubethumbsig)
{
//echo $imagevarpath2;
echo $filename;
$insert7="delete from vbtube_tubes WHERE tubeid =$row4[0]";
$insert7= mysqlCleaner($insert7);
mysql_query($insert7);
echo "<br><span style="color: red;"><b>Tube " . $row4[0] . " Deleted</b></span>";
//sleep(10); use it if you run the srcipt from your web browser commented to run in ssh php script-name.php
}else
{
echo ".";
$counter=$counter+1;
if ($counter % 300 == 0)
{
echo $counter . '<br>';
}
}//
flush();
}
//delete non active tubes do it after aproving all tubes
$query5 = "Select * from vbtube_tubes where active=0";
$query5= mysqlCleaner($query5);
$result5 = mysql_query($query5);
while ($row5 = mysql_fetch_row($result5))
{
//delete non active tubes
$insert5="delete from vbtube_tubes WHERE tubeid =$row5[0]";
$insert5= mysqlCleaner($insert5);
mysql_query($insert5);
echo "<br>In active Tube " . $row5[0] . " Deleted<br>";
$imagevarpath2="<a target="blank" rel="noopener"><img src="$row5[12]" alt="\"$row5[6]\"" width="80" height="60/"></a> $row5[0]";
echo $imagevarpath2;
flush();
}
echo '<br> Deleting dead thumbs + none active tubes done :)';
}
else if ($action==1) //get missing and corrupted titles replace them with valid once from youtube
{
// utf to uni code not uses we use iconv instead
function charset_decode_utf_8 ($string)
{
/* Only do the slow convert if there are 8-bit characters */
/* avoid using 0xA0 (\240) in ereg ranges. RH73 does not like that */
if (! ereg("[\200-\237]", $string) and ! ereg("[\241-\377]", $string))
return $string;
// decode three byte unicode characters
$string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e",
"'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",
$string);
// decode two byte unicode characters
$string = preg_replace("/([\300-\337])([\200-\277])/e",
"'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",
$string);
return $string;
} //end function
//remove bad charectors
function mysql_escape_mimic($inp)
{
if(is_array($inp))
return array_map(__METHOD__, $inp);
if(!empty($inp) && is_string($inp)) {
return str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $inp);
}
return $inp;
}
$query6 = 'select * from vbtube_tubes where title=" " ORDER BY tubeid'; // where tubeid=9848 where title=" " ORDER BY tubeid where title=" " ORDER BY tubeid Limit 5
$query6 = mysqlCleaner($query6 );
$result6 = mysql_query($query6);
while ($row6 = mysql_fetch_row($result6))
{
//if($row6[0]=="9740")
//{
//echo "is utf " . $row6[6];
$m= explode("v=", $row6[11]);
$video_id = "http://gdata.youtube.com/feeds/api/videos/" .$m[1];
$content = file_get_contents($video_id);
//echo $content ." <br>";
if(!$content)
{
echo "Dead vid " . $row6[0] . " " . $video_id ." <br>";
}
else
{
$string2 = explode("", $string2[1]);
$string3[0] =iconv("UTF8", "windows-1256//TRANSLIT", $string3[0]);
//$string3[0]=charset_decode_utf_8($string3[0]);
//$string3[0]=decode_utf8($string3[0]);
//echo "New title found " . $string3[0] . "<br>";
//echo "escaped title = " . addslashes($string3[0]) ;
$title=addslashes($string3[0]);
if ($title)
{
$insert7="update vbtube_tubes set title=\"$title\" where tubeid =$row6[0]";
$insert7= mysqlCleaner($insert7);
mysql_query($insert7);
echo "Tube uid " .$m[1] . " Tube id " . $row6[0] . " Old title =" . $row6[6] . " New title " . $title . "<br>";
//echo $string2[1] . "<br>";
//echo $string3[0] . "<br> ";
}
else
{
echo "Title not found for Tube uid " .$m[1] . " Tube id " . $row6[0] . "<br>";
echo $string2[1] . "<br>";
echo $string3[0] . "<br> ";
sleep(5);
}
flush();
//}
}
}
echo '<br> Fixing missing titles done :)';
}
else if ($action==2) //Correct tube links
{
$query6 = 'select * from vbtube_tubes where link like "%forum%"'; // remove word forum from path
//$query6 = 'select * from vbtube_tubes where link3 like "%&%"'; // find links with &
//$query6 = 'select * from vbtube_tubes where link1img like "%oman%"'; // find local images
//$query6 = 'select * from vbtube_tubes where link1img like "%&%"'; // find vars with &
$query6= mysqlCleaner($query6);
$result6 = mysql_query($query6);
while ($row6 = mysql_fetch_row($result6))
{
$m= explode("v=", $row6[11]);
//echo $m[1] . "<br> ";;
$s= explode("&", $m[1]);
$var =$mysiteadress . $row6[0] . "-"; //// remove word forum from path
//$var ="http://www.youtube.com/watch?v=" . $s[0] ; //for links
//$var ="http://img.youtube.com/vi/" . $s[0] . "/default.jpg"; //for images
//$insert7="update vbtube_tubes set link1img=\"$var\" where tubeid =$row6[0]"; //for iamges
$insert7="update vbtube_tubes set link=\"$var\" where tubeid =$row6[0]"; //for links
$insert7= mysqlCleaner($insert7);
mysql_query($insert7);
echo $var . "<br> ";
flush();
}
echo '<br> Removing local thumbs done :)';
}
else
{
echo "Sorry !! Nothing to do bye bye.....";
exit;
}
?>
PHP
Usage:
ShellScript
To delete all invalid tubes, the command would be:
http://www.yoursite.com/vbtube_delete.php?action=0
or
http://www.yoursite.com/vbtube_delete.php
To correct invalid titles of the tubes the command would be:
http://www.yoursite.com/vbtube_delete.php?action=1
To correct invalid links of the tubes the command would be:
http://www.yoursite.com/vbtube_delete.php?action=2
ShellScript
The script in action:
Posted in Tech Blog