Hello, i want to make Google Link Grabber with couch but i have some problem to generate couch tag with native php.
here is my code:
Grabber Code:
And here is the movie.php code:
When i tried with actual video id 1otiVNHxYs5wJH7OMDedhXv3bL3jtC3LQ from google video it was work.
Here the works code:
Now, my problem is when i set the code to couch <cms:show movie_link/> tag it's not executing. Need some help here.
Here is the error code:
I've tried with <cms:php>, not work either.
Here is the error code:
I've tried wrapping it with <cms:pages masterpage='movie.php'></cms:pages> also, but still no luck.
Here is the error code:
Need to find what is my problem, thankyou.
here is my code:
Grabber Code:
- Code: Select all
<?php
class DriveGrabber {
// Variables
public $cacheDir = __DIR__ .'/drive_cache/';
public $cacheLen = 60 * 60; // 60 Minutes
// Get download link
function getDownloadLink($fileId) {
$cacheFile = $this->cacheDir . md5($fileId) . ".cache";
$returnUrl = null;
$driveUrl = "https://drive.google.com/uc?id=".urlencode($fileId)."&export=download";
if (file_exists($cacheFile)) {
$resource = file_get_contents($cacheFile);
$resource = explode('~', $resource);
if (is_array($resource) && isset($resource[1]) && (time() - $resource[0]) <= 3600) {
$returnUrl = trim($resource[1]);
}
}
if ($returnUrl == null) {
$returnUrl = $this->parseUrl($driveUrl);
$this->cacheLink($cacheFile, $returnUrl);
}
return $returnUrl;
}
function cacheLink($path, $link) {
// Create cache directory
if (!file_exists($this->cacheDir)) {
mkdir($this->cacheDir, 0777, true);
}
// Create cache file
$data = time().'~'.$link;
file_put_contents($path, $data);
}
// Search for download link from drive url
function parseUrl($url, $cookies = null) {
$fileId = null;
$idPos = strpos($url, 'id=');
if ($idPos !== false) {
$fileId = substr($url, $idPos+3);
$fileId = substr($fileId, 0, strpos($fileId, '&'));
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_COOKIESESSION, true);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if ($cookies != null && is_array($cookies) && count($cookies) > 0) {
curl_setopt($ch, CURLOPT_COOKIE, implode('; ', $cookies));
}
$response = curl_exec($ch);
$headers = substr($response, 0, curl_getinfo($ch, CURLINFO_HEADER_SIZE));
$headers = explode("\r\n", $headers);
$redirect = null;
$cookies = array();
foreach ($headers as $header) {
$delimeterPos = strpos($header, ':');
if ($delimeterPos === false)
continue;
$key = trim(strtolower(substr($header, 0, $delimeterPos)));
$value = trim(substr($header, $delimeterPos+1));
if ($key == 'location') {
$redirect = $value;
}
if (strpos($key, 'cookie') !== false) {
$cookies[] = substr($value, 0, strpos($value, ';'));
}
}
if ($redirect == null) {
$confirm = strpos($response, "confirm=");
if ($confirm !== false) {
$confirm = substr($response, $confirm, strpos($response, '"'));
$confirm = substr($confirm, strpos($confirm, '=')+1);
$confirm = substr($confirm, 0, strpos($confirm, '&'));
$redirect = $this->parseUrl("https://drive.google.com/uc?export=download&confirm=".urlencode($confirm)."&id=".urlencode($fileId), $cookies);
}
}
return $redirect;
}
}
?>
- Code: Select all
<?php
if ( !defined('K_COUCH_DIR') ) die(); // cannot be loaded directly
//require_once( K_COUCH_DIR.'addons/cart/cart.php' );
//require_once( K_COUCH_DIR.'addons/inline/inline.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-folders.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-comments.php' );
//require_once( K_COUCH_DIR.'addons/extended/extended-users.php' );
//require_once( K_COUCH_DIR.'addons/routes/routes.php' );
//require_once( K_COUCH_DIR.'addons/jcropthumb/jcropthumb.php' );
//require_once( K_COUCH_DIR.'addons/bootstrap-grid/bootstrap-grid.php' );
require_once( K_COUCH_DIR.'addons/drive-grabber/drive-grabber.php' );
And here is the movie.php code:
- Code: Select all
<?php require_once( '../admin/cms.php' ); ?>
<cms:template title='Player' clonable='1'>
<cms:editable name='movie_link' label='Movie Link' required='1' type='text' />
</cms:template>
<?php
$drive = new DriveGrabber();
$videoUrl = $drive->getDownloadLink('1otiVNHxYs5wJH7OMDedhXv3bL3jtC3LQ');
?>
<!doctype html>
<html>
<head>
<title>Player | Movie123</title>
<style>
html{
padding: 0px;
margin: 0px
}
body{
margin: 0px;
padding: 0px;
background:black
}
</style>
<script src="https://content.jwplatform.com/libraries/smC1HW9J.js"></script>
<script>jwplayer.key="BiSnaPijub75RBQ8wmE/EHROZeNTH1neTb9gLR1QIooNVALLwBoi2w==";</script>
<!---<script src="<cms:show k_site_link/>assets/themes/moview/js/jwbox.js"></script>--->
</head>
<body>
<div style="margin: 0px;padding: 0px" id="myElement"></div>
<script>
var playerInstance = jwplayer("myElement")
playerInstance.setup({
file: "<?php echo $videoUrl ?>",
type: "mp4",
primary: "flash",
provider: "video",
image: "<cms:show movie_wallpaper/>",
width: "100%",
height: "100%",
skin: {
name: "vapor",
active: "red",
inactive: "grey",
background: "white"
},
tracks: [{
<cms:show_repeatable 'repeat_movie_subtitle'>
file: "<cms:show movie_subtitle/>",
label: "<cms:show subtitle_country/>",
kind: "captions",
"default": <cms:show subtitle_default/>
},{
</cms:show_repeatable>
}],
responsive: true
}).on('play', function () {
statusCollection('play');
playerData();
}).on('pause', function () {
statusCollection('pause');
playerData();
}).on('complete', function () {
this.setControls(true);
statusCollection('complete');
});
</script>
</body>
</html>
<?php COUCH::invoke(); ?>
When i tried with actual video id 1otiVNHxYs5wJH7OMDedhXv3bL3jtC3LQ from google video it was work.
Here the works code:
- Code: Select all
<?php
$drive = new DriveGrabber();
$videoUrl = $drive->getDownloadLink('1otiVNHxYs5wJH7OMDedhXv3bL3jtC3LQ');
?>
Now, my problem is when i set the code to couch <cms:show movie_link/> tag it's not executing. Need some help here.
Here is the error code:
- Code: Select all
<?php
$drive = new DriveGrabber();
$videoUrl = $drive->getDownloadLink('<cms:show movie_link/>');
?>
I've tried with <cms:php>, not work either.
Here is the error code:
- Code: Select all
<cms:php>
$drive = new DriveGrabber();
$videoUrl = $drive->getDownloadLink('<cms:show movie_link/>');
</cms:php>
I've tried wrapping it with <cms:pages masterpage='movie.php'></cms:pages> also, but still no luck.
Here is the error code:
- Code: Select all
<cms:pages masterpage='movie.php'>
<cms:php>
$drive = new DriveGrabber();
$videoUrl = $drive->getDownloadLink('<cms:show movie_link/>');
</cms:php>
</cms:pages>
Need to find what is my problem, thankyou.