diff --git a/README.md b/README.md index 3a00f9a..ea150d1 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Use `!tmdb help` to get help about the bot usage. Use `!tmdb movie {title} [y:{release year}]` to get movie detail based on the given title. -Use `!tmdb popular` to get most popular movies. +Use `!tmdb popular [{rating}]` to get most popular movies. Get details about any one movie in the list by adding the {rating}. Use `!tmdb language {language}` to set your prefered language. diff --git a/tmdb/tmdb.py b/tmdb/tmdb.py index 37f0352..39dee77 100644 --- a/tmdb/tmdb.py +++ b/tmdb/tmdb.py @@ -74,7 +74,7 @@ class TmdbBot(Plugin): async def send_help(self, evt: MessageEvent) -> None: html = """
Use !tmdb movie {title} [y:{release year}] to get movie detail based on the given title.
-Use !tmdb popular to get most popular movies.
+Use !tmdb popular [{rating}] to get most popular movies. Get details about any one movie in the list by adding the {rating}.
Use !tmdb language {language} to set your prefered language.
Use !tmdb poster_size [{size}] to set your prefered poster size. With empty {size} all available sizes are listed.
Use !tmdb tvshow {title} to get detail about a tv show based on the given title.
""" @@ -151,14 +151,24 @@ class TmdbBot(Plugin): async def movie_popular(self, evt: MessageEvent, message: str = "") -> None: popular = await self.init_moviepopular() language = self.db.get_language(evt.sender) + self.poster_size(evt, popular) if language: popular.set_language(language) length = 5 await popular.query() - text = popular.getListText(length) - html = popular.getListHtml(length) - await self.send_html_message(evt, text, html) + + m = re.search(r'([1-5])', message) + if m: + number = m.group(1) + movie = await popular.getMovieByNumber(number) + if language: + movie.set_language(language) + await self.send_movie_info(evt, movie) + else: + text = popular.getListText(length) + html = popular.getListHtml(length) + await self.send_html_message(evt, text, html) @command.new("movie-search", help="Movie lookup by Title") @command.argument("message", pass_raw=True, required=True) diff --git a/tmdb/tmdb_api.py b/tmdb/tmdb_api.py index 91318ea..8594cfa 100644 --- a/tmdb/tmdb_api.py +++ b/tmdb/tmdb_api.py @@ -52,6 +52,13 @@ class TmdbApi(): async def close_session(self): await self.session.close() + def set_poster_size(self, size): + for x in self.poster_sizes: + if x == size: + self.base_url_poster = self.base_url_images + x + return x + return None + class TmdbApiSingle(TmdbApi): def __init__(self): @@ -74,13 +81,6 @@ class TmdbApiSingle(TmdbApi): else: self.poster_binary = None - def set_poster_size(self, size): - for x in self.poster_sizes: - if x == size: - self.base_url_poster = self.base_url_images + x - return x - return None - class MoviePopular(TmdbApi): def __init__(self): @@ -100,8 +100,10 @@ class MoviePopular(TmdbApi): loop = length else: loop = self.length + id = 1 for element in self.list[:loop]: - html += f"""""" + html += f"""{str(id)} - {escape(element['title'])} - {str(int(element['vote_average']*10))}%
""" + id += 1 return html def getListText(self, length: int = None) -> str: @@ -114,11 +116,33 @@ class MoviePopular(TmdbApi): text += element['title'] return text + async def getMovieByNumber(self, number): + movie = Movie() + await movie.load_parameters() + movie.base_url_poster = self.base_url_poster + item = self.list[int(number) - 1] + await movie.setData(item) + return movie + class Movie(TmdbApiSingle): def __init__(self): super().__init__() + async def setData(self, data): + self.title = data['title'] + if not self.title: + self.valid = False + self.id = data['id'] + self.poster_url = self.base_url_poster + data['poster_path'] + self.overview = data['overview'] + self.web_url = 'https://www.themoviedb.org/movie/' + str(self.id) + self.vote_average = data['vote_average'] + await asyncio.gather( + self.query_cast(self.id), + self.query_image_binary()) + return self.id + async def search_title(self, title: str, year: int = None) -> int: payload = {} payload['query'] = title