Terrance/SkPy

msg.fileContent

Closed this issue · 9 comments

Attribute fileContent is not implemented for RichText/Media_Video and RichText/Media_AudioMsg. Is it a bug?

This detection was apparently written 5 years ago, when we only had images in their own message structure (to show thumbnails), and everything else was a generic file download:

SkPy/skpy/msg.py

Lines 212 to 213 in 97da1eb

"RichText/Media_GenericFile": SkypeFileMsg,
"RichText/UriObject": SkypeImageMsg,

What do the full messages of those types look like? If they're the same structure as a generic file or an image then we can just extend the use of the existing classes, otherwise we'll need to figure out the new ways of downloading files of those types.

They all have same structure in msg.content. Different views to get file content, as I found.

"RichText/UriObject" - "/views/imgpsh_fullsize_anim"
"RichText/Media_GenericFile" - "/views/original"
"RichText/Media_Video" - "/views/video"
"RichText/Media_AudioMsg" - "/views/audio"

Are those paths in the message content, or did you observe them in Skype for Web? It'd be useful to have a whole raw message example here.

I've found these paths in Skype for Web with browser dev tools.
I don't know how to get raw message. Example of video message I got using skpy:

[SkypeMsg]
Id: *
Type: RichText/Media_Video
Time: * 
ClientId: *
UserId: *
ChatId: *
Content: <URIObject uri="https://api.asm.skype.com/v1/objects/0-neu-d2-01f53124cba69e20cf2d3733772e62fe" url_thumbnail="https://api.asm.skype.com/v1/objects/0-neu-d2-01f53124cba69e20cf2d3733772e62fe/views/thumbnail" type="Video.1" doc_id="0-neu-d2-01f53124cba69e20cf2d3733772e62fe" width="1080" height="1920">Чтобы просмотреть это общее видео, перейдите к: <a href="https://login.skype.com/login/sso?go=webclient.xmm&amp;docid=0-neu-d2-01f53124cba69e20cf2d3733772e62fe">https://login.skype.com/login/sso?go=webclient.xmm&amp;docid=0-neu-d2-01f53124cba69e20cf2d3733772e62fe</a><OriginalName v="WhatsApp Video 2021-01-18 at 14.42.47.mp4"></OriginalName><FileSize v="16364678"></FileSize></URIObject>

Care to try that commit (audio-video-msg-types branch) and see if that handles the messages correctly?

Thanks, it works!
RichText/Media_Video - ok.
RichText/Media_AudioMsg - ok.
But it looks like API downloads file when I call flieContent, takes some time to get content.
For me its ok. Thank you very much!

Indeed, .fileContent will give you the raw bytes, which it can only do once it's got all of them.

I've added SkypeFileMsg.urlContent if you want to roll your own download (e.g. to do chunked requests), though you'll have to do auth yourself, or go via the SkypeConnection:

resp = sk.conn("GET", msg.urlContent, auth=SkypeConnection.Auth.Authorize, **kwargs)

I tried to download using SkypeConnection, but it fails in 70% of calls with http401 error.
Code I used:

filepath = '/views/video'
f = sk.conn("GET",url + filepath,codes=(200, 201, 202, 204, 207),auth=sk.conn.Auth.Authorize)
open(folder + filename, 'wb').write(f.content)

If it works some of the time then that sounds like an issue with Skype itself, unless the link is single-use and it fails a while after it's generated.