Advertisement
s4m33r789

dooo-app-automate

Aug 5th, 2024 (edited)
483
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 6.62 KB | Source Code | 0 0
  1. <?php
  2. // Enable error reporting for debugging
  3. // https://moviemates.cloud
  4. ini_set('display_errors', 1);
  5. ini_set('display_startup_errors', 1);
  6. error_reporting(E_ALL);
  7.  
  8. $tmdbApiKey = '1bfdbff05c2698dc917dd28c08d41096';
  9.  
  10. // Database connection
  11. $host = 'localhost';
  12. $dbname = 'fire';
  13. $username = 'fire';
  14. $password = 'fire@789';
  15.  
  16. try {
  17.     $conn = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
  18.     $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  19. } catch (PDOException $e) {
  20.     die("Database connection failed: " . $e->getMessage());
  21. }
  22.  
  23. // Function to fetch YouTube trailer
  24. function fetchYouTubeTrailer($tmdbId, $apiKey) {
  25.     $url = "https://api.themoviedb.org/3/movie/$tmdbId/videos?api_key=$apiKey";
  26.     $data = file_get_contents($url);
  27.     $videos = json_decode($data, true);
  28.  
  29.     foreach ($videos['results'] as $video) {
  30.         if ($video['site'] == 'YouTube' && $video['type'] == 'Trailer') {
  31.             return 'https://www.youtube.com/watch?v=' . $video['key'];
  32.         }
  33.     }
  34.     return '';
  35. }
  36.  
  37. if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['tmdb_ids'])) {
  38.     $tmdbIds = explode(',', $_POST['tmdb_ids']);
  39.  
  40.     foreach ($tmdbIds as $tmdbId) {
  41.         $tmdbId = trim($tmdbId);
  42.         // Fetch movie data from TMDb
  43.         $tmdbUrl = "https://api.themoviedb.org/3/movie/$tmdbId?api_key=$tmdbApiKey";
  44.         $tmdbData = file_get_contents($tmdbUrl);
  45.         $movieData = json_decode($tmdbData, true);
  46.  
  47.         if (!empty($movieData)) {
  48.             $name = $movieData['title'];
  49.             $description = $movieData['overview'];
  50.             $genres = implode(', ', array_map(function($genre) { return $genre['name']; }, $movieData['genres']));
  51.             $release_date = $movieData['release_date'];
  52.             $runtime = $movieData['runtime'];
  53.             $poster = 'https://image.tmdb.org/t/p/w500' . $movieData['poster_path'];
  54.             $banner = 'https://image.tmdb.org/t/p/w500' . $movieData['backdrop_path'];
  55.             $youtube_trailer = fetchYouTubeTrailer($tmdbId, $tmdbApiKey);
  56.  
  57.             // Insert movie data into movies table
  58.             try {
  59.                 $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)");
  60.                 $stmt->execute([
  61.                     ':tmdb_id' => $tmdbId,
  62.                     ':name' => $name,
  63.                     ':description' => $description,
  64.                     ':genres' => $genres,
  65.                     ':release_date' => $release_date,
  66.                     ':runtime' => $runtime,
  67.                     ':poster' => $poster,
  68.                     ':banner' => $banner,
  69.                     ':youtube_trailer' => $youtube_trailer,
  70.                     ':downloadable' => 0,
  71.                     ':type' => 0,
  72.                     ':status' => 1,
  73.                     ':content_type' => 1,
  74.                 ]);
  75.  
  76.                 // Retrieve the movie_id based on the inserted TMDB_ID
  77.                 $stmt = $conn->prepare("SELECT id FROM movies WHERE TMDB_ID = :tmdb_id");
  78.                 $stmt->execute([':tmdb_id' => $tmdbId]);
  79.                 $movie = $stmt->fetch(PDO::FETCH_ASSOC);
  80.                 $movie_id = $movie['id'] ?? null;
  81.  
  82.                 if ($movie_id) {
  83.                     // Insert movie play links using the retrieved movie_id
  84.                     try {
  85.                         $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)");
  86.                         $stmt->execute([
  87.                             ':name' => 'server 1',
  88.                             ':size' => '2.0GB',
  89.                             ':quality' => '1080p',
  90.                             ':link_order' => 1,
  91.                             ':movie_id' => $movie_id,
  92.                             ':url' => "https://moviemates.cloud/embed/$tmdbId",
  93.                             ':type' => 'Embed',
  94.                             ':status' => 1,
  95.                             ':skip_available' => 0,
  96.                             ':intro_start' => '',
  97.                             ':intro_end' => '',
  98.                             ':end_credits_marker' => '',
  99.                             ':link_type' => 0,
  100.                             ':drm_uuid' => '',
  101.                             ':drm_license_uri' => '',
  102.                         ]);
  103.                     } catch (PDOException $e) {
  104.                         echo "Error inserting movie play link data for TMDb ID $tmdbId: " . $e->getMessage();
  105.                     }
  106.                 } else {
  107.                     echo "Error: Movie ID not found for TMDb ID $tmdbId";
  108.                 }
  109.             } catch (PDOException $e) {
  110.                 echo "Error inserting movie data: " . $e->getMessage();
  111.             }
  112.         }
  113.     }
  114.  
  115.     // Clear the input after processing
  116.     header("Location: " . $_SERVER['PHP_SELF']);
  117.     exit();
  118. }
  119. ?>
  120.  
  121. <!DOCTYPE html>
  122. <html lang="en">
  123. <head>
  124.     <meta charset="UTF-8">
  125.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  126.     <title>Import Movies</title>
  127.     <style>
  128.         body { font-family: Arial, sans-serif; background-color: #f4f4f4; margin: 0; padding: 0; }
  129.         .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); }
  130.         h1 { text-align: center; margin-bottom: 20px; }
  131.         form { display: flex; flex-direction: column; }
  132.         label { margin-bottom: 10px; }
  133.         input[type="text"] { padding: 10px; margin-bottom: 20px; border: 1px solid #ddd; border-radius: 4px; }
  134.         input[type="submit"] { padding: 10px; background: #007BFF; color: #fff; border: none; border-radius: 4px; cursor: pointer; }
  135.         input[type="submit"]:hover { background: #0056b3; }
  136.     </style>
  137. </head>
  138. <body>
  139.     <div class="container">
  140.         <h1>Import Movies</h1>
  141.         <form method="post" action="">
  142.             <label for="tmdb_ids">Enter TMDb IDs (comma separated):</label>
  143.             <input type="text" id="tmdb_ids" name="tmdb_ids" required>
  144.             <input type="submit" value="Import">
  145.         </form>
  146.     </div>
  147. </body>
  148. </html>
  149.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement