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,17 +756,16 @@ class chatBuffer(baseBuffer):
a = posts.audio(session=self.session, postObject=[attachment["audio"]]) a = posts.audio(session=self.session, postObject=[attachment["audio"]])
a.dialog.get_response() a.dialog.get_response()
a.dialog.Destroy() 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) output.speak(_(u"Opening URL..."), True)
webbrowser.open_new_tab(attachment["link"]["url"]) webbrowser.open_new_tab(attachment["link"]["url"])
elif attachment["type"] == "doc": elif attachment["type"] == "doc":
if attachment["doc"].has_key("preview") and attachment["doc"]["preview"].has_key("audio_msg"): output.speak(_(u"Opening document in web browser..."))
link = attachment["doc"]["preview"]["audio_msg"]["link_mp3"] webbrowser.open(attachment["doc"]["url"])
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": elif attachment["type"] == "video":
# it seems VK doesn't like to attach video links as normal URLS, so we'll have to # it seems VK doesn't like to attach video links as normal URLS, so we'll have to
# get the full video object and use its "player" key which will open a webbrowser in their site with a player for the video. # get the full video object and use its "player" key which will open a webbrowser in their site with a player for the video.

View File

@ -174,3 +174,11 @@ def render_video(video, session=None):
if video == False: if video == False:
return [_(u"Video not available"), "", ""] return [_(u"Video not available"), "", ""]
return [video["title"], video["description"], utils.seconds_to_string(video["duration"])] 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"]))) msg = u"{0}".format(" ".join(renderers.render_audio(attachment["audio"])))
tpe = _(u"Audio") tpe = _(u"Audio")
elif attachment["type"] == "doc": elif attachment["type"] == "doc":
if attachment["doc"].has_key("preview") and attachment["doc"]["preview"].has_key("audio_msg"): msg = u"{0}".format(attachment["doc"]["title"])
tpe = _(u"Voice message") tpe = _(u"{0} file").format(attachment["doc"]["ext"])
msg = seconds_to_string(attachment["doc"]["preview"]["audio_msg"]["duration"]) elif attachment["type"] == "audio_message":
print attachment["doc"]["ext"] msg = u"{0}".format(" ".join(renderers.render_audio_message(attachment["audio_message"])))
else: tpe = _(u"Voice message")
msg = u"{0}".format(attachment["doc"]["title"]) else:
tpe = _(u"{0} file").format(attachment["doc"]["ext"]) print attachment
return [tpe, msg] return [tpe, msg]