Skip to content

Commit

Permalink
Patch file URLs on content fetch
Browse files Browse the repository at this point in the history
Workaround for Skype providing full URLs with the wrong domain.

Fixes #46.
  • Loading branch information
Terrance committed Apr 11, 2018
1 parent 7a3c575 commit 178b3ea
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions skpy/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ def externalCall(cls, method, url, codes=(200, 201, 204, 207), **kwargs):
API_ENTITLEMENT = "https://consumer.entitlement.skype.com"
API_SCHEDULE = "https://api.scheduler.skype.com"
API_TRANSLATE = "https://dev.microsofttranslator.com/api"
API_ASM = "https://api.asm.skype.com/v1/objects"
API_ASM_LOCAL = "https://{0}1-api.asm.skype.com/v1/objects"
API_URL = "https://urlp.asm.skype.com/v1/url/info"
API_CONTACTS = "https://contacts.skype.com/contacts/v2"
API_MSGSHOST = "https://client-s.gateway.messenger.live.com/v1"
Expand Down
16 changes: 14 additions & 2 deletions skpy/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,18 @@ class File(SkypeObj):

attrs = ("name", "size", "urlFull", "urlThumb", "urlView")

@property
def urlAsm(self):
# Workaround for Skype providing full URLs with the wrong domain.
# api.asm.skype.com/.../0-xxx-yy-zzz... -> xxx-api.asm.skype.com
if not self.urlFull:
return None
match = re.match("{}/0-([a-z0-9]+)-".format(SkypeConnection.API_ASM), self.urlFull)
if not match:
return self.urlFull
prefix = SkypeConnection.API_ASM_LOCAL.format(match.group(1))
return self.urlFull.replace(SkypeConnection.API_ASM, prefix, 1)

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

@classmethod
Expand All @@ -564,7 +576,7 @@ def rawToFields(cls, raw={}):
@property
@SkypeUtils.cacheResult
def fileContent(self):
return self.skype.conn("GET", "{0}/views/original".format(self.file.urlFull),
return self.skype.conn("GET", "{0}/views/original".format(self.file.urlAsm),
auth=SkypeConnection.Auth.Authorize).content

@property
Expand All @@ -589,7 +601,7 @@ class SkypeImageMsg(SkypeFileMsg):
@property
@SkypeUtils.cacheResult
def fileContent(self):
return self.skype.conn("GET", "{0}/views/imgpsh_fullsize".format(self.file.urlFull),
return self.skype.conn("GET", "{0}/views/imgpsh_fullsize".format(self.file.urlAsm),
auth=SkypeConnection.Auth.Authorize).content

@property
Expand Down

0 comments on commit 178b3ea

Please sign in to comment.