From d71721ab87d6822f10c7454f687bc207289ca9b5 Mon Sep 17 00:00:00 2001 From: Manuel Cortez Date: Thu, 20 Dec 2018 17:29:23 -0600 Subject: [PATCH] Added audio uploading support in posts. Needs improvements to detect its ID3 tags --- src/controller/attach.py | 13 +++++++++++++ src/controller/buffers.py | 7 +++++++ src/wxUI/dialogs/attach.py | 6 ++++++ 3 files changed, 26 insertions(+) diff --git a/src/controller/attach.py b/src/controller/attach.py index 0716425..6458257 100644 --- a/src/controller/attach.py +++ b/src/controller/attach.py @@ -22,6 +22,7 @@ class attachFromLocal(object): self.type = "local" self.dialog = gui.attachDialog(voice_messages) widgetUtils.connect_event(self.dialog.photo, widgetUtils.BUTTON_PRESSED, self.upload_image) + widgetUtils.connect_event(self.dialog.audio, widgetUtils.BUTTON_PRESSED, self.upload_audio) widgetUtils.connect_event(self.dialog.remove, widgetUtils.BUTTON_PRESSED, self.remove_attachment) self.dialog.get_response() log.debug("Attachments controller started.") @@ -40,6 +41,18 @@ class attachFromLocal(object): self.dialog.attachments.insert_item(False, *info) self.dialog.remove.Enable(True) + def upload_audio(self, *args, **kwargs): + audio = self.dialog.get_audio() + if audio != None: + # Define data structure for this attachment, as will be required by VK API later. + audioInfo = {"type": "audio", "file": audio} + log.debug("Audio data to upload: %r" % (audioInfo,)) + self.attachments.append(audioInfo) + # Translators: This is the text displayed in the attachments dialog, when the user adds a photo. + info = [_(u"Audio file"), os.path.basename(audio)] + self.dialog.attachments.insert_item(False, *info) + self.dialog.remove.Enable(True) + def remove_attachment(self, *args, **kwargs): """ Remove the currently focused item from the attachments list.""" current_item = self.dialog.attachments.get_selected() diff --git a/src/controller/buffers.py b/src/controller/buffers.py index 0d1bdab..0e69acb 100644 --- a/src/controller/buffers.py +++ b/src/controller/buffers.py @@ -146,6 +146,13 @@ class baseBuffer(object): id = r[0]["id"] owner_id = r[0]["owner_id"] local_attachments += "photo{0}_{1},".format(owner_id, id) + + elif i["type"] == "audio": + audio = i["file"] + r = uploader.audio(audio, "untitled", "untitled") + id = r["id"] + owner_id = r["owner_id"] + local_attachments += "audio{0}_{1},".format(owner_id, id) return local_attachments def connect_events(self): diff --git a/src/wxUI/dialogs/attach.py b/src/wxUI/dialogs/attach.py index 324b181..72835b4 100644 --- a/src/wxUI/dialogs/attach.py +++ b/src/wxUI/dialogs/attach.py @@ -49,3 +49,9 @@ class attachDialog(widgetUtils.BaseDialog): result = dlg.GetValue() dlg.Destroy() return result + + def get_audio(self): + openFileDialog = wx.FileDialog(self, _(u"Select the audio file to be uploaded"), "", "", _("Audio files (*.mp3)|*.mp3"), wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) + if openFileDialog.ShowModal() == wx.ID_CANCEL: + return None + return openFileDialog.GetPath()