Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Enable error reporting for debugging
- // https://moviemates.cloud
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- $tmdbApiKey = '1bfdbff05c2698dc917dd28c08d41096';
- // Database connection
- $host = 'localhost';
- $dbname = 'fire';
- $username = 'fire';
- $password = 'fire@789';
- try {
- $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
- $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- } catch (PDOException $e) {
- die("Database connection failed: " . $e->getMessage());
- }
- // Function to fetch YouTube trailer
- function fetchYouTubeTrailer($tmdbId, $apiKey) {
- $url = "https://api.themoviedb.org/3/movie/$tmdbId/videos?api_key=$apiKey";
- $data = file_get_contents($url);
- $videos = json_decode($data, true);
- foreach ($videos['results'] as $video) {
- if ($video['site'] == 'YouTube' && $video['type'] == 'Trailer') {
- return 'https://www.youtube.com/watch?v=' . $video['key'];
- }
- }
- return '';
- }
- if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['tmdb_ids'])) {
- $tmdbIds = explode(',', $_POST['tmdb_ids']);
- foreach ($tmdbIds as $tmdbId) {
- $tmdbId = trim($tmdbId);
- // Fetch movie data from TMDb
- $tmdbUrl = "https://api.themoviedb.org/3/movie/$tmdbId?api_key=$tmdbApiKey";
- $tmdbData = file_get_contents($tmdbUrl);
- $movieData = json_decode($tmdbData, true);
- if (!empty($movieData)) {
- $name = $movieData['title'];
- $description = $movieData['overview'];
- $genres = implode(', ', array_map(function($genre) { return $genre['name']; }, $movieData['genres']));
- $release_date = $movieData['release_date'];
- $runtime = $movieData['runtime'];
- $poster = 'https://image.tmdb.org/t/p/w500' . $movieData['poster_path'];
- $banner = 'https://image.tmdb.org/t/p/w500' . $movieData['backdrop_path'];
- $youtube_trailer = fetchYouTubeTrailer($tmdbId, $tmdbApiKey);
- // Insert movie data into movies table
- try {
- $stmt = $conn->prepare("INSERT INTO movies (TMDB_ID, name, description, genres, release_date, runtime, poster, banner, youtube_trailer, downloadable, type, status, content_type) VALUES (:tmdb_id, :name, :description, :genres, :release_date, :runtime, :poster, :banner, :youtube_trailer, :downloadable, :type, :status, :content_type)");
- $stmt->execute([
- ':tmdb_id' => $tmdbId,
- ':name' => $name,
- ':description' => $description,
- ':genres' => $genres,
- ':release_date' => $release_date,
- ':runtime' => $runtime,
- ':poster' => $poster,
- ':banner' => $banner,
- ':youtube_trailer' => $youtube_trailer,
- ':downloadable' => 0,
- ':type' => 0,
- ':status' => 1,
- ':content_type' => 1,
- ]);
- // Retrieve the movie_id based on the inserted TMDB_ID
- $stmt = $conn->prepare("SELECT id FROM movies WHERE TMDB_ID = :tmdb_id");
- $stmt->execute([':tmdb_id' => $tmdbId]);
- $movie = $stmt->fetch(PDO::FETCH_ASSOC);
- $movie_id = $movie['id'] ?? null;
- if ($movie_id) {
- // Insert movie play links using the retrieved movie_id
- try {
- $stmt = $conn->prepare("INSERT INTO movie_play_links (name, size, quality, link_order, movie_id, url, type, status, skip_available, intro_start, intro_end, end_credits_marker, link_type, drm_uuid, drm_license_uri) VALUES (:name, :size, :quality, :link_order, :movie_id, :url, :type, :status, :skip_available, :intro_start, :intro_end, :end_credits_marker, :link_type, :drm_uuid, :drm_license_uri)");
- $stmt->execute([
- ':name' => 'server 1',
- ':size' => '2.0GB',
- ':quality' => '1080p',
- ':link_order' => 1,
- ':movie_id' => $movie_id,
- ':url' => "https://moviemates.cloud/embed/$tmdbId",
- ':type' => 'Embed',
- ':status' => 1,
- ':skip_available' => 0,
- ':intro_start' => '',
- ':intro_end' => '',
- ':end_credits_marker' => '',
- ':link_type' => 0,
- ':drm_uuid' => '',
- ':drm_license_uri' => '',
- ]);
- } catch (PDOException $e) {
- echo "Error inserting movie play link data for TMDb ID $tmdbId: " . $e->getMessage();
- }
- } else {
- echo "Error: Movie ID not found for TMDb ID $tmdbId";
- }
- } catch (PDOException $e) {
- echo "Error inserting movie data: " . $e->getMessage();
- }
- }
- }
- // Clear the input after processing
- header("Location: " . $_SERVER['PHP_SELF']);
- exit();
- }
- ?>
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Import Movies</title>
- <style>
- body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; }
- .container { max-width: 600px; margin: 50px auto; padding: 20px; background: #fff; border-radius: 8px; box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); }
- h1 { text-align: center; margin-bottom: 20px; }
- form { display: flex; flex-direction: column; }
- label { margin-bottom: 10px; }
- input[type="text"] { padding: 10px; margin-bottom: 20px; border: 1px solid #ddd; border-radius: 4px; }
- input[type="submit"] { padding: 10px; background: #007BFF; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
- input[type="submit"]:hover { background: #0056b3; }
- </style>
- </head>
- <body>
- <div class="container">
- <h1>Import Movies</h1>
- <form method="post" action="">
- <label for="tmdb_ids">Enter TMDb IDs (comma separated):</label>
- <input type="text" id="tmdb_ids" name="tmdb_ids" required>
- <input type="submit" value="Import">
- </form>
- </div>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement