parse videos with TMDB
better size of video tiles
This commit is contained in:
		
							
								
								
									
										34
									
								
								api/TMDBMovie.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								api/TMDBMovie.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,34 @@
 | 
				
			|||||||
 | 
					<?php
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					class TMDBMovie
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					    private $apikey = "9fd90530b11447f5646f8e6fb4733fb4";
 | 
				
			||||||
 | 
					    private $baseurl = "https://api.themoviedb.org/3/";
 | 
				
			||||||
 | 
					    public $picturebase = "https://image.tmdb.org/t/p/w500";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    public function searchMovie($moviename)
 | 
				
			||||||
 | 
					    {
 | 
				
			||||||
 | 
					        $reply = json_decode(file_get_contents($this->baseurl . "search/movie?api_key=" . $this->apikey . "&query=" . urlencode($moviename)));
 | 
				
			||||||
 | 
					        if ($reply->total_results == 0) {
 | 
				
			||||||
 | 
					            // no results found
 | 
				
			||||||
 | 
					            // todo maybe parse first pictures somehow
 | 
				
			||||||
 | 
					            return null;
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return $reply->results[0];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					//            $image_base64 = base64_encode(file_get_contents($this->posterbase . $reply->results[0]->poster_path));
 | 
				
			||||||
 | 
					//            $image = 'data:image/jpeg;base64,' . $image_base64;
 | 
				
			||||||
 | 
					//            // Insert record
 | 
				
			||||||
 | 
					//            $conn = Database::getInstance()->getConnection();
 | 
				
			||||||
 | 
					//            $query = "insert into Movie(name,url,poster) values('" . pathinfo($i)['filename'] . "','/data/$i','" . $image . "')";
 | 
				
			||||||
 | 
					//            if ($conn->query($query) === TRUE) {
 | 
				
			||||||
 | 
					//                echo('{"data":"successfully created entry"}');
 | 
				
			||||||
 | 
					//            } else {
 | 
				
			||||||
 | 
					//                echo('{"data":"' . $conn->error . '"}');
 | 
				
			||||||
 | 
					//            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					$temp = new TMDBMovie();
 | 
				
			||||||
 | 
					$temp->searchMovie("007 - Ein quantum Trost");
 | 
				
			||||||
@@ -1,10 +1,14 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
require 'Database.php';
 | 
					require 'Database.php';
 | 
				
			||||||
 | 
					require 'TMDBMovie.php';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$ffmpeg = 'ffmpeg'; //or: /usr/bin/ffmpeg , or /usr/local/bin/ffmpeg - depends on your installation (type which ffmpeg into a console to find the install path)
 | 
					$ffmpeg = 'ffmpeg'; //or: /usr/bin/ffmpeg , or /usr/local/bin/ffmpeg - depends on your installation (type which ffmpeg into a console to find the install path)
 | 
				
			||||||
 | 
					$tmdb = new TMDBMovie();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$conn = Database::getInstance()->getConnection();
 | 
					$conn = Database::getInstance()->getConnection();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$arr = scandir("../videos/prn/");
 | 
					$scandir = "../videos/prn/";
 | 
				
			||||||
 | 
					$arr = scandir($scandir);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
$all = 0;
 | 
					$all = 0;
 | 
				
			||||||
$added = 0;
 | 
					$added = 0;
 | 
				
			||||||
@@ -13,63 +17,74 @@ $failed = 0;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
foreach ($arr as $elem) {
 | 
					foreach ($arr as $elem) {
 | 
				
			||||||
    if ($elem != "." && $elem != "..") {
 | 
					    if ($elem != "." && $elem != "..") {
 | 
				
			||||||
 | 
					        if (strpos($elem, '.mp4') !== false) {
 | 
				
			||||||
 | 
					            $moviename = substr($elem, 0, -4);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        $query = "SELECT * FROM videos WHERE movie_name = '" . mysqli_real_escape_string($conn, $elem) . "'";
 | 
					            $query = "SELECT * FROM videos WHERE movie_name = '" . mysqli_real_escape_string($conn, $moviename) . "'";
 | 
				
			||||||
        $result = $conn->query($query);
 | 
					            $result = $conn->query($query);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // insert if not available in db
 | 
					            // insert if not available in db
 | 
				
			||||||
        if (!mysqli_fetch_assoc($result)) {
 | 
					            if (!mysqli_fetch_assoc($result)) {
 | 
				
			||||||
            $pic = 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");
 | 
					                // try to fetch data from TMDB
 | 
				
			||||||
 | 
					                if (!is_null($dta = $tmdb->searchMovie($moviename))) {
 | 
				
			||||||
 | 
					                    $pic = file_get_contents($tmdb->picturebase . $dta->poster_path);
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    echo "nothing found with TMDB!\n";
 | 
				
			||||||
 | 
					                    $pic = 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");
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $image_base64 = base64_encode($pic);
 | 
					                $image_base64 = base64_encode($pic);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $image = 'data:image/jpeg;base64,' . $image_base64;
 | 
					                $image = 'data:image/jpeg;base64,' . $image_base64;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $video_attributes = _get_video_attributes($elem);
 | 
					                $video_attributes = _get_video_attributes($elem);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $duration = 60 * $video_attributes['hours'] + $video_attributes['mins'];
 | 
					                $duration = 60 * $video_attributes['hours'] + $video_attributes['mins'];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            $query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length) 
 | 
					                $query = "INSERT INTO videos(movie_name,movie_url,thumbnail,quality,length) 
 | 
				
			||||||
                            VALUES ('" . mysqli_real_escape_string($conn, $elem) . "',
 | 
					                            VALUES ('" . mysqli_real_escape_string($conn, $moviename) . "',
 | 
				
			||||||
                            '" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "',
 | 
					                            '" . mysqli_real_escape_string($conn, 'videos/prn/' . $elem) . "',
 | 
				
			||||||
                            '$image',
 | 
					                            '$image',
 | 
				
			||||||
                            '" . $video_attributes['height'] . "',
 | 
					                            '" . $video_attributes['height'] . "',
 | 
				
			||||||
                            '$duration')";
 | 
					                            '$duration')";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            if ($conn->query($query) === TRUE) {
 | 
					                if ($conn->query($query) === TRUE) {
 | 
				
			||||||
                echo('successfully added ' . $elem . " to video gravity\n");
 | 
					                    echo('successfully added ' . $elem . " to video gravity\n");
 | 
				
			||||||
                $last_id = $conn->insert_id;
 | 
					                    $last_id = $conn->insert_id;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                // full hd
 | 
					                    // full hd
 | 
				
			||||||
                if ($video_attributes['height'] >= 1080) {
 | 
					                    if ($video_attributes['height'] >= 1080) {
 | 
				
			||||||
                    $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)";
 | 
					                        $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,2)";
 | 
				
			||||||
                    if ($conn->query($query) !== TRUE) {
 | 
					                        if ($conn->query($query) !== TRUE) {
 | 
				
			||||||
                        echo "failed to add default tag here.\n";
 | 
					                            echo "failed to add default tag here.\n";
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if ($video_attributes['height'] >= 720 && $video_attributes['height'] < 1080) {
 | 
					                    if ($video_attributes['height'] >= 720 && $video_attributes['height'] < 1080) {
 | 
				
			||||||
                    $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)";
 | 
					                        $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,4)";
 | 
				
			||||||
                    if ($conn->query($query) !== TRUE) {
 | 
					                        if ($conn->query($query) !== TRUE) {
 | 
				
			||||||
                        echo "failed to add default tag here.\n";
 | 
					                            echo "failed to add default tag here.\n";
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
                if ($video_attributes['height'] < 720) {
 | 
					                    if ($video_attributes['height'] < 720) {
 | 
				
			||||||
                    $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)";
 | 
					                        $query = "INSERT INTO video_tags(video_id,tag_id) VALUES ($last_id,3)";
 | 
				
			||||||
                    if ($conn->query($query) !== TRUE) {
 | 
					                        if ($conn->query($query) !== TRUE) {
 | 
				
			||||||
                        echo "failed to add default tag here.\n";
 | 
					                            echo "failed to add default tag here.\n";
 | 
				
			||||||
 | 
					                        }
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					                    $added++;
 | 
				
			||||||
 | 
					                    $all++;
 | 
				
			||||||
 | 
					                } else {
 | 
				
			||||||
 | 
					                    echo('errored item: ' . $elem . "\n");
 | 
				
			||||||
 | 
					                    echo('{"data":"' . $conn->error . '"}\n');
 | 
				
			||||||
 | 
					                    $failed++;
 | 
				
			||||||
                }
 | 
					                }
 | 
				
			||||||
                $added++;
 | 
					 | 
				
			||||||
                $all++;
 | 
					 | 
				
			||||||
            } else {
 | 
					            } else {
 | 
				
			||||||
                echo('errored item: ' . $elem . "\n");
 | 
					                $all++;
 | 
				
			||||||
                echo('{"data":"' . $conn->error . '"}\n');
 | 
					 | 
				
			||||||
                $failed++;
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        } else {
 | 
					        }else{
 | 
				
			||||||
            $all++;
 | 
					            echo($elem . " does not contain a .mp4 extension! - skipping \n");
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -7,16 +7,17 @@
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
.previewpic {
 | 
					.previewpic {
 | 
				
			||||||
    height: 80%;
 | 
					    height: 80%;
 | 
				
			||||||
 | 
					    overflow: hidden;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.previewimage {
 | 
					.previewimage {
 | 
				
			||||||
    width: 100%;
 | 
					    width: 100%;
 | 
				
			||||||
    height: 100%;
 | 
					    overflow: hidden;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
.videopreview {
 | 
					.videopreview {
 | 
				
			||||||
    height: 300px;
 | 
					    height: 500px;
 | 
				
			||||||
    width: 30%;
 | 
					    width: 250px;
 | 
				
			||||||
    float: left;
 | 
					    float: left;
 | 
				
			||||||
    margin-left: 25px;
 | 
					    margin-left: 25px;
 | 
				
			||||||
    margin-top: 25px;
 | 
					    margin-top: 25px;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user