Beispiel #1
0
    def get(self):
        YOUTUBE_EMBED_URL = "https://www.youtube.com/embed/"
        movie_name = self.request.get('movie_name').strip()
        params = dict(query=movie_name, api_key=API_KEY)
        url = TMDB_API_SEARCH_URL + "?" + urllib.urlencode(params)
        try:
            resp = urlfetch.fetch(url, validate_certificate=True)
            if resp.status_code != 200:
                raise ValueError("Error response: %s" % resp.code)
            res = json.loads(resp.content)
            results = []
            for movie_info in res.get('results'):
                title = (movie_info.get('title') or
                         movie_info.get('original_title'))
                overview = movie_info.get('overview')
                poster_path = movie_info.get('poster_path')
                if not poster_path:
                    continue
                poster_path = 'https://image.tmdb.org/t/p/w500' + poster_path
                movie_id = movie_info.get('id')

                # Get trailer url from imdb
                movie_url = TMDB_API_VIDEO_URL % (movie_id, API_KEY)
                logging.info('MOVIE URL : %s\n' % movie_url)
                resp = urlfetch.fetch(movie_url, validate_certificate=True)
                if resp.status_code != 200:
                    continue
                resp = json.loads(resp.content)
                resp = resp.get('results', [])
                if not resp:
                    continue
                trailer_url = YOUTUBE_EMBED_URL + resp[0].get('key')
                info = dict(title=title, overview=overview,
                            poster=poster_path,
                            trailer_url=trailer_url)
                results.append(info)
            if results:
                write_mako_template(self, 'templates/search.html',
                                    results=results)
            else:
                write_mako_template(self, 'templates/submit.html',
                                    error="No results found")

        except urlfetch.Error as e:
            logging.exception(e)
        except ValueError as e:
            logging.exception(e)
Beispiel #2
0
 def get(self):
     write_mako_template(self, 'templates/submit.html', error=None)
Beispiel #3
0
 def get(self):
     movies = Movie.get_all()
     write_mako_template(self, 'templates/main.html', movies=movies)
Beispiel #4
0
    def get(self, movie_id):
        movie = Movie.get_from_cache(movie_id)
        if not movie:
                return self.response.write('Movie not found')

        write_mako_template(self, 'templates/view_movie.html', movie=movie)