Monday, 29 May 2017

List clickable movie thumbnails within a directory with node.js and JavaScript

I have a directory with movie files and a correspondent thumbnail (jpg) for each movie within the same directory. The video files have the same name as the corresponding thumbnail (beside the extension). Now I need to list these thumbnails within a browser and a click on a thumbnail will open the matching movie with VLC (no html5 player, just VLC for all). This is intended to run on a local machine only.

I did some research and it looks like that node.js and JavaScript is the way to go.

I’ve used below PHP script, but how should I do something similar in JavaScript in combination with node.js?

<?php
$files = glob("media/*.*");
$vid=NULL;

$imgExts = array("gif", "jpg", "jpeg", "png", "tiff", "tif");
$vidExts = array("mp4", "mpg", "avi", "mk4", "ogg", "3gp");

for ($i=0; $i<count($files); $i++) {
    $image = $files[$i];


$urlExt = pathinfo($files[$i], PATHINFO_EXTENSION);

    if(in_array($urlExt,$imgExts )){

        for($j=0; $j<count($files); $j++){
          $urlExt2 = pathinfo($files[$j], PATHINFO_EXTENSION);
            if(in_array($urlExt2,$vidExts )){

                if(strcmp(pathinfo($files[$i], PATHINFO_FILENAME),pathinfo($files[$j], PATHINFO_FILENAME))==0)
                $vid=$files[$j];
                }

        }
    echo '<a href="'.$vid .'"><img src="'.$image .'" />'."<br /></a>";
    }

}


?>



via MikeSkril

No comments:

Post a Comment