From c0654658b5725d7f15aba0a0feb727436a523037 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Wed, 9 Nov 2022 09:09:37 -0600 Subject: [PATCH] Added indications when there are audio, video, photos or gifvs in media attachments --- src/controller/buffers/mastodon/base.py | 10 +++++----- src/mastodon.defaults | 2 ++ src/sessions/mastodon/utils.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/src/controller/buffers/mastodon/base.py b/src/controller/buffers/mastodon/base.py index c6d8df5f..e7b10bee 100644 --- a/src/controller/buffers/mastodon/base.py +++ b/src/controller/buffers/mastodon/base.py @@ -304,13 +304,13 @@ class BaseBuffer(base.Buffer): original_date = arrow.get(self.session.db[self.name][self.buffer.list.get_selected()].created_at) ts = original_date.humanize(locale=languageHandler.getLanguage()) self.buffer.list.list.SetItem(self.buffer.list.get_selected(), 2, ts) -# if self.session.settings['sound']['indicate_audio'] and utils.is_audio(toot): -# self.session.sound.play("audio.ogg") -# if self.session.settings['sound']['indicate_img'] and utils.is_media(toot): -# self.session.sound.play("image.ogg") + if self.session.settings['sound']['indicate_audio'] and utils.is_audio_or_video(toot): + self.session.sound.play("audio.ogg") + if self.session.settings['sound']['indicate_img'] and utils.is_image(toot): + self.session.sound.play("image.ogg") # can_share = self.can_share() # pub.sendMessage("toggleShare", shareable=can_share) -# self.buffer.retweet.Enable(can_share) +# self.buffer.boost.Enable(can_share) def audio(self, url='', *args, **kwargs): if sound.URLPlayer.player.is_playing(): diff --git a/src/mastodon.defaults b/src/mastodon.defaults index 3a10fcb7..81113b82 100644 --- a/src/mastodon.defaults +++ b/src/mastodon.defaults @@ -20,6 +20,8 @@ input_device = string(default="Default") output_device = string(default="Default") session_mute = boolean(default=False) current_soundpack = string(default="default") +indicate_audio = boolean(default=True) +indicate_img = boolean(default=True) [other_buffers] timelines = list(default=list()) diff --git a/src/sessions/mastodon/utils.py b/src/sessions/mastodon/utils.py index ce1e987b..1091f778 100644 --- a/src/sessions/mastodon/utils.py +++ b/src/sessions/mastodon/utils.py @@ -18,3 +18,19 @@ def find_item(item, listItems): if item.reblog != None and item.reblog.id == listItems[i].id: return i return None + +def is_audio_or_video(toot): + if toot.reblog != None: + return is_audio_or_video(toot.reblog) + # Checks firstly for Mastodon native videos and audios. + for media in toot.media_attachments: + if media["type"] == "video" or media["type"] == "audio": + return True + +def is_image(toot): + if toot.reblog != None: + return is_audio_or_video(toot.reblog) + # Checks firstly for Mastodon native videos and audios. + for media in toot.media_attachments: + if media["type"] == "gifv" or media["type"] == "image": + return True \ No newline at end of file