Added voice messages to the list of supported attached files in chats

This commit is contained in:
Manuel Cortez 2018-12-13 11:48:17 -06:00
parent 0144a5787a
commit f16576c03c
3 changed files with 23 additions and 16 deletions

View File

@ -756,15 +756,14 @@ class chatBuffer(baseBuffer):
a = posts.audio(session=self.session, postObject=[attachment["audio"]])
a.dialog.get_response()
a.dialog.Destroy()
if attachment["type"] == "link":
elif attachment["type"] == "audio_message":
link = attachment["audio_message"]["link_mp3"]
output.speak(_(u"Playing..."))
player.player.play(url=dict(url=link), set_info=False)
elif attachment["type"] == "link":
output.speak(_(u"Opening URL..."), True)
webbrowser.open_new_tab(attachment["link"]["url"])
elif attachment["type"] == "doc":
if attachment["doc"].has_key("preview") and attachment["doc"]["preview"].has_key("audio_msg"):
link = attachment["doc"]["preview"]["audio_msg"]["link_mp3"]
output.speak(_(u"Playing..."))
player.player.play(url=dict(url=link), set_info=False)
else:
output.speak(_(u"Opening document in web browser..."))
webbrowser.open(attachment["doc"]["url"])
elif attachment["type"] == "video":

View File

@ -174,3 +174,11 @@ def render_video(video, session=None):
if video == False:
return [_(u"Video not available"), "", ""]
return [video["title"], video["description"], utils.seconds_to_string(video["duration"])]
def render_audio_message(audio_message, session=None):
""" Render a voice message from VK
Example result:
["Voice message", "01:30:28"]"""
if audio_message == False:
return [_(u"Voice message not available"), "", ""]
return [utils.seconds_to_string(audio_message["duration"])]

View File

@ -79,12 +79,12 @@ def add_attachment(attachment):
msg = u"{0}".format(" ".join(renderers.render_audio(attachment["audio"])))
tpe = _(u"Audio")
elif attachment["type"] == "doc":
if attachment["doc"].has_key("preview") and attachment["doc"]["preview"].has_key("audio_msg"):
tpe = _(u"Voice message")
msg = seconds_to_string(attachment["doc"]["preview"]["audio_msg"]["duration"])
print attachment["doc"]["ext"]
else:
msg = u"{0}".format(attachment["doc"]["title"])
tpe = _(u"{0} file").format(attachment["doc"]["ext"])
elif attachment["type"] == "audio_message":
msg = u"{0}".format(" ".join(renderers.render_audio_message(attachment["audio_message"])))
tpe = _(u"Voice message")
else:
print attachment
return [tpe, msg]