forked from Mondego/TubeKit
-
Notifications
You must be signed in to change notification settings - Fork 12
/
runsetup.php
executable file
·535 lines (501 loc) · 12.2 KB
/
runsetup.php
1
<?php // TubeKit Beta 4 // http://www.tubekit.org // Author: Chirag Shah // Date: 10/22/2010 require_once("header.php");?> <br> <br> <table class="body"> <tr> <td><ul><?php $project = $_POST['project']; $prefix = $_POST['prefix']; if ((!$prefix) || ($prefix=="")) $prefix = "tk"; $numvideos = $_POST['numvideos']; if ($numvideos>1000) $numvideos = 1000; if (!$numvideos) $numvideos = 100; $dbhost = $_POST['dbhost']; $dbname = $_POST['dbname']; $username = $_POST['dbusername']; $password = $_POST['password']; $cdirectory = $_POST['cdirectory']; $mpdirectory = 'tools/magpierss-0.72'; $ytdldirectory = $_POST['ytdl']; $fdirectory = $cdirectory . "/flash"; $mdirectory = $cdirectory . "/mpeg"; system("mkdir $fdirectory $mdirectory"); $fc = fopen("$cdirectory/config.php", 'w') or die("<br/>Error creating file. Make sure you have given your webserver write permission to the crawler directory.<br/>\n"); $stringData = "<?php\n \$dbh = mysql_connect('$dbhost','$username','$password') or die('Cannot connect to the database: '. mysql_error());\n \$db_selected = mysql_select_db('$dbname') or die ('Cannot connect to the database: ' . mysql_error());\n\$project=\"$project\";\n\$prefix=\"$prefix\";\n\$numvideos=$numvideos;\n\$fdirectory=\"$fdirectory\";\n\$mdirectory=\"$mdirectory\";\n\$mpdirectory=\"$mpdirectory\";\n\$ytdldirectory=\"$ytdldirectory\";\n?>\n"; fwrite($fc, $stringData); fclose($fc); echo "<li> Configuration parameters stored in 'config.php'.</li>\n"; $dbh = mysql_connect($dbhost, $username, $password); if (!mysql_query("CREATE DATABASE $dbname")) die(mysql_error()); $dbh = mysql_connect($dbhost, $username, $password); if (!mysql_select_db($dbname)) die(mysql_error()); echo "<li> Success in database creation.</li>\n"; // Prepare tables in the database $firstDone1 = true; $firstDone2 = true; $query1 = "CREATE TABLE ". $prefix . "_once (video_id INT(11) unsigned NOT NULL auto_increment,query_id INT(11),yt_id VARCHAR(20),timestamp INT(11),downloaded TINYINT(4) default '0',converted TINYINT(4) default '0',collectiondate DATE, Type VARCHAR(20)"; $query2 = "CREATE TABLE " . $prefix . "_everytime (id INT(11) unsigned NOT NULL auto_increment,video_id INT(11),timestamp INT(11),collectiondate DATE,Type VARCHAR(20)"; if ($_POST['title'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "title VARCHAR(200)"; $firstDone1 = true; } else if ($_POST['title'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "title VARCHAR(200)"; $firstDone2 = true; } if ($_POST['description'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "description blob"; $firstDone1 = true; } else if ($_POST['description'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "description blob"; $firstDone2 = true; } if ($_POST['username'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "username VARCHAR(50)"; $firstDone1 = true; } else if ($_POST['username'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "username VARCHAR(50)"; $firstDone2 = true; } if ($_POST['date'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "recording_date DATE"; $firstDone1 = true; } else if ($_POST['date'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "recording_date DATE"; $firstDone2 = true; } if ($_POST['upload_time'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "upload_time datetime"; $firstDone1 = true; } else if ($_POST['upload_time'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "upload_time datetime"; $firstDone2 = true; } if ($_POST['duration'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "duration INT(11)"; $firstDone1 = true; } else if ($_POST['duration'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "duration INT(11)"; $firstDone2 = true; } if ($_POST['category'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "category VARCHAR(200)"; $firstDone1 = true; } else if ($_POST['category'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "category VARCHAR(200)"; $firstDone2 = true; } if ($_POST['keywords'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "keywords text"; $firstDone1 = true; } else if ($_POST['keywords'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "keywords text"; $firstDone2 = true; } if ($_POST['video_url'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "video_url VARCHAR(100)"; $firstDone1 = true; } else if ($_POST['video_url'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "video_url VARCHAR(100)"; $firstDone2 = true; } if ($_POST['thumb_url'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "thumb_url VARCHAR(100)"; $firstDone1 = true; } else if ($_POST['thumb_url'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "thumb_url VARCHAR(100)"; $firstDone2 = true; } if ($_POST['view_count'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "view_count INT(11)"; $firstDone1 = true; } else if ($_POST['view_count'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "view_count INT(11)"; $firstDone2 = true; } if ($_POST['rating_count'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "rating_count INT(11)"; $firstDone1 = true; } else if ($_POST['rating_count'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "rating_count INT(11)"; $firstDone2 = true; } if ($_POST['rating_avg'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "rating_avg FLOAT"; $firstDone1 = true; } else if ($_POST['rating_avg'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "rating_avg FLOAT"; $firstDone2 = true; } if ($_POST['comment_count'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "comment_count INT(11)"; $firstDone1 = true; } else if ($_POST['comment_count'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "comment_count INT(11)"; $firstDone2 = true; } if ($_POST['comments'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "comments blob"; $firstDone1 = true; } else if ($_POST['comments'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "comments blob"; $firstDone2 = true; } if ($_POST['response_count'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "response_count INT(11)"; $firstDone1 = true; } else if ($_POST['response_count'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "response_count INT(11)"; $firstDone2 = true; } if ($_POST['favorite_count'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "favorite_count INT(11)"; $firstDone1 = true; } else if ($_POST['favorite_count'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "favorite_count INT(11)"; $firstDone2 = true; } if ($_POST['rank'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "rank INT(11)"; $firstDone1 = true; } else if ($_POST['rank'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "rank INT(11)"; $firstDone2 = true; } if ($_POST['related_id'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "related_id LONGTEXT"; $firstDone1 = true; } else if ($_POST['related_id'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "related_id LONGTEXT"; $firstDone2 = true; } // InResponse Retrieval if ($_POST['inresponse'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "inresponse LONGTEXT"; $firstDone1 = true; } else if ($_POST['inresponse'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "inresponse LONGTEXT"; $firstDone2 = true; } // Likes and Dislikes to follow if ($_POST['likes'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "likes INT(11)"; $firstDone1 = true; } else if ($_POST['likes'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "likes INT(11)"; $firstDone2 = true; } if ($_POST['dislikes'] == "once") { if ($firstDone1) { $query1 = $query1 . ","; } $query1 = $query1 . "dislikes INT(11)"; $firstDone1 = true; } else if ($_POST['dislikes'] == "everytime") { if ($firstDone2) { $query2 = $query2 . ","; } $query2 = $query2 . "dislikes INT(11)"; $firstDone2 = true; } $query1 = $query1 . ",PRIMARY KEY(`video_id`))"; $query2 = $query2 . ",PRIMARY KEY(`id`))"; $query3 = "CREATE TABLE ". $prefix . "_queries (id INT(11) NOT NULL auto_increment,query varchar(100) default NULL,PRIMARY KEY(`id`))"; $result = mysql_query($query3) || die(mysql_error()); echo "<li> Table for queries created.</li>\n"; $result = mysql_query($query1) || die(mysql_error()); echo "<li> Table for storing crawl-once data created.</li>\n"; $result = mysql_query($query2) || die(mysql_error()); echo "<li> Table for storing crawl-always data created.</li>\n"; $qmo = $_POST['qmo']; $qdm = $_POST['qdm']; $qdw = $_POST['qdm']; $qho = $_POST['qho']; $qmi = $_POST['qmi']; $cmo = $_POST['cmo']; $cdm = $_POST['cdm']; $cdw = $_POST['cdm']; $cho = $_POST['cho']; $cmi = $_POST['cmi']; $dmo = $_POST['dmo']; $ddm = $_POST['ddm']; $ddw = $_POST['ddm']; $dho = $_POST['dho']; $dmi = $_POST['dmi']; $mmo = $_POST['mmo']; $mdm = $_POST['mdm']; $mdw = $_POST['mdm']; $mho = $_POST['mho']; $mmi = $_POST['mmi']; $amo = $_POST['amo']; $adm = $_POST['adm']; $adw = $_POST['adm']; $aho = $_POST['aho']; $ami = $_POST['ami']; $fc = fopen("$cdirectory/cron", 'w') or die ("Error writing the cron file<br>"); $command = "SHELL=/bin/bash\nPATH=/sbin:/bin:/usr/sbin:/usr/bin\n\n"; fwrite($fc, $command); $command = "$qmi $qho $qdm $qmo $qdw php " . $cdirectory . "/" . "collectOnce.php\n"; fwrite($fc, $command); $command = "$cmi $cho $cdm $cmo $cdw php " . $cdirectory . "/" . "collectEverytime.php\n"; fwrite($fc, $command); $command = "$dmi $dho $ddm $dmo $ddw php " . $cdirectory . "/" . "downloadVideos.php\n"; fwrite($fc, $command); $command = "$mmi $mho $mdm $mmo $mdw php " . $cdirectory . "/" . "convertVideos.php\n"; fwrite($fc, $command); fclose($fc); echo "<li> Cron job file 'cron' created.</li>\n"; system ("cp crawler/* $cdirectory/"); echo "<li> Crawler is ready in $cdirectory.</li>\n"; ?> </ul></td> </tr> </table><?php require_once("footer.php");?>