/** * Get all video files recursive * * @param mixed $dir * @return array */ function getVideoFiles($dir) { global $totalIterations; $arr = array(); if (is_dir($dir) && is_readable($dir)) { $files = scandir($dir, SCANDIR_SORT_ASCENDING); foreach ($files as $file) { if ($file == "." || $file == "..") { continue; } $path = $dir . "/" . $file; if (is_dir($path)) { $arr = array_merge($arr, getVideoFiles($path)); } else { if (!preg_match("~\\.(mp4|mkv|mpg|avi|mpeg)~i", $file)) { continue; } $arr[] = $path; } } } return $arr; }
} } } break; } echo json_encode($data); exit; } # ajax requests if (isset($_POST["action"])) { switch ($_POST["action"]) { # getting the filelist case "get-filelist": $files = array(); foreach ($folders as $folder) { $files = array_merge($files, isStreamUrl($folder) ? array($folder) : getVideoFiles($folder)); } foreach ($files as $file) { $classes = array("file"); if (isset($options["viewed"][getPathHash($file)])) { $classes[] = "viewed"; } echo '<div class="' . implode(" ", $classes) . '" data-path="' . $file . '"><span class="eye"></span> <span class="path">' . $file . '</span></div>'; } exit; break; # save options # save options case "save-options": $folders = explode("\n", trim($_POST["folders"])); $error = false;