<?php
/**
* WiseLoop PHP Web Media Grabber Sample<br/>
* Title: Video<br/>Grabber
*/
require_once dirname(__FILE__) . "/../php-web-media-grabber/bin/wlWmg.php";
require_once dirname(__FILE__) . "/demo-utils.php";
$arrays = array($_POST, $_GET);
$url = wlExtArray::searchArraysByKey($arrays, 'url', null);
$download = wlExtArray::searchArraysByKey($arrays, 'download', '');
$size_active = wlExtArray::searchArraysByKey($arrays, 'size_active', '');
$size = intval(wlExtArray::searchArraysByKey($arrays, 'size', ''));
$size_operator = wlExtArray::searchArraysByKey($arrays, 'size_operator', '');
$limit_active = wlExtArray::searchArraysByKey($arrays, 'limit_active', '');
$limit = intval(wlExtArray::searchArraysByKey($arrays, 'limit', ''));
$tagslice_active = wlExtArray::searchArraysByKey($arrays, 'tagslice_active', '');
$tagslice = wlExtArray::searchArraysByKey($arrays, 'tagslice', '');
$ctype_active = wlExtArray::searchArraysByKey($arrays, 'ctype_active', '');
$video_extensions_active = wlExtArray::searchArraysByKey($arrays, 'video_extensions_active', '');
$video_extensions = wlExtArray::searchArraysByKey($arrays, 'video_extensions', '');
//testing if the url is coming from the approved sites (wiseloop or darkroomdesign)
//this test is meant to save bandwidth and disk space only on wiseloop.com demonstration page
//please remove this from your real production project
if ($download && isset($allowDownloadFrom)) {
$download = false;
foreach ($allowDownloadFrom as $approvedSite) {
if (stripos($url, $approvedSite)) {
$download = true;
break;
}
}
}
?>
<div class="row container">
<form action="" id="form" method="POST" enctype="multipart/form-data" class="form form-horizontal" role="form">
<div class="well well-sm">
<label class="control control-label" for="url">Full target URL path:</label>
<input class="form-control" type="text" name="url" id="url" placeholder="http://" value="<?php echo isset($url) ? $url : 'http://darkroomdesign.net/item/corporate-lower-third-2'; ?>"/>
<small class="text-info">include http:// also</small>
</div>
<div class="well well-sm">
<h4>Video Grabber Filters</h4>
<div class="container row">
<div class="checkbox col-sm-2">
<label>
<input type="checkbox" id="video_extensions_active" name="video_extensions_active" <?php echo $video_extensions_active ? 'checked' : ''; ?>/>
Video Extensions
</label>
</div>
<div class="col-sm-10">
<small class="text-info">if nothing is selected or the filter is inactive (unchecked), all extensions will be searched</small>
</div>
</div>
<select class="form-control" name="video_extensions[]" multiple>
<?php echo options(wlWmgVideoGrabber::getVideoFileExtensions(), $video_extensions); ?>
</select>
<small class="text-info">Ctrl+Click to select multiple values</small>
<div class="container row">
<div class="checkbox col-sm-2">
<label>
<input type="checkbox" id="ctype_active" name="ctype_active" <?php echo $ctype_active ? 'checked' : ''; ?>/>
Check Content-Type header
</label>
</div>
<div class="col-sm-10">
<small class="text-info">
if checked, the grabber engine will check also the content-type of the grabbed media to make sure it is a video;
this checking will add some additional processing as headers for each possible media will be downloaded in order to perform video validation.
If unchecked, the grabber engine will use only the provided file extensions and therefore the grabbing process will be faster but can bring non-video files also
</small>
</div>
</div>
</div>
<?php require_once 'widget-grabbing-parameters.php'; ?>
<div>
<input type="submit" value="Grab Videos" class="btn btn-primary"/>
</div>
</form>
</div>
<?php
if (!$video_extensions_active) {
$video_extensions = null;
}
//the magic starts here ...
//creating the video grabber object by giving some necessary parameters:
//$url: url,
//$video_extensions: the video extensions to grab (null means all)
$videoMediaGrabber = new wlWmgVideoGrabber($url, $video_extensions, $ctype_active);
//set download switch: if the videos should be downloaded to localhost
$videoMediaGrabber->setDoDownload($download);
//limit filter: setting the media limit count to be grabbed
if ($limit_active) {
$videoMediaGrabber->setLimit($limit);
}
//the processor will grab only the media founded inside the contents of the tag specified here
if ($tagslice_active) {
$videoMediaGrabber->setGrabOnlyFromTagSlice($tagslice);
}
//the content-length (size) filter
if ($size_active) {
//filter creation
$sizeFilter = new wlWmgFilter(
$size,
wlWmgFilter::TYPE_CONTENT_LENGTH,
$size_operator
);
//adding filter to the grabber
$videoMediaGrabber->addFilter($sizeFilter);
}
//grabbing
if ($url) {
$videoMediaGrabber->grab();
//displaying the grabbed media
echo '<h3>Grabbed media (' . $videoMediaGrabber->countValidMedia() . ' items found)</h3>';
echo '<pre>' . print_r($videoMediaGrabber->getValidMediaTable(true), true) . '</pre>';
//displaying founded invalid media or unsuccessful grabbing tries (due to various server rejections, or broken links)
if ($videoMediaGrabber->hasInvalidMedia()) {
echo '<h3>Invalid media (' . $videoMediaGrabber->countInvalidMedia() . ' items found)</h3>';
echo '<pre>' . print_r($videoMediaGrabber->getInvalidMediaTable(true), true) . '</pre>';
}
}
?>