Mastodon: Allow adding descriptions to all supported media. Closes #516

This commit is contained in:
2023-02-10 01:01:25 -06:00
parent e9dc02e868
commit f3fd1087b4
5 changed files with 15 additions and 11 deletions

View File

@@ -148,9 +148,9 @@ class post(messages.basicTweet):
break
if can_attach == False or big_media_present == True:
return self.message.unable_to_attach_file()
video = self.message.get_video()
video, description = self.message.get_video()
if video != None:
videoInfo = {"type": "video", "file": video, "description": ""}
videoInfo = {"type": "video", "file": video, "description": description}
self.attachments.append(videoInfo)
self.message.add_item(item=[os.path.basename(videoInfo["file"]), videoInfo["type"], videoInfo["description"]])
self.text_processor()
@@ -166,9 +166,9 @@ class post(messages.basicTweet):
break
if can_attach == False or big_media_present == True:
return self.message.unable_to_attach_file()
audio = self.message.get_audio()
audio, description = self.message.get_audio()
if audio != None:
audioInfo = {"type": "audio", "file": audio, "description": ""}
audioInfo = {"type": "audio", "file": audio, "description": description}
self.attachments.append(audioInfo)
self.message.add_item(item=[os.path.basename(audioInfo["file"]), audioInfo["type"], audioInfo["description"]])
self.text_processor()

View File

@@ -210,8 +210,8 @@ class Session(base.baseSession):
poll = self.api.make_poll(options=obj["attachments"][0]["options"], expires_in=obj["attachments"][0]["expires_in"], multiple=obj["attachments"][0]["multiple"], hide_totals=obj["attachments"][0]["hide_totals"])
else:
for i in obj["attachments"]:
img = self.api_call("media_post", media_file=i["file"], description=i["description"], synchronous=True)
media_ids.append(img.id)
media = self.api_call("media_post", media_file=i["file"], description=i["description"], synchronous=True)
media_ids.append(media.id)
item = self.api_call(call_name="status_post", status=text, _sound="tweet_send.ogg", in_reply_to_id=in_reply_to_id, media_ids=media_ids, visibility=visibility, poll=poll, sensitive=obj["sensitive"], spoiler_text=obj["spoiler_text"])
if item != None:
in_reply_to_id = item["id"]

View File

@@ -42,7 +42,7 @@ def process_image_descriptions(media_attachments):
image_descriptions.append(media.get("description"))
idescriptions = ""
for image in image_descriptions:
idescriptions = idescriptions + _("Image description: {}").format(image) + "\n"
idescriptions = idescriptions + _("Media description: {}").format(image) + "\n"
return idescriptions
def render_post(post, template, relative_times=False, offset_hours=0):

View File

@@ -147,14 +147,16 @@ class Post(wx.Dialog):
def get_video(self):
openFileDialog = wx.FileDialog(self, _("Select the video to be uploaded"), "", "", _("Video files (*.mp4, *.mov, *.m4v, *.webm)| *.mp4; *.m4v; *.mov; *.webm"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return None
return openFileDialog.GetPath()
return (None, None)
dsc = self.ask_description()
return (openFileDialog.GetPath(), dsc)
def get_audio(self):
openFileDialog = wx.FileDialog(self, _("Select the audio file to be uploaded"), "", "", _("Audio files (*.mp3, *.ogg, *.wav, *.flac, *.opus, *.aac, *.m4a, *.3gp)|*.mp3; *.ogg; *.wav; *.flac; *.opus; *.aac; *.m4a; *.3gp"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST)
if openFileDialog.ShowModal() == wx.ID_CANCEL:
return None
return openFileDialog.GetPath()
return (None, None)
dsc = self.ask_description()
return (openFileDialog.GetPath(), dsc)
def unable_to_attach_file(self, *args, **kwargs):
return wx.MessageDialog(self, _("It is not possible to add more attachments. Please take into account that You can add only a maximum of 4 images, or one audio, video or poll per post. Please remove other attachments before continuing."), _("Error adding attachment"), wx.ICON_ERROR).ShowModal()