Added voice messages to the list of supported attached files in chats
This commit is contained in:
parent
0144a5787a
commit
f16576c03c
@ -756,17 +756,16 @@ 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"])
|
||||
output.speak(_(u"Opening document in web browser..."))
|
||||
webbrowser.open(attachment["doc"]["url"])
|
||||
elif attachment["type"] == "video":
|
||||
# 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.
|
||||
|
@ -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"])]
|
@ -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"])
|
||||
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]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user