Added details to popular
This commit is contained in:
parent
8d32883c71
commit
50482ea2ca
|
@ -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.
|
||||
|
||||
|
|
18
tmdb/tmdb.py
18
tmdb/tmdb.py
|
@ -74,7 +74,7 @@ class TmdbBot(Plugin):
|
|||
|
||||
async def send_help(self, evt: MessageEvent) -> None:
|
||||
html = """<p>Use <b>!tmdb movie {title} [y:{release year}]</b> to get movie detail based on the given title.</p>
|
||||
<p>Use <b>!tmdb popular</b> to get most popular movies.</p>
|
||||
<p>Use <b>!tmdb popular [{rating}]</b> to get most popular movies. Get details about any one movie in the list by adding the {rating}.</p>
|
||||
<p>Use <b>!tmdb language {language}</b> to set your prefered language.</p>
|
||||
<p>Use <b>!tmdb poster_size [{size}]</b> to set your prefered poster size. With empty {size} all available sizes are listed.</p>
|
||||
<p>Use <b>!tmdb tvshow {title}</b> to get detail about a tv show based on the given title.</p>"""
|
||||
|
@ -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)
|
||||
|
|
|
@ -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"""<p><a href="https://www.themoviedb.org/movie/{str(element['id'])}">{escape(element['title'])}</a></p>"""
|
||||
html += f"""<p>{str(id)} - <a href="https://www.themoviedb.org/movie/{str(element['id'])}">{escape(element['title'])}</a> - {str(int(element['vote_average']*10))}%</p>"""
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue