From 92f89dc9a8bb2716bf2edb8fdb32ae29b4ae6e5e Mon Sep 17 00:00:00 2001 From: lomion Date: Tue, 16 Feb 2021 15:00:01 +0100 Subject: [PATCH 1/2] Added mime type to poster message. This might address #10 but needs to be verified (not reproduceable). --- test_tmdb.py | 9 +++++++-- tmdb/tmdb.py | 16 +++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/test_tmdb.py b/test_tmdb.py index e55d716..d58e661 100644 --- a/test_tmdb.py +++ b/test_tmdb.py @@ -67,9 +67,9 @@ class TestTmdbMethods(unittest.TestCase): def test_search_year(self): movie = Movie() - id = movie.search_title('Dune') + id = movie.search_title('Dune', 1984) self.assertEqual(id, 841) - id = movie.search_title('Dune', 2020) + id = movie.search_title('Dune') self.assertEqual(id, 438631) def test_split_year(self): @@ -105,6 +105,11 @@ class TestTmdbMethods(unittest.TestCase): movie.search_title('The Flash') #self.assertEqual('Tom Cavanagh', movie.cast[0]) self.assertEqual('Carlos Valdes', movie.cast[2]) + + def test_poster_path(self): + movie = Movie() + id = movie.search_title('Dune') + self.assertEqual(movie.poster_url, "http://image.tmdb.org/t/p/w92/9HNZTw2D3cM1yA08FF5SeWEO9eX.jpg") if __name__ == '__main__': unittest.main() diff --git a/tmdb/tmdb.py b/tmdb/tmdb.py index c46a2db..b00f293 100644 --- a/tmdb/tmdb.py +++ b/tmdb/tmdb.py @@ -16,7 +16,7 @@ along with tmdb-bot. If not, see . from html import escape import re -from mautrix.types import TextMessageEventContent, MediaMessageEventContent, MessageType, Format +from mautrix.types import TextMessageEventContent, MediaMessageEventContent, MessageType, Format, ImageInfo from maubot import Plugin, MessageEvent from maubot.handlers import command @@ -74,12 +74,14 @@ class TmdbBot(Plugin): await evt.respond(content) async def send_image(self, evt: MessageEvent, title, image) -> None: - mxc_uri = await self.client.upload_media(image) - content = MediaMessageEventContent( - msgtype=MessageType.IMAGE, - body=f"Image {title}", - url=f"{mxc_uri}") - await evt.respond(content) + if image: + mxc_uri = await self.client.upload_media(image) + content = MediaMessageEventContent( + msgtype=MessageType.IMAGE, + body=f"Image {title}", + url=f"{mxc_uri}", + info=ImageInfo(mimetype='image/jpg')) + await evt.respond(content) def construct_html_message(self, movie, overview_length = 200, cast_length = 3) -> str: if len(movie.overview) > overview_length: From 91ac13cf2963d27ce9a7616e1554d37c8f9e8bd2 Mon Sep 17 00:00:00 2001 From: lomion Date: Wed, 17 Feb 2021 12:54:35 +0100 Subject: [PATCH 2/2] Forced image upload to mimetype "image/jpg" Test result: Image download working with all clients. Image preview is working with Element Android and FluffyChat but not in Element Web. Todo: Get mimetype from downloaded image or make sure its always jpg --- tmdb/tmdb.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tmdb/tmdb.py b/tmdb/tmdb.py index b00f293..9564f33 100644 --- a/tmdb/tmdb.py +++ b/tmdb/tmdb.py @@ -75,13 +75,14 @@ class TmdbBot(Plugin): async def send_image(self, evt: MessageEvent, title, image) -> None: if image: - mxc_uri = await self.client.upload_media(image) + mxc_uri = await self.client.upload_media(image, mime_type='image/jpg') content = MediaMessageEventContent( msgtype=MessageType.IMAGE, body=f"Image {title}", url=f"{mxc_uri}", info=ImageInfo(mimetype='image/jpg')) await evt.respond(content) + #await self.client.send_image(evt.room_id, url=mxc_uri, info=ImageInfo(mimetype='image/jpg')) def construct_html_message(self, movie, overview_length = 200, cast_length = 3) -> str: if len(movie.overview) > overview_length: