add option to enable disable the tmdb support
This commit is contained in:
		@@ -2,7 +2,7 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
class SSettings
 | 
					class SSettings
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
    private $database;
 | 
					    private ?Database $database;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /**
 | 
					    /**
 | 
				
			||||||
     * SSettings constructor.
 | 
					     * SSettings constructor.
 | 
				
			||||||
@@ -19,4 +19,21 @@ class SSettings
 | 
				
			|||||||
        $r = mysqli_fetch_assoc($result);
 | 
					        $r = mysqli_fetch_assoc($result);
 | 
				
			||||||
        return $r['video_path'];
 | 
					        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
 | 
					<?php
 | 
				
			||||||
require 'Database.php';
 | 
					require 'Database.php';
 | 
				
			||||||
 | 
					require 'SSettings.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$conn = Database::getInstance()->getConnection();
 | 
					$conn = Database::getInstance()->getConnection();
 | 
				
			||||||
 | 
					$settings = new SSettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
if (isset($_POST['action'])) {
 | 
					if (isset($_POST['action'])) {
 | 
				
			||||||
    $action = $_POST['action'];
 | 
					    $action = $_POST['action'];
 | 
				
			||||||
@@ -15,11 +17,10 @@ if (isset($_POST['action'])) {
 | 
				
			|||||||
            }
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $r = mysqli_fetch_assoc($result);
 | 
					            $r = mysqli_fetch_assoc($result);
 | 
				
			||||||
            if ($r['password'] != "-1") {
 | 
					            // booleans need to be set manually
 | 
				
			||||||
                $r['passwordEnabled'] = true;
 | 
					            $r['passwordEnabled']  = $r['password'] != "-1";
 | 
				
			||||||
            } else {
 | 
					            $r['TMDB_grabbing'] = ($r['TMDB_grabbing'] != '0');
 | 
				
			||||||
                $r['passwordEnabled'] = false;
 | 
					
 | 
				
			||||||
            }
 | 
					 | 
				
			||||||
            echo json_encode($r);
 | 
					            echo json_encode($r);
 | 
				
			||||||
            break;
 | 
					            break;
 | 
				
			||||||
        case "saveGeneralSettings":
 | 
					        case "saveGeneralSettings":
 | 
				
			||||||
@@ -27,12 +28,14 @@ if (isset($_POST['action'])) {
 | 
				
			|||||||
            $password = $_POST['password'];
 | 
					            $password = $_POST['password'];
 | 
				
			||||||
            $videopath = $_POST['videopath'];
 | 
					            $videopath = $_POST['videopath'];
 | 
				
			||||||
            $tvshowpath = $_POST['tvshowpath'];
 | 
					            $tvshowpath = $_POST['tvshowpath'];
 | 
				
			||||||
 | 
					            $tmdbsupport = $_POST['tmdbsupport'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $query = "UPDATE settings SET 
 | 
					            $query = "UPDATE settings SET 
 | 
				
			||||||
                        video_path='$videopath',
 | 
					                        video_path='$videopath',
 | 
				
			||||||
                        episode_path='$tvshowpath',
 | 
					                        episode_path='$tvshowpath',
 | 
				
			||||||
                        password='$password',
 | 
					                        password='$password',
 | 
				
			||||||
                        mediacenter_name='$mediacentername'
 | 
					                        mediacenter_name='$mediacentername',
 | 
				
			||||||
 | 
					                        TMDB_grabbing=$tmdbsupport
 | 
				
			||||||
                    WHERE 1";
 | 
					                    WHERE 1";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($conn->query($query) === true) {
 | 
					            if ($conn->query($query) === true) {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,6 +1,7 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
require 'Database.php';
 | 
					require 'Database.php';
 | 
				
			||||||
require 'TMDBMovie.php';
 | 
					require 'TMDBMovie.php';
 | 
				
			||||||
 | 
					require 'SSettings.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
writeLog("starting extraction!\n");
 | 
					writeLog("starting extraction!\n");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -10,9 +11,12 @@ $tmdb = new TMDBMovie();
 | 
				
			|||||||
$tmdbgenres = $tmdb->getAllGenres();
 | 
					$tmdbgenres = $tmdb->getAllGenres();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$conn = Database::getInstance()->getConnection();
 | 
					$conn = Database::getInstance()->getConnection();
 | 
				
			||||||
 | 
					$settings = new SSettings();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$scandir = "../videos/prn/";
 | 
					// load video path from settings
 | 
				
			||||||
 | 
					$scandir = "../" . $settings->getVideoPath();
 | 
				
			||||||
$arr = scandir($scandir);
 | 
					$arr = scandir($scandir);
 | 
				
			||||||
 | 
					$TMDB_enabled = $settings->isTMDBGrabbingEnabled();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$all = 0;
 | 
					$all = 0;
 | 
				
			||||||
$added = 0;
 | 
					$added = 0;
 | 
				
			||||||
@@ -33,14 +37,21 @@ foreach ($arr as $elem) {
 | 
				
			|||||||
                $poster = -1;
 | 
					                $poster = -1;
 | 
				
			||||||
                $genres = -1;
 | 
					                $genres = -1;
 | 
				
			||||||
                if (!is_null($dta = $tmdb->searchMovie($moviename))) {
 | 
					                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");
 | 
					                    $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
 | 
					                    // check if tmdb support is enabled
 | 
				
			||||||
                    if (!$pic) {
 | 
					                    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;
 | 
					                        $pic = $poster;
 | 
				
			||||||
                        $poster = -1;
 | 
					                        $poster = -1;
 | 
				
			||||||
                        echo "Failed to load Picture from TMDB!  \n";
 | 
					 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    $genres = $dta->genre_ids;
 | 
					                    $genres = $dta->genre_ids;
 | 
				
			||||||
 
 | 
				
			|||||||
							
								
								
									
										13
									
								
								database.sql
									
									
									
									
									
								
							
							
						
						
									
										13
									
								
								database.sql
									
									
									
									
									
								
							@@ -29,9 +29,22 @@ create table if not exists video_tags
 | 
				
			|||||||
        foreign key (video_id) references videos (movie_id)
 | 
					        foreign key (video_id) references videos (movie_id)
 | 
				
			||||||
);
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					create table settings
 | 
				
			||||||
 | 
					(
 | 
				
			||||||
 | 
					    id enum(1) NOT NULL default 0,
 | 
				
			||||||
 | 
					    video_path       varchar(255)                          null,
 | 
				
			||||||
 | 
					    episode_path     varchar(255)                          null,
 | 
				
			||||||
 | 
					    password         varchar(32) default '-1'              null,
 | 
				
			||||||
 | 
					    mediacenter_name varchar(32) default 'OpenMediaCenter' null,
 | 
				
			||||||
 | 
					    PRIMARY KEY (id)
 | 
				
			||||||
 | 
					);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
INSERT INTO tags (tag_id, tag_name)
 | 
					INSERT INTO tags (tag_id, tag_name)
 | 
				
			||||||
VALUES (2, 'fullhd');
 | 
					VALUES (2, 'fullhd');
 | 
				
			||||||
INSERT INTO tags (tag_id, tag_name)
 | 
					INSERT INTO tags (tag_id, tag_name)
 | 
				
			||||||
VALUES (3, 'lowquality');
 | 
					VALUES (3, 'lowquality');
 | 
				
			||||||
INSERT INTO tags (tag_id, tag_name)
 | 
					INSERT INTO tags (tag_id, tag_name)
 | 
				
			||||||
VALUES (4, 'hd');
 | 
					VALUES (4, 'hd');
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INSERT INTO settings (video_path, episode_path, password, mediacenter_name)
 | 
				
			||||||
 | 
					VALUES ('./videos/', './tvshows/', -1, 'OpenMediaCenter');
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -110,4 +110,21 @@ describe('<CategoryPage/>', function () {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        expect(func).toBeCalledTimes(1);
 | 
					        expect(func).toBeCalledTimes(1);
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('test sidebar tag clicks', function () {
 | 
				
			||||||
 | 
					        const func = jest.fn();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        const wrapper = mount(<CategoryPage category="fullhd"/>);
 | 
				
			||||||
 | 
					        wrapper.instance().loadTag = func;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        console.log(wrapper.debug());
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expect(func).toBeCalledTimes(0);
 | 
				
			||||||
 | 
					        wrapper.find("SideBar").find("Tag").forEach(e => {
 | 
				
			||||||
 | 
					            e.simulate("click");
 | 
				
			||||||
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expect(func).toBeCalledTimes(4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -8,6 +8,7 @@ class GeneralSettings extends React.Component {
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        this.state = {
 | 
					        this.state = {
 | 
				
			||||||
            passwordsupport: false,
 | 
					            passwordsupport: false,
 | 
				
			||||||
 | 
					            tmdbsupport: null,
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            videopath: "",
 | 
					            videopath: "",
 | 
				
			||||||
            tvshowpath: "",
 | 
					            tvshowpath: "",
 | 
				
			||||||
@@ -23,12 +24,14 @@ class GeneralSettings extends React.Component {
 | 
				
			|||||||
        fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
 | 
					        fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
 | 
				
			||||||
            .then((response) => response.json()
 | 
					            .then((response) => response.json()
 | 
				
			||||||
                .then((result) => {
 | 
					                .then((result) => {
 | 
				
			||||||
 | 
					                    console.log(result);
 | 
				
			||||||
                    this.setState({
 | 
					                    this.setState({
 | 
				
			||||||
                        videopath: result.video_path,
 | 
					                        videopath: result.video_path,
 | 
				
			||||||
                        tvshowpath: result.episode_path,
 | 
					                        tvshowpath: result.episode_path,
 | 
				
			||||||
                        mediacentername: result.mediacenter_name,
 | 
					                        mediacentername: result.mediacenter_name,
 | 
				
			||||||
                        password: result.password,
 | 
					                        password: result.password,
 | 
				
			||||||
                        passwordsupport: result.passwordEnabled
 | 
					                        passwordsupport: result.passwordEnabled,
 | 
				
			||||||
 | 
					                        tmdbsupport: result.TMDB_grabbing
 | 
				
			||||||
                    });
 | 
					                    });
 | 
				
			||||||
                }));
 | 
					                }));
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@@ -67,6 +70,17 @@ class GeneralSettings extends React.Component {
 | 
				
			|||||||
                            }}
 | 
					                            }}
 | 
				
			||||||
                        />
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        <Form.Check
 | 
				
			||||||
 | 
					                            type="switch"
 | 
				
			||||||
 | 
					                            id="custom-switch-2"
 | 
				
			||||||
 | 
					                            data-testid='tmdb-switch'
 | 
				
			||||||
 | 
					                            label="Enable TMDB video grabbing support"
 | 
				
			||||||
 | 
					                            checked={this.state.tmdbsupport}
 | 
				
			||||||
 | 
					                            onChange={() => {
 | 
				
			||||||
 | 
					                                this.setState({tmdbsupport: !this.state.tmdbsupport})
 | 
				
			||||||
 | 
					                            }}
 | 
				
			||||||
 | 
					                        />
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                        {this.state.passwordsupport ?
 | 
					                        {this.state.passwordsupport ?
 | 
				
			||||||
                            <Form.Group data-testid="passwordfield">
 | 
					                            <Form.Group data-testid="passwordfield">
 | 
				
			||||||
                                <Form.Label>Password</Form.Label>
 | 
					                                <Form.Label>Password</Form.Label>
 | 
				
			||||||
@@ -98,6 +112,7 @@ class GeneralSettings extends React.Component {
 | 
				
			|||||||
        updateRequest.append('videopath', this.state.videopath);
 | 
					        updateRequest.append('videopath', this.state.videopath);
 | 
				
			||||||
        updateRequest.append('tvshowpath', this.state.tvshowpath);
 | 
					        updateRequest.append('tvshowpath', this.state.tvshowpath);
 | 
				
			||||||
        updateRequest.append('mediacentername', this.state.mediacentername);
 | 
					        updateRequest.append('mediacentername', this.state.mediacentername);
 | 
				
			||||||
 | 
					        updateRequest.append("tmdbsupport", this.state.tmdbsupport);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
 | 
					        fetch('/api/Settings.php', {method: 'POST', body: updateRequest})
 | 
				
			||||||
            .then((response) => response.json()
 | 
					            .then((response) => response.json()
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -98,4 +98,13 @@ describe('<GeneralSettings/>', function () {
 | 
				
			|||||||
        wrapper.find("[data-testid='passwordfield']").find("FormControl").simulate("change", event);
 | 
					        wrapper.find("[data-testid='passwordfield']").find("FormControl").simulate("change", event);
 | 
				
			||||||
        expect(wrapper.state().password).toBe("test");
 | 
					        expect(wrapper.state().password).toBe("test");
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    it('test tmdbsupport change event', function () {
 | 
				
			||||||
 | 
					        const wrapper = shallow(<GeneralSettings/>);
 | 
				
			||||||
 | 
					        wrapper.setState({tmdbsupport: true});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        expect(wrapper.state().tmdbsupport).toBe(true);
 | 
				
			||||||
 | 
					        wrapper.find("[data-testid='tmdb-switch']").simulate("change");
 | 
				
			||||||
 | 
					        expect(wrapper.state().tmdbsupport).toBe(false);
 | 
				
			||||||
 | 
					    });
 | 
				
			||||||
});
 | 
					});
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user