Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php //author Vinicius Kwasinski:: [email protected]
- ///////////////////////////////
- // Check all directories recursively
- // and search for videos files
- // with extensions defined in the data structure
- ///////////////////////////////
- if(isset($_GET['filename']) && isset($_GET['ext'])) {
- header("Content-disposition: attachment; filename=" . $_GET['filename']);
- header("Content-type: application/{$_GET['ext']}");
- readfile($_GET['filename']);
- }
- $scrap_structure = array(
- 'ext' => array('mov', 'avi', 'mpeg', 'divx'), //availabe video extensions
- 'basefolders_to_ignore' => array('video_scraper_img'), //add here folders that contains files used by video_scraper
- 'exclude_paths' => '/^[^\.]/', //regExp to exclude original folder's path
- 'get_extension' => '/\.(\w\w\w\w?)$/', //regExp to catch file extension
- //var_dump($scrap_structurevideo_scraper_imgvideofolder.png
- );
- list_dirs();
- //var_dump($scrap_structurevideo_scraper_img/folder.png
- ?>
- <html>
- <head>
- <title>Video Scraper 0.1</title>
- <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
- <style type="text/css">
- .content h2 { width: 540px; margin: 0 auto;}
- li { cursor: pointer; list-style-type: none; }
- .tree li span, .tree li a { position: relative; bottom: 10px;}
- .tree { display: none; position: relative; left: 30px; top: 10px; }
- .content { width: 1024px; margin: 0 auto; border: 1px solid black; padding: 20px; }
- .indicator img { width: 17px; position: relative; top: 3px; }
- </style>
- </head>
- <body>
- <div class="content">
- <h2>Lista de todos os vídeos dentro dessas pastas</h2>
- <p>Clique na(s) pasta(s) abaixo para mostrar o(s) video(s) que cada uma contém ou realize uma busca.</p>
- <ul>
- <?php
- $i = 0; if($scrap_structure['paths'] & $paths = $scrap_structure['paths'])
- foreach ($paths as $path_name => $keys): $i++; ?>
- <li <?= "class=\"clicklabe_$i\""?>> <span class="indicator"><img src="video_scraper_img/close.png" alt=""></span> <?= $path_name == '.'? 'Raiz': $path_name; ?> -- Arquivos:<?= array_pop($paths[$path_name]) ?>
- <?php foreach ($paths[$path_name] as $filename): ?>
- <ul class="tree">
- <?php if(file_check($filename, true)): ?>
- <li style="list-style-image: url('video_scraper_img/video.png')">
- <a href="index.php?filename=<?= "$path_name/$filename"?>&ext=<?= file_check($filename, true) ?>"><?= $filename ?></a>
- </li>
- <?php else: ?>
- <li style="list-style-image: url('video_scraper_img/folder.png')">
- <span><?= $filename ?></span>
- </li>
- <?php endif; ?>
- </ul>
- <?php endforeach; ?>
- </li>
- <br/>
- <?php endforeach; ?>
- </ul>
- </div>
- </body>
- </html>
- <script type="text/javascript">
- jQuery(document).ready(function($) {
- var image = {
- open: 'open.png',
- close: 'close.png',
- }
- $("li[class^='clicklabe_']").click(function(){
- var $this = $(this);
- var file_tree = $this.find('ul.tree');
- file_tree.toggle('fast');
- //Swap the open <-> close img;
- var img_src = $this.find('.indicator > img'),
- img_src_attr = img_src.attr('src').match(/(\w+)\.\w{3,3}$/)[0]? RegExp.$1: null;
- var replace = img_src.attr('src').replace(/(\w+)\.\w{3,3}$/, img_src_attr == 'close'? 'open.png': 'close.png');
- img_src.attr('src', replace);
- });
- });
- </script>
- <?php
- function list_dirs($path = false) {
- $base_path = $path? $path: '.';
- global $scrap_structure;
- $directories = sanitize_dir(scandir($base_path));
- foreach ($directories as $path) {
- $full_filename = "$base_path/$path";
- if (in_array($path, $scrap_structure['basefolders_to_ignore'])) continue;
- if (is_dir($full_filename))
- list_dirs($full_filename) & $scrap_structure['paths'][$base_path][] = $full_filename;
- if (!file_check($path)) continue;
- $scrap_structure['paths'][$base_path][] = $path;
- }
- $scrap_structure['paths'][$base_path]['n_files'] = count($directories);
- ksort($scrap_structure['paths']);
- }
- // exclude [.] && [..] and hidden linux files [.filename]
- function sanitize_dir($arr_dir) {
- if(!$arr_dir) return;
- global $scrap_structure;
- $to_exclude = preg_grep($scrap_structure['exclude_paths'], $arr_dir, PREG_GREP_INVERT);
- foreach ($to_exclude as $key => $value)
- if ($to_exclude[$key] == $arr_dir[$key] || !file_check($arr_dir[$key], true)) unset($arr_dir[$key]);
- return $arr_dir;
- }
- // Check if the filename has a video extension if not add the path with a value [vazio]
- // @returns $get_ext? bool: extension
- function file_check($filename, $get_ext = false) {
- if(!$filename) return false;
- global $scrap_structure;
- $ext = preg_match($scrap_structure['get_extension'], $filename , $_)? $_[1]: '';
- if (!empty($ext)) $is_a_video = in_array($ext, $scrap_structure['ext'])? true: false;
- if (isset($is_a_video)) return !$get_ext? $is_a_video: $_[1];
- return false;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement