Prechádzať zdrojové kódy

Added possibility to download posters of series and use them instead of the name on the overview

Moritz Schmidt 10 rokov pred
rodič
commit
b83340e582
3 zmenil súbory, kde vykonal 313 pridanie a 60 odobranie
  1. 69 0
      functions.php
  2. 95 60
      index.php
  3. 149 0
      updateMetadata.php

+ 69 - 0
functions.php

@@ -0,0 +1,69 @@
+<?php
+
+function pa($debug, $var = false) {
+    echo "<pre>";
+    if($var) {
+        var_dump($debug);
+    } else {
+        print_r($debug);
+    }
+    echo "</pre>";
+}
+
+function getImageByName($folder) {
+
+    return "/posters/" . $folder . ".jpg";
+
+
+    error_log($folder);
+    $imdbID = trim(preg_replace('/\s+/', ' ', file_get_contents($folder . '/imdbid')));
+    error_log($imdbID);
+
+    $result = json_decode(curl_download("http://www.omdbapi.com/?i=" . $imdbID));
+
+    error_log($result->{"Poster"});
+
+    return $result->{"Poster"};
+
+
+}
+
+function curl_download($Url){
+    // is cURL installed yet?
+    if (!function_exists('curl_init')){
+        die('Sorry cURL is not installed!');
+    }
+
+    // OK cool - then let's create a new cURL resource handle
+    $ch = curl_init();
+
+    // Now set some options (most are optional)
+
+    // Set URL to download
+    curl_setopt($ch, CURLOPT_URL, $Url);
+
+    // Set a referer
+    //curl_setopt($ch, CURLOPT_REFERER, "http://www.example.org/yay.htm");
+
+    // User agent
+    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/45.0.2454.101 Safari/537.36");
+
+    // Include header in result? (0 = yes, 1 = no)
+    curl_setopt($ch, CURLOPT_HEADER, 0);
+
+    // Should cURL return or print out the data? (true = return, false = print)
+    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+
+    // Timeout in seconds
+    curl_setopt($ch, CURLOPT_TIMEOUT, 10);
+
+    // Download the given URL, and return output
+    $output = curl_exec($ch);
+
+    // Close the cURL resource, and free system resources
+    curl_close($ch);
+
+    return $output;
+}
+
+?>

+ 95 - 60
index.php

@@ -1,79 +1,114 @@
-<html>
+<?php
+require('functions.php');
+?>
+<!DOCTYPE html>
+<html lang="de">
     <head>
+        <meta charset="utf-8">
+        <meta http-equiv="X-UA-Compatible" content="IE=edge">
+        <meta name="viewport" content="width=device-width, initial-scale=1">
+
         <title>WebVideoViewer</title>
+
+        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" integrity="sha512-dTfge/zgoMYpP7QbHy4gWMEGsbsdZeCXz7irItjcC3sPUFtf0kuFbDz/ixG7ArTxmDjLXDmezHubeNikyKGVyQ==" crossorigin="anonymous">
+
+        <style>
+
+            .col-sm-3 > a > img {
+                width: 100%;
+            }
+
+            .col-sm-3 {
+                padding-bottom: 15px;
+            }
+
+        </style>
     </head>
     <body>
-    <?php
 
-    $CONFIG = array(
-        "paths" => array(
-            "/media/Serien",
-            "/media/Filme"
-        )
-    );
+        <div class="container-fluid">
+
+        <?php
 
-    if(!isset($_GET['path']) || !$_GET['path']) {
-        foreach($CONFIG['paths'] as $path) {
-            echo "<h2>" . $path . "</h2>";
+        $CONFIG = array(
+            "paths" => array(
+                "/media/Serien",
+                "/media/Filme"
+            )
+        );
 
-            $list = scandir($path);
-            $list = array_diff($list, array('.', '..'));
+        if(!isset($_GET['path']) || !$_GET['path']) {
+            foreach($CONFIG['paths'] as $path) {
+                $folderName = split('/', $path);
+                echo "<h1>" . $folderName[sizeof($folderName) - 1] . "</h1>";
 
-            foreach($list as $object) {
-                echo "<a href=\"?path=" . $path . "/" . $object . "\">" . $object . "</a><br>";
+                $list = scandir($path);
+                $list = array_diff($list, array('.', '..'));
+
+                echo "<div class=\"row\">";
+                foreach($list as $object) {
+                    echo "<div class=\"col-sm-3\">";
+                    echo "<a href=\"?path=" . $path . "/" . $object . "\">" . "<img src=\"" . getImageByName($object) . "\" alt=\"" . $object . "\">" . "</a><br>";
+                    echo "</div>";
+                }
+                echo "</div>";
             }
-        }
-    } else {
-        $_GET['path'] = str_replace('/..', '', $_GET['path']);
-        $_GET['path'] = str_replace('../', '', $_GET['path']);
-        $_GET['path'] = str_replace('..', '', $_GET['path']);
-
-        echo "<h2>" . $_GET['path'] . "</h2>";
-        if(is_dir($_GET['path'])) {
-            $list = scandir($_GET['path']);
-            $list = array_diff($list, array('.'));
-            foreach($list as $object) {
-                if($object == "..") {
-                    if(in_array($_GET['path'], $CONFIG['paths'])) {
-                        echo "<a href=\"?path=\">Home</a><br>";
-                    } else {
-                        $paths = explode('/', $_GET['path']);
-                        $paths = array_diff($paths, array($paths[sizeof($paths) - 1]));
-                        $pathv = "";
-                        foreach($paths as $key => $path) {
-                            if($key == sizeof($paths) - 1) {
-                                $pathv .= $path;
-                            } else {
-                                $pathv .= $path . "/";
+        } else {
+            $_GET['path'] = str_replace('/..', '', $_GET['path']);
+            $_GET['path'] = str_replace('../', '', $_GET['path']);
+            $_GET['path'] = str_replace('..', '', $_GET['path']);
+
+            echo "<h1>" . $_GET['path'] . "</h1>";
+            if(is_dir($_GET['path'])) {
+                $list = scandir($_GET['path']);
+                $list = array_diff($list, array('.'));
+                foreach($list as $object) {
+                    if($object == "..") {
+                        if(in_array($_GET['path'], $CONFIG['paths'])) {
+                            echo "<a href=\"?path=\">Home</a><br>";
+                        } else {
+                            $paths = explode('/', $_GET['path']);
+                            $paths = array_diff($paths, array($paths[sizeof($paths) - 1]));
+                            $pathv = "";
+                            foreach($paths as $key => $path) {
+                                if($key == sizeof($paths) - 1) {
+                                    $pathv .= $path;
+                                } else {
+                                    $pathv .= $path . "/";
+                                }
                             }
+                            echo "<a href=\"?path=" . $pathv . "\">" . $object . "</a><br>";
                         }
-                        echo "<a href=\"?path=" . $pathv . "\">" . $object . "</a><br>";
+                    } else {
+                        echo "<a href=\"?path=" . $_GET['path'] . "/" .  $object . "\">" . $object . "</a><br>";
                     }
-                } else {
-                    echo "<a href=\"?path=" . $_GET['path'] . "/" .  $object . "\">" . $object . "</a><br>";
                 }
-            }
-        } else {
-            $paths = explode('/', $_GET['path']);
-            $paths = array_diff($paths, array($paths[sizeof($paths) - 1]));
-            $pathv = "";
-            foreach($paths as $key => $path) {
-                if($key == sizeof($paths) - 1) {
-                    $pathv .= $path;
-                } else {
-                    $pathv .= $path . "/";
+            } else {
+                $paths = explode('/', $_GET['path']);
+                $paths = array_diff($paths, array($paths[sizeof($paths) - 1]));
+                $pathv = "";
+                foreach($paths as $key => $path) {
+                    if($key == sizeof($paths) - 1) {
+                        $pathv .= $path;
+                    } else {
+                        $pathv .= $path . "/";
+                    }
                 }
-            }
 
-            $mime = explode(';', finfo_file(finfo_open(FILEINFO_MIME), $_GET['path']));
+                $mime = explode(';', finfo_file(finfo_open(FILEINFO_MIME), $_GET['path']));
 
-            echo "<a href=\"?path=" . $pathv . "\">Back</a> | <a href=\"readfile.php?file=" . $_GET['path'] . "\">Download</a><br>";
-            echo "<video width=\"auto\" height=\"auto\" controls>";
-            echo "<source src=\"readfile.php?file=" . $_GET['path'] . "\" type=\"" . $mime[0] . "\">";
-            echo "Your browser does not support the video tag.";
-            echo "</video>";
+                echo "<a href=\"?path=" . $pathv . "\">Back</a> | <a href=\"readfile.php?file=" . $_GET['path'] . "\">Download</a><br>";
+                echo "<video width=\"auto\" height=\"auto\" controls>";
+                echo "<source src=\"readfile.php?file=" . $_GET['path'] . "\" type=\"" . $mime[0] . "\">";
+                echo "Your browser does not support the video tag.";
+                echo "</video>";
+            }
         }
-    }
-    ?>
+        ?>
+
+        </div>
+
+        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
+        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js" integrity="sha512-K1qjQ+NcF2TYO/eI3M6v8EiNYZfA95pQumfvcVrTHtwQVDG+aHRqLi/ETn2uB+1JqwYqVG3LIvdm9lj6imS/pQ==" crossorigin="anonymous"></script>
     </body>
 </html>

+ 149 - 0
updateMetadata.php

@@ -0,0 +1,149 @@
+<?php
+require('functions.php');
+
+$apiURL = "http://thetvdb.com/api/084F3E73D176AD88/";
+$bannerURL = "http://www.thetvdb.com/banners/";
+
+if(!file_exists("posters")) {
+    mkdir("posters");
+}
+
+// http://www.thetvdb.com/wiki/index.php/Programmers_API
+
+// Step 2 (dev)
+
+$languages = curl_download($apiURL . "languages.xml");
+$languages = new SimpleXMLElement($languages);
+
+$german = $languages->xpath('/Languages/Language/abbreviation[.="de"]/parent::*');
+$english = $languages->xpath('/Languages/Language/abbreviation[.="en"]/parent::*');
+
+// Step 1
+
+$mirrors = curl_download($apiURL . "mirrors.xml");
+$mirrors = new SimpleXMLElement($mirrors);
+
+// xml mirrors
+
+$xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="1"]/parent::*');
+
+if(sizeof($xmlMirrors < 1)) {
+    $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
+
+    if(sizeof($xmlMirrors < 1)) {
+        $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
+
+        if(sizeof($xmlMirrors < 1)) {
+            $xmlMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
+        }
+    }
+}
+
+// banner mirrors
+
+$bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="2"]/parent::*');
+
+if(sizeof($bannerMirrors < 1)) {
+    $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="3"]/parent::*');
+
+    if(sizeof($bannerMirrors < 1)) {
+        $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
+
+        if(sizeof($bannerMirrors < 1)) {
+            $bannerMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
+        }
+    }
+}
+
+// zip mirrors
+
+$zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="4"]/parent::*');
+
+if(sizeof($zipMirrors < 1)) {
+    $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="5"]/parent::*');
+
+    if(sizeof($zipMirrors < 1)) {
+        $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="6"]/parent::*');
+
+        if(sizeof($zipMirrors < 1)) {
+            $zipMirrors = $mirrors->xpath('/Mirrors/Mirror/typemask[.="7"]/parent::*');
+        }
+    }
+}
+
+// Step 2
+
+$serverTime = curl_download("http://thetvdb.com/api/Updates.php?type=none");
+$serverTime = new SimpleXMLElement($serverTime);
+
+// Step 3
+
+if(isset($_REQUEST['action']) && $_REQUEST['action'] == "singleDownload") {
+    $seriesName = $_REQUEST['seriesname'];
+    $seriesID = $_REQUEST['seriesid'];
+
+    $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
+
+    if(strpos($series, 'Not Found') !== false) {
+        $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
+    }
+
+    $series = new SimpleXMLElement($series);
+    $poster = (string) $series->Series->poster;
+    $poster = $bannerURL . $poster;
+
+    file_put_contents("posters/" . $seriesName . ".jpg", fopen($poster, 'r'));
+
+} else {
+
+    $list = scandir("/media/Serien");
+    $list = array_diff($list, array('.', '..'));
+
+    foreach($list as $name) {
+
+        echo $name . "<br>";
+
+        if(file_exists("posters/" . $name . ".jpg")) {
+            echo "skipping..<br><br>";
+            continue;
+        }
+
+
+        $series = curl_download("http://thetvdb.com/api/GetSeries.php?seriesname=" . urlencode($name));
+        $series = new SimpleXMLElement($series);
+
+        if(sizeof($series) > 1) {
+
+            foreach($series as $serie) {
+                pa($serie);
+                echo "<a target=\"_blank\" href=\"?action=singleDownload&seriesname=" . (string) $serie->SeriesName . "&seriesid=" . (string) $serie->seriesid . "\">Load</a><br>";
+            }
+        } else {
+            $seriesID = (string) $series->Series->seriesid[0];
+
+            $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $german[0]->abbreviation . ".xml");
+
+            if(strpos($series, 'Not Found') !== false) {
+                $series = curl_download($apiURL . "series/" . $seriesID . "/" . (string) $english[0]->abbreviation . ".xml");
+            }
+
+            $series = new SimpleXMLElement($series);
+            $poster = (string) $series->Series->poster;
+            $poster = $bannerURL . $poster;
+
+            file_put_contents("posters/" . $name . ".jpg", fopen($poster, 'r'));
+        }
+
+    }
+}
+
+
+
+
+
+
+
+
+
+
+?>