add option to enable disable the tmdb support
This commit is contained in:
		@@ -2,7 +2,7 @@
 | 
			
		||||
 | 
			
		||||
class SSettings
 | 
			
		||||
{
 | 
			
		||||
    private $database;
 | 
			
		||||
    private ?Database $database;
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * SSettings constructor.
 | 
			
		||||
@@ -19,4 +19,21 @@ class SSettings
 | 
			
		||||
        $r = mysqli_fetch_assoc($result);
 | 
			
		||||
        return $r['video_path'];
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * check if TMDB is enableds
 | 
			
		||||
     * @return bool isenabled?
 | 
			
		||||
     */
 | 
			
		||||
    public function isTMDBGrabbingEnabled(): bool
 | 
			
		||||
    {
 | 
			
		||||
        $query = "SELECT TMDB_grabbing from settings";
 | 
			
		||||
 | 
			
		||||
        $result = $this->database->getConnection()->query($query);
 | 
			
		||||
        if(!$result){
 | 
			
		||||
            return true; // if undefined in db --> default true
 | 
			
		||||
        }else{
 | 
			
		||||
            $r = mysqli_fetch_assoc($result);
 | 
			
		||||
            return $r['TMDB_grabbing'] == '1';
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -1,7 +1,9 @@
 | 
			
		||||
<?php
 | 
			
		||||
require 'Database.php';
 | 
			
		||||
require 'SSettings.php';
 | 
			
		||||
 | 
			
		||||
$conn = Database::getInstance()->getConnection();
 | 
			
		||||
$settings = new SSettings();
 | 
			
		||||
 | 
			
		||||
if (isset($_POST['action'])) {
 | 
			
		||||
    $action = $_POST['action'];
 | 
			
		||||
@@ -15,11 +17,10 @@ if (isset($_POST['action'])) {
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            $r = mysqli_fetch_assoc($result);
 | 
			
		||||
            if ($r['password'] != "-1") {
 | 
			
		||||
                $r['passwordEnabled'] = true;
 | 
			
		||||
            } else {
 | 
			
		||||
                $r['passwordEnabled'] = false;
 | 
			
		||||
            }
 | 
			
		||||
            // booleans need to be set manually
 | 
			
		||||
            $r['passwordEnabled']  = $r['password'] != "-1";
 | 
			
		||||
            $r['TMDB_grabbing'] = ($r['TMDB_grabbing'] != '0');
 | 
			
		||||
 | 
			
		||||
            echo json_encode($r);
 | 
			
		||||
            break;
 | 
			
		||||
        case "saveGeneralSettings":
 | 
			
		||||
@@ -27,12 +28,14 @@ if (isset($_POST['action'])) {
 | 
			
		||||
            $password = $_POST['password'];
 | 
			
		||||
            $videopath = $_POST['videopath'];
 | 
			
		||||
            $tvshowpath = $_POST['tvshowpath'];
 | 
			
		||||
            $tmdbsupport = $_POST['tmdbsupport'];
 | 
			
		||||
 | 
			
		||||
            $query = "UPDATE settings SET 
 | 
			
		||||
                        video_path='$videopath',
 | 
			
		||||
                        episode_path='$tvshowpath',
 | 
			
		||||
                        password='$password',
 | 
			
		||||
                        mediacenter_name='$mediacentername'
 | 
			
		||||
                        mediacenter_name='$mediacentername',
 | 
			
		||||
                        TMDB_grabbing=$tmdbsupport
 | 
			
		||||
                    WHERE 1";
 | 
			
		||||
 | 
			
		||||
            if ($conn->query($query) === true) {
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
<?php
 | 
			
		||||
require 'Database.php';
 | 
			
		||||
require 'TMDBMovie.php';
 | 
			
		||||
require 'SSettings.php';
 | 
			
		||||
 | 
			
		||||
writeLog("starting extraction!\n");
 | 
			
		||||
 | 
			
		||||
@@ -10,9 +11,12 @@ $tmdb = new TMDBMovie();
 | 
			
		||||
$tmdbgenres = $tmdb->getAllGenres();
 | 
			
		||||
 | 
			
		||||
$conn = Database::getInstance()->getConnection();
 | 
			
		||||
$settings = new SSettings();
 | 
			
		||||
 | 
			
		||||
$scandir = "../videos/prn/";
 | 
			
		||||
// load video path from settings
 | 
			
		||||
$scandir = "../" . $settings->getVideoPath();
 | 
			
		||||
$arr = scandir($scandir);
 | 
			
		||||
$TMDB_enabled = $settings->isTMDBGrabbingEnabled();
 | 
			
		||||
 | 
			
		||||
$all = 0;
 | 
			
		||||
$added = 0;
 | 
			
		||||
@@ -33,14 +37,21 @@ foreach ($arr as $elem) {
 | 
			
		||||
                $poster = -1;
 | 
			
		||||
                $genres = -1;
 | 
			
		||||
                if (!is_null($dta = $tmdb->searchMovie($moviename))) {
 | 
			
		||||
                    $pic = file_get_contents($tmdb->picturebase . $dta->poster_path);
 | 
			
		||||
                    $poster = shell_exec("ffmpeg -hide_banner -loglevel panic -ss 00:04:00 -i \"../videos/prn/$elem\" -vframes 1 -q:v 2 -f singlejpeg pipe:1 2>/dev/null");
 | 
			
		||||
 | 
			
		||||
                    // error handling for download error
 | 
			
		||||
                    if (!$pic) {
 | 
			
		||||
                    // check if tmdb support is enabled
 | 
			
		||||
                    if ($TMDB_enabled) {
 | 
			
		||||
                        $pic = file_get_contents($tmdb->picturebase . $dta->poster_path);
 | 
			
		||||
 | 
			
		||||
                        // error handling for download error
 | 
			
		||||
                        if (!$pic) {
 | 
			
		||||
                            $pic = $poster;
 | 
			
		||||
                            $poster = -1;
 | 
			
		||||
                            echo "Failed to load Picture from TMDB!  \n";
 | 
			
		||||
                        }
 | 
			
		||||
                    } else {
 | 
			
		||||
                        $pic = $poster;
 | 
			
		||||
                        $poster = -1;
 | 
			
		||||
                        echo "Failed to load Picture from TMDB!  \n";
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    $genres = $dta->genre_ids;
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user