From 96acb05f54aa9291731db4f575f8675a19204850 Mon Sep 17 00:00:00 2001 From: Chewbaka69 Date: Wed, 21 Nov 2018 14:39:59 +0100 Subject: [PATCH] Movie trailer --- fuel/app/classes/model/trailer.php | 99 ++++++++++++++++++++++++++++++ fuel/app/views/movie/index.php | 14 ++--- 2 files changed, 106 insertions(+), 7 deletions(-) create mode 100644 fuel/app/classes/model/trailer.php diff --git a/fuel/app/classes/model/trailer.php b/fuel/app/classes/model/trailer.php new file mode 100644 index 0000000..f1a13a0 --- /dev/null +++ b/fuel/app/classes/model/trailer.php @@ -0,0 +1,99 @@ +_title = $title; + $this->_year = $year; + $this->_type = $type; + + if($this->_type === 'movie') { + $this->getUrl(); + + if($this->_url === null) + return; + + $this->getMovieTrailer(); + + if(!$this->trailer) + $this->getMovieTeaser(); + + return $this->trailer; + } + } + + private function getUrl() + { + $html = Request::forge('https://www.themoviedb.org/search/movie?query=' . urlencode($this->_title) . '+y%3A' . $this->_year . '&language=us', 'curl'); + $html->execute(); + + if ($html->response()->status !== 200) + return false; + + $media = $html->response()->body; + + preg_match('//i', $media, $urls); + + if (!isset($urls[1])) + return false; + + $this->_url = explode('?', $urls[1])[0]; + } + + private function getMovieTrailer() + { + $html = Request::forge('https://www.themoviedb.org' . $this->_url . '/videos?active_nav_item=Trailers&video_language=en-US&language=en-US', 'curl'); + $html->set_options(array( + CURLOPT_FOLLOWLOCATION => true, + ) + ); + $html->execute(); + + if ($html->response()->status !== 200) + return false; + + $media = $html->response()->body; + + preg_match('/' + ''); }); + $(document).on('click', '#youtube-iframe', function (event) { + event.target.remove(); + }); /** LOAD IMG **/ $('.PosterCardImg-imageContainer-1Ar4M[data-movie-id]').each(function (index, element) { var movie_id = $(element).data('movie-id');