File: /home/httpd/html/freecams1.com/public_html/admin/scraper.php
<?php
ignore_user_abort();
ini_set('max_execution_time', 86400);
require "db.php";
require 'scrape_functions.php';
if (isset($_POST['formScraperSubmit'])) {
$pid = backgroundProcess("$php_path $basepath/admin/scraper_cron.php", 'scraper_log.txt');
dbQuery("UPDATE status SET scraper_pid = '$pid'");
setMessage("The scraper has been executed as PID $pid. Please check back on this page to see its progress.");
header("Location: $_SERVER[REQUEST_URI]");
exit();
}
if (isset($_POST['formSubmit'])) {
$_POST = array_map_array('trim', $_POST);
if ($_POST['dump'] == '') {
setMessage('"Dump" is required!', 'error');
}
if ($_POST['submitter'] == '') {
setMessage('"Submitter" is required!', 'error');
}
if ($_POST['paysite'] == '') {
setMessage('"Paysite" is required!', 'error');
}
if (!getMessages(false, 'error')) {
$counter = 0;
$errors = 0;
if ($_POST['dump'] != "") {
$dump = explode("\n", $_POST['dump']);
$getUser = dbRow("SELECT `record_num` FROM `users` WHERE `username` = '" . mysqli_real_escape_string($dblink, $_POST['submitter']) . "'");
$_POST['submitter'] = is_array($getUser) ? $getUser['record_num'] : 0;
foreach ($dump as $i) {
if ($i != '' && (strstr($i, 'http://') || strstr($i, 'https://'))) {
$i = trim($i);
if (dbQuery("INSERT INTO scraper_import (url, user, paysite) VALUES ('$i','$_POST[submitter]', '$_POST[paysite]')")) {
$counter++;
} else {
$errors++;
}
}
}
}
$pid = backgroundProcess("$php_path $basepath/admin/scraper_cron.php", 'scraper_log.txt');
setMessage("$counter added to queue, $errors errors. The scraper has been executed as PID $pid. Please check back on this page to see its progress.");
header("Location: $_SERVER[REQUEST_URI]");
exit();
}
}
entities_walk($_POST);
?>
<? require "header.php"; ?>
<script>
$(document).ready(function () {
$("#scraperListButton").click(function () {
$("#scraperList").toggle('slow');
});
});
</script>
<div class="content-page">
<div class="header-area">
<div class="breadcrumbs">
<a href="index.php">Admin Home</a>
<span><a href="scraper.php">Tube Scraper</a></span>
</div>
</div>
<div class="content-outer">
<h2>Tube<strong>Scraper</strong></h2>
<div class="notification info">
This function uses <a href="http://rg3.github.io/youtube-dl/index.html" target="_blank">youtube-dl</a> as it's scraper. We suggest installing it as per the instructions on their download page, and adding the update function to cron as root <br /><em>1 0 * * * /usr/local/bin/youtube-dl -U</em><br />
so that your scraper is always up to date. <a href='#' id='scraperListButton'>Click here to view the list of supported sites</a>. Youtube-dl is not maintained by us and we are unable to fix any of these. If some do not work, please make sure you've updated your youtube-dl.
</div>
<div id="scraperList" class="notification info" style="display:none;">
<?
$output = shell_exec("/usr/local/bin/youtube-dl --extractor-descriptions");
$output = explode("\n", $output);
echo "<ul>";
foreach ($output as $i) {
echo "<li>$i</li>";
}
echo "</ul>";
?>
</div>
<div class="notification warning">Please enter video page urls, one per line. Please note that this function is not instant - many of these sites cap the download speeds at around 100k/sec, so downloading large videos may take some time.</div>
<div class="notification info">To start scraper manually, if using APIs or you need to restart it due to server reboot/api restart, please press START SCRAPER below.</div>
<? echo getMessages(); ?>
<div class="content-inner">
<? if (file_exists('scripts/scraper.txt') && !$_POST['dump']) { ?>
<div class="notification alert">The scraper is already running! If you are SURE something went wrong, delete /admin/scripts/scraper.txt, and run this script again.</div>
<? } else { ?>
<form method="POST" action="" class="form" novalidate autocomplete="off">
<table class="pagetable">
<tr class="item submit">
<td>
<input type="hidden" name="formScraperSubmit" value="1" />
<button type="submit" class="btn btn-red action-save">START SCRAPER</button>
</td>
</tr>
</table>
</form>
<form method="POST" action="" class="form" novalidate autocomplete="off">
<table class="pagetable">
<tr>
<td>Dump:</td>
<td><textarea name="dump" rows="10" required><? echo $_POST['dump']; ?></textarea></td>
</tr>
<tr>
<td>Video Submitter:</td>
<td>
<input type="text" name="submitter" id="contentAutocomplete" value="<? echo $_POST['submitter']; ?>" placeholder="Start typing username..." required />
<script type="text/javascript">
$(document).ready(function () {
$("#contentAutocomplete").autocomplete({
source: "<?php echo $basehttp; ?>/admin/search_content.php?type=2",
minLength: 2
});
});
</script>
</td>
</tr>
<tr>
<td>Paysite:</td>
<td>
<select name="paysite" required>
<option value=""> - select paysite - </option>
<? $rresult = dbQuery("SELECT * FROM `paysites` ORDER BY `name`", false); ?>
<? foreach ($rresult as $rrow) { ?>
<option<? echo ($_POST['paysite'] == $rrow['record_num']) ? ' selected' : ''; ?> value="<? echo $rrow['record_num']; ?>"><? echo $rrow['name']; ?></option>
<? } ?>
</select>
</td>
</tr>
<tr class="item submit">
<td colspan="2">
<input type="hidden" name="formSubmit" value="1" />
<button type="submit" class="btn action-save">Submit</button>
</td>
</tr>
</table>
</form>
<? } ?>
</div>
</div>
</div>
<? require "footer.php"; ?>