|
2 | 2 | from __future__ import unicode_literals |
3 | 3 |
|
4 | 4 | import attr |
| 5 | +from . import _util |
5 | 6 |
|
6 | 7 |
|
7 | 8 | @attr.s(cmp=False) |
@@ -46,3 +47,40 @@ class ShareAttachment(Attachment): |
46 | 47 |
|
47 | 48 | # Put here for backwards compatibility, so that the init argument order is preserved |
48 | 49 | uid = attr.ib(None) |
| 50 | + |
| 51 | + @classmethod |
| 52 | + def _from_graphql(cls, data): |
| 53 | + from . import _file |
| 54 | + |
| 55 | + url = data.get("url") |
| 56 | + rtn = cls( |
| 57 | + uid=data.get("deduplication_key"), |
| 58 | + author=data["target"]["actors"][0]["id"] |
| 59 | + if data["target"].get("actors") |
| 60 | + else None, |
| 61 | + url=url, |
| 62 | + original_url=_util.get_url_parameter(url, "u") |
| 63 | + if "/l.php?u=" in url |
| 64 | + else url, |
| 65 | + title=data["title_with_entities"].get("text"), |
| 66 | + description=data["description"].get("text") |
| 67 | + if data.get("description") |
| 68 | + else None, |
| 69 | + source=data["source"].get("text"), |
| 70 | + attachments=[ |
| 71 | + _file.graphql_to_subattachment(attachment) |
| 72 | + for attachment in data.get("subattachments") |
| 73 | + ], |
| 74 | + ) |
| 75 | + media = data.get("media") |
| 76 | + if media and media.get("image"): |
| 77 | + image = media["image"] |
| 78 | + rtn.image_url = image.get("uri") |
| 79 | + rtn.original_image_url = ( |
| 80 | + _util.get_url_parameter(rtn.image_url, "url") |
| 81 | + if "/safe_image.php" in rtn.image_url |
| 82 | + else rtn.image_url |
| 83 | + ) |
| 84 | + rtn.image_width = image.get("width") |
| 85 | + rtn.image_height = image.get("height") |
| 86 | + return rtn |
0 commit comments