Skip to content

Commit

Permalink
Expose content URL on file messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Terrance committed Feb 11, 2021
1 parent 364aa56 commit 77270e1
Showing 1 changed file with 15 additions and 24 deletions.
39 changes: 15 additions & 24 deletions skpy/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,6 +535,8 @@ class SkypeFileMsg(SkypeMsg):
Attributes:
file (:class:`File`):
File object embedded in the message.
urlContent (str):
URL to retrieve the raw file content.
fileContent (bytes):
Raw content of the file.
"""
Expand Down Expand Up @@ -573,6 +575,8 @@ def urlAsm(self):

attrs = SkypeMsg.attrs + ("file",)

contentPath = "original"

@classmethod
def contentToFields(cls, content):
fields = super(SkypeFileMsg, cls).contentToFields(content)
Expand All @@ -587,13 +591,18 @@ def contentToFields(cls, content):
fields["file"] = SkypeFileMsg.File(**fileFields)
return fields

@property
def urlContent(self):
return "{0}/views/{1}".format(self.file.urlAsm, self.contentPath) if self.file else None

@property
@SkypeUtils.cacheResult
def fileContent(self):
if not self.file:
if self.file:
return self.skype.conn("GET", self.urlContent,
auth=SkypeConnection.Auth.Authorize).content
else:
return None
return self.skype.conn("GET", "{0}/views/original".format(self.file.urlAsm),
auth=SkypeConnection.Auth.Authorize).content

@property
def html(self):
Expand All @@ -614,13 +623,7 @@ class SkypeImageMsg(SkypeFileMsg):
A message containing a picture shared in a conversation.
"""

@property
@SkypeUtils.cacheResult
def fileContent(self):
if not self.file:
return None
return self.skype.conn("GET", "{0}/views/imgpsh_fullsize".format(self.file.urlAsm),
auth=SkypeConnection.Auth.Authorize).content
contentPath = "imgpsh_fullsize"

@property
def html(self):
Expand All @@ -639,13 +642,7 @@ class SkypeAudioMsg(SkypeFileMsg):
A message containing audio shared in a conversation.
"""

@property
@SkypeUtils.cacheResult
def fileContent(self):
if not self.file:
return None
return self.skype.conn("GET", "{0}/views/audio".format(self.file.urlAsm),
auth=SkypeConnection.Auth.Authorize).content
contentPath = "audio"

@property
def html(self):
Expand All @@ -663,13 +660,7 @@ class SkypeVideoMsg(SkypeFileMsg):
A message containing a video shared in a conversation.
"""

@property
@SkypeUtils.cacheResult
def fileContent(self):
if not self.file:
return None
return self.skype.conn("GET", "{0}/views/video".format(self.file.urlAsm),
auth=SkypeConnection.Auth.Authorize).content
contentPath = "video"

@property
def html(self):
Expand Down

0 comments on commit 77270e1

Please sign in to comment.