Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $smbhost = '192.168.11.1';
- $smbuser = '';
- $smbpass = '';
- $smbdir = 'Media/YouTube/Videos';
- $m = @$_REQUEST['m']; // dir
- $z = @$_REQUEST['z']; // raw video
- $v = @$_REQUEST['v']; // video player
- $i = @$_REQUEST['i']; // raw info json
- $t = @$_REQUEST['t']; // raw jpeg thumb
- $m = str_replace("..","",$m);
- $win = false;
- $smb = smbclient_state_new();
- smbclient_state_init($smb,null,$smbuser,$smbpass);
- if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
- $win = true;
- }
- if (!@$z && !@$v && !@$i && !@$t) {
- // Default output
- echo "<!DOCTYPE html>\n";
- echo "<head>\n";
- echo "<meta charset=\"UTF-8\">\n";
- echo "<link rel=\"stylesheet\" href=\"includes/zefie.css\" />\n";
- echo "<title>Video Browser";
- if (@$m) { echo " - ".str_replace('//','/',$m); }
- echo "</title>\n";
- echo "<script type='text/javascript' src='includes/jquery-2.1.4.min.js'></script>\n";
- echo "<script type='text/javascript' src='includes/jquery-dateFormat.min.js'></script>\n";
- echo "<script type='text/javascript' src='includes/zefie.js'></script>\n";
- echo "</head>\n";
- echo "<body>\n";
- if ($m && $m != "/") {
- $up = preg_split("/\//",$m);
- $updir = "";
- for ($q = 0; $q < (count($up)-1); $q++) {
- $updir .= "/".$up[$q];
- }
- $updir = str_replace('//','/',$updir);
- echo "<div class=\"dir\" data-href='?m=".rawurlencode($updir)."'>..</div>\n";
- }
- $basepath = str_replace('//','/',$smbdir.'/'.@$m);
- $handle = smbclient_opendir($smb,'smb://'.$smbhost.'/'.$basepath);
- if ($handle) {
- while (false !== ($f = smbclient_readdir($smb,$handle))) {
- $file = $f['name'];
- if ($file == "." || $file == ".." || $file == "meta") { continue; }
- $path = str_replace('//','/',$basepath.'/'.@$m.'/'.$file);
- if ($f['type'] == 'directory')
- $dirs[] = $file;
- else
- $files[] = $file;
- }
- smbclient_closedir($smb,$handle);
- }
- if (@$dirs) {
- sort($dirs);
- foreach (@$dirs as $file) {
- $path = $smbdir."/".@$m."/".$file;
- echo "<div class=\"dir\" data-href='?m=".rawurlencode(@$m."/".$file)."'>".$file."</div>\n";
- }
- }
- if (@$files) {
- sort($files);
- foreach (@$files as $file) {
- if ($file != "." && $file != ".." && (strtolower(substr($file, strrpos($file, '.') + 1)) == 'mp4' || strtolower(substr($file, strrpos($file, '.') + 1)) == 'm4a'))
- {
- $f = str_replace(" [".getID($file)."].".getExt($file),"",$file);
- $f = substr($f,11,strlen($f));
- echo "<div class=\"file\">".$f."</div>\n<div class='info' data-id='".getID($file)."'> </div>\n";
- }
- }
- }
- echo "</body>\n";
- echo "</html>\n";
- }
- if (@$v) {
- // Generate video player
- $vid = findFileByID($v);
- $nfo = findFileByID($v,true);
- $fp = smbclient_open($smb,'smb://'.$smbhost.'/'.$smbdir.'/'.$nfo,'r');
- $fdat = smbclient_fstat($smb,$fp);
- $jsnr = smbclient_read($smb,$fp,$fdat[7]);
- smbclient_close($smb,$fp);
- $json = json_decode($jsnr);
- $contype = getConType($vid);
- echo "<!DOCTYPE html>\n";
- echo "<head>\n";
- echo "<meta charset=\"UTF-8\">\n";
- echo "<link rel=\"stylesheet\" href=\"includes/zefie.css\" />\n";
- echo "<title>Video Player - ".$json->title."</title>\n";
- echo "</head>\n";
- echo "<body>\n";
- echo "<center>\n";
- if ($contype == "audio/m4a" || $contype == "audio/mp3") {
- echo "<audio width='800' src='?z=".$v."' controls autoplay type='".$contype."'>\n";
- echo " Your browser does not support the audio tag.\n";
- echo "</audio>\n";
- } else {
- echo "<video width='800' height='450' controls autoplay src='?z=".$v."' type='".$contype."'>\n";
- echo " Your browser does not support the video tag.\n";
- echo "</video>\n";
- }
- echo "</center>\n";
- echo "<div class='desc'><pre>".$json->description."</pre></div>";
- echo "</body>\n";
- echo "</html>\n";
- }
- if (@$z || @$i || @$t) {
- // Send file
- //@error_reporting(0);
- $vid = "";
- if (@$z) { $vid = findFileByID($z); }
- if (@$i) { $vid = findFileByID($i,true); }
- if (@$t) { $vid = findFileByID($t,false,true); }
- $contype = getConType($vid);
- if (strlen($vid) == null) {
- header("404 No Such Video ID");
- echo "<!DOCTYPE html>\n";
- echo "<head>\n";
- echo "<meta charset=\"UTF-8\">\n";
- echo "No Such Video ID";
- exit;
- }
- if ($vid) {
- sendFile($vid,$contype);
- }
- }
- function sendFile($vid,$contype) {
- require_once("includes/servlet.php");
- global $smb, $smbhost, $smbdir;
- $smbdata = array($smb,$smbhost,$smbdir);
- serveFilePartial($vid,$smbdata,$contype);
- }
- function findFileByID($id,$meta = false,$thumb = false) {
- // scan filesystem for "[youtubeid]"
- global $basedir;
- if ($meta) {
- $vid = scanDirectories($basedir, array("json"),$id);
- } elseif ($thumb) {
- $vid = scanDirectories($basedir, array("jpg","gif","png"),$id);
- } else {
- $vid = scanDirectories($basedir, array("m4a","mp4","mp3"),$id);
- }
- return @$vid[0];
- }
- function getExt($s) {
- $s = strrev($s);
- $o = strtolower(substr($s,0,strpos($s,'.')));
- return strrev($o);
- }
- function getID($s) {
- // Get YTID from filename
- $s = strrev($s);
- $st = strpos($s,"]") + 1;
- $len = (strpos($s,"[") - $st);
- return strrev(substr($s,$st,$len ));
- }
- function getConType($s) {
- $ext = getExt($s);
- switch ($ext) {
- case 'jpg':
- return "image/jpeg";
- ;;
- case 'png':
- return "image/png";
- ;;
- case 'gif':
- return "image/gif";
- ;;
- case 'm4a':
- return "audio/m4a";
- ;;
- case 'mp4':
- return "video/mp4";
- ;;
- case 'mp3':
- return "audio/mp3";
- ;;
- case 'json':
- return "application/json";
- ;;
- }
- }
- function scanDirectories($rootDir, $allowext, $ytid, $res = array()) {
- global $smb, $smbhost, $smbdir;
- $handle = smbclient_opendir($smb, 'smb://'.$smbhost.'/'.$smbdir.'/'.$rootDir);
- while (false !== ($f = smbclient_readdir($smb,$handle))) {
- $file = $f['name'];
- $path = $rootDir.'/'.$file;
- $ext = substr($file, strrpos($file, '.') + 1);
- if(in_array($ext, $allowext)) {
- $readable = ($f['type'] == 'file');
- if($readable && preg_match("/\\[".$ytid."\\]/",$file))
- $res[] = $path;
- }
- $isdir = ($f['type'] == 'directory');
- if($isdir && $file != "." && $file != "..") {
- // recursive callback to open new directory
- $res = scanDirectories($path, $allowext, $ytid, $res);
- }
- }
- smbclient_closedir($smb,$handle);
- return $res;
- }
- smbclient_state_free($smb);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement