Error: Warning: file_get_contents(http://www.youtube.com/watch?v=VH5qQKQuuM): failed to open stream: HTTP request failed! HTTP/1.0 404 Not Found in /home2/wepkcom1/public_html/data/leechv/functions.php on line 30
Fatal error: Error while retreiving video page in /home2/wepkcom1/public_html/data/leechv/functions.php on line 31
Fatal error: Error while retreiving video page in /home2/wepkcom1/public_html/data/leechv/functions.php on line 31
PHP:
<?php
ini_set('error_reporting', -1);
ini_set('display_errors', true);
ini_set('max_execution_time', 0);
ini_set('ignore_user_abort', true);
ini_set('include_path', '.');
ini_set('user_agent', 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko Firefox/11.0');
if ( !defined('__DIR__') ) define('__DIR__', dirname(__FILE__));
require_once 'Zend/Loader/Autoloader.php';
Zend_Loader_Autoloader::getInstance();
// Youtube Developer Key
const YT_DEV_KEY = ''***************'***************';
// Facebook Application ID
const FB_APP_ID = '***************';
// Facebook Application Secret
const FB_APP_SECRET = '71fa4383bdc9459e82b7b6262be3e381';
function youtube_download($videoId, $targetDir, $jsProgressCallback = null)
{
if(!$page = file_get_contents('http://www.youtube.com/watch?v=' . $videoId)) {
trigger_error('Error while retreiving video page', E_USER_ERROR);
}
if(!preg_match("/yt\.playerConfig\s\=\s(?<config>.*?)\;\s*?yt\.setConfig/s", $page, $matches)) {
trigger_error('Unable to find PLAYER_CONFIG', E_USER_ERROR);
}
if(!$config = json_decode($matches['config'])) {
trigger_error('Malformed PLAYER_CONFIG', E_USER_ERROR);
}
$fmts = explode(',', $config->args->url_encoded_fmt_stream_map);
foreach( $fmts as $k => $v ) { parse_str($v, $fmts[$k]); }
$fmtToDl = $fmts[1];
$ch = curl_init($fmtToDl['url']);
$targetPath = $targetDir . '/' . $videoId . '.flv';
curl_setopt($ch, CURLOPT_FILE, fopen($targetPath, 'w'));
curl_setopt($ch, CURLOPT_FAILONERROR, true);
if ($jsProgressCallback) {
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($dlsize, $dled) use ($jsProgressCallback) {
static $lastUpdate = 0;
@$progress = round($dled / $dlsize * 100);
if( $progress > $lastUpdate ) {
echo "<script>{$jsProgressCallback}({$progress});</script>" . str_repeat(' ', 1024);
flush(); @ob_flush();
$lastUpdate = $progress;
}
return 0;
});
}
if (!curl_exec($ch)) {
trigger_error('Curl error:' . curl_error($ch), E_USER_ERROR);
}
return array(
'path' => $targetPath,
'type' => $fmtToDl['type'],
);
}
function youtube_upload($videoFile, $videoType, $username, $password)
{
$httpClient = Zend_Gdata_ClientLogin::getHttpClient(
$username, $password,
'youtube', null, 'LeechVid', null, null,
'https://www.google.com/accounts/ClientLogin'
);
$yt = new Zend_Gdata_YouTube($httpClient, 123, null, YT_DEV_KEY);
$yt->setMajorProtocolVersion(2);
$videoEntry = new Zend_Gdata_YouTube_VideoEntry;
$videoEntry->setMediaSource(
$yt->newMediaFileSource($videoFile)
->setContentType($videoType)
->setSlug('Change.Me')
);
$videoEntry->setVideoTitle('Change Me!');
$videoEntry->setVideoDescription('Edit Me!');
$videoEntry->setVideoCategory('Comedy');
$newEntry = $yt->insertEntry(
$videoEntry,
'http://uploads.gdata.youtube.com/feeds/api/users/default/uploads',
'Zend_Gdata_YouTube_VideoEntry'
);
return $newEntry;
}
function facebook_download($fb, $videoId, $targetDir, $jsProgressCallback)
{
$video = $fb->api($videoId);
$videoSrc = $video['source'];
$ch = curl_init($videoSrc);
$targetFile = $targetDir . '/' . basename(parse_url($videoSrc, PHP_URL_PATH));
curl_setopt_array($ch, array(
CURLOPT_FILE => fopen($targetFile, 'w'),
CURLOPT_FAILONERROR => true,
CURLOPT_NOPROGRESS => false,
CURLOPT_USERAGENT => $_SERVER['HTTP_USER_AGENT'],
CURLOPT_PROGRESSFUNCTION => function($dlsize, $dled) use ($jsProgressCallback)
{
static $lastUpdate = 0;
@$progress = round($dled / $dlsize * 100);
if( $progress > $lastUpdate ) {
echo "<script>{$jsProgressCallback}({$progress});</script>" . str_repeat(' ', 1024);
flush(); @ob_flush();
$lastUpdate = $progress;
}
return 0;
}
));
if (!curl_exec($ch)) {
trigger_error('Curl error:' . curl_error($ch), E_USER_ERROR);
}
return array(
'path' => $targetFile,
'type' => 'video/mp4',
);
}
function santabanta_download($videoId, $targetDir, $jsProgressCallback = null)
{
if(!$page = file_get_contents('http://www.santabanta.com/video.asp?video=' . $videoId)) {
trigger_error('Error while retreiving video page', E_USER_ERROR);
}
if(!preg_match('/clip\:\s\{\s*url\:\s\"(?<url>.*?)\"\,/s', $page, $matches)) {
trigger_error('Unable to find video url', E_USER_ERROR);
}
$ch = curl_init($matches['url']);
$targetPath = $targetDir . '/' . $videoId . '.flv';
curl_setopt($ch, CURLOPT_FILE, fopen($targetPath, 'w'));
if ($jsProgressCallback) {
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_NOPROGRESS, false);
curl_setopt($ch, CURLOPT_PROGRESSFUNCTION, function($dlsize, $dled) use ($jsProgressCallback) {
static $lastUpdate = 0;
@$progress = round($dled / $dlsize * 100);
if( $progress > $lastUpdate ) {
echo "<script>{$jsProgressCallback}({$progress});</script>" . str_repeat(' ', 1024);
flush(); @ob_flush();
$lastUpdate = $progress;
}
return 0;
});
}
if (!curl_exec($ch)) {
trigger_error('Curl error:' . curl_error($ch), E_USER_ERROR);
}
return array(
'path' => $targetPath,
'type' => 'video/x-flv',
);
}