Handling for Tv Shows (tmdb part)
This commit is contained in:
parent
984ce533e5
commit
59a6ce50bf
|
@ -1,6 +1,6 @@
|
||||||
maubot: 0.1.0
|
maubot: 0.1.0
|
||||||
id: lomion.tmdb
|
id: lomion.tmdb
|
||||||
version: 0.0.3
|
version: 0.2.0
|
||||||
license: AGPL 3.0
|
license: AGPL 3.0
|
||||||
modules:
|
modules:
|
||||||
- tmdb
|
- tmdb
|
||||||
|
|
|
@ -44,7 +44,7 @@ class TestTmdbMethods(unittest.TestCase):
|
||||||
self.assertEqual(message, """<p><a href="https://www.themoviedb.org/movie/550"><b>Fight Club</b></a></p>
|
self.assertEqual(message, """<p><a href="https://www.themoviedb.org/movie/550"><b>Fight Club</b></a></p>
|
||||||
<p>Ein Yuppie [...]</p>
|
<p>Ein Yuppie [...]</p>
|
||||||
<p>Acting: Edward Norton, Brad Pitt, Helena Bonham Carter</p>
|
<p>Acting: Edward Norton, Brad Pitt, Helena Bonham Carter</p>
|
||||||
<p>taken from www.themoviedb.org</p>""")
|
<p>Taken from www.themoviedb.org</p>""")
|
||||||
|
|
||||||
def test_database_language(self):
|
def test_database_language(self):
|
||||||
engine = create_engine('sqlite:///test.db', echo = True)
|
engine = create_engine('sqlite:///test.db', echo = True)
|
||||||
|
|
28
tmdb/tmdb.py
28
tmdb/tmdb.py
|
@ -20,7 +20,7 @@ from mautrix.types import TextMessageEventContent, MediaMessageEventContent, Mes
|
||||||
from maubot import Plugin, MessageEvent
|
from maubot import Plugin, MessageEvent
|
||||||
from maubot.handlers import command
|
from maubot.handlers import command
|
||||||
|
|
||||||
from tmdb.tmdb_api import Movie
|
from tmdb.tmdb_api import Movie, TvShow
|
||||||
from tmdb.database import Database
|
from tmdb.database import Database
|
||||||
|
|
||||||
|
|
||||||
|
@ -31,14 +31,14 @@ class TmdbBot(Plugin):
|
||||||
await super().start()
|
await super().start()
|
||||||
self.db = Database(self.database)
|
self.db = Database(self.database)
|
||||||
|
|
||||||
async def send_html_message(self, text_message, html_message) -> None:
|
async def send_html_message(self, evt: MessageEvent, text_message, html_message) -> None:
|
||||||
content = TextMessageEventContent(
|
content = TextMessageEventContent(
|
||||||
msgtype=MessageType.TEXT, format=Format.HTML,
|
msgtype=MessageType.TEXT, format=Format.HTML,
|
||||||
body=f"{text_message}",
|
body=f"{text_message}",
|
||||||
formatted_body=f"{html_message}")
|
formatted_body=f"{html_message}")
|
||||||
await evt.respond(content)
|
await evt.respond(content)
|
||||||
|
|
||||||
async def send_image(self, title, image) -> None:
|
async def send_image(self, evt: MessageEvent, title, image) -> None:
|
||||||
mxc_uri = await self.client.upload_media(image)
|
mxc_uri = await self.client.upload_media(image)
|
||||||
content = MediaMessageEventContent(
|
content = MediaMessageEventContent(
|
||||||
msgtype=MessageType.IMAGE,
|
msgtype=MessageType.IMAGE,
|
||||||
|
@ -59,13 +59,13 @@ class TmdbBot(Plugin):
|
||||||
html_message = f"""<p><a href="{movie.web_url}"><b>{escape(movie.title)}</b></a></p>
|
html_message = f"""<p><a href="{movie.web_url}"><b>{escape(movie.title)}</b></a></p>
|
||||||
<p>{escape(movie.overview)[:overview_length]}{three_dotts}</p>
|
<p>{escape(movie.overview)[:overview_length]}{three_dotts}</p>
|
||||||
<p>{cast}</p>
|
<p>{cast}</p>
|
||||||
<p>taken from www.themoviedb.org</p>"""
|
<p>Taken from www.themoviedb.org</p>"""
|
||||||
return html_message
|
return html_message
|
||||||
|
|
||||||
async def send_movie_info(self, evt: MessageEvent, movie) -> None:
|
async def send_movie_info(self, evt: MessageEvent, movie) -> None:
|
||||||
html_message = self.construct_html_message(movie)
|
html_message = self.construct_html_message(movie)
|
||||||
await self.send_html_message(f'{movie.title}', html_message)
|
await self.send_html_message(evt, f'{movie.title}', html_message)
|
||||||
await self.send_image(movie.title, movie.get_image_binary())
|
await self.send_image(evt, movie.title, movie.get_image_binary())
|
||||||
|
|
||||||
|
|
||||||
@command.new("movie-id", help="Movie lookup by id")
|
@command.new("movie-id", help="Movie lookup by id")
|
||||||
|
@ -103,3 +103,19 @@ class TmdbBot(Plugin):
|
||||||
msgtype=MessageType.NOTICE, format=Format.HTML,
|
msgtype=MessageType.NOTICE, format=Format.HTML,
|
||||||
body=f"Language set to {message}!")
|
body=f"Language set to {message}!")
|
||||||
await evt.respond(content)
|
await evt.respond(content)
|
||||||
|
|
||||||
|
@command.new("tvshow-search", help="TV Show lookup by Title")
|
||||||
|
@command.argument("message", pass_raw=True, required=True)
|
||||||
|
async def tvshow_search(self, evt: MessageEvent, message: str = "") -> None:
|
||||||
|
movie = TvShow()
|
||||||
|
language = self.db.get_language(evt.sender)
|
||||||
|
if language:
|
||||||
|
movie.set_language(language)
|
||||||
|
movie.search_title(message)
|
||||||
|
if movie.valid:
|
||||||
|
await self.send_movie_info(evt, movie)
|
||||||
|
else:
|
||||||
|
content = TextMessageEventContent(
|
||||||
|
msgtype=MessageType.NOTICE, format=Format.HTML,
|
||||||
|
body=f"No tv show found!")
|
||||||
|
await evt.respond(content)
|
Loading…
Reference in a new issue