Split graphql_to_attachment into smaller methods
This commit is contained in:
@@ -21,6 +21,15 @@ class FileAttachment(Attachment):
|
|||||||
# Put here for backwards compatibility, so that the init argument order is preserved
|
# Put here for backwards compatibility, so that the init argument order is preserved
|
||||||
uid = attr.ib(None)
|
uid = attr.ib(None)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_graphql(cls, data):
|
||||||
|
return cls(
|
||||||
|
url=data.get("url"),
|
||||||
|
name=data.get("filename"),
|
||||||
|
is_malicious=data.get("is_malicious"),
|
||||||
|
uid=data.get("message_file_fbid"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(cmp=False)
|
@attr.s(cmp=False)
|
||||||
class AudioAttachment(Attachment):
|
class AudioAttachment(Attachment):
|
||||||
@@ -38,6 +47,15 @@ class AudioAttachment(Attachment):
|
|||||||
# Put here for backwards compatibility, so that the init argument order is preserved
|
# Put here for backwards compatibility, so that the init argument order is preserved
|
||||||
uid = attr.ib(None)
|
uid = attr.ib(None)
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_graphql(cls, data):
|
||||||
|
return cls(
|
||||||
|
filename=data.get("filename"),
|
||||||
|
url=data.get("playable_url"),
|
||||||
|
duration=data.get("playable_duration_in_ms"),
|
||||||
|
audio_type=data.get("audio_type"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(cmp=False, init=False)
|
@attr.s(cmp=False, init=False)
|
||||||
class ImageAttachment(Attachment):
|
class ImageAttachment(Attachment):
|
||||||
@@ -122,6 +140,21 @@ class ImageAttachment(Attachment):
|
|||||||
self.animated_preview_width = animated_preview.get("width")
|
self.animated_preview_width = animated_preview.get("width")
|
||||||
self.animated_preview_height = animated_preview.get("height")
|
self.animated_preview_height = animated_preview.get("height")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_graphql(cls, data):
|
||||||
|
return cls(
|
||||||
|
original_extension=data.get("original_extension")
|
||||||
|
or (data["filename"].split("-")[0] if data.get("filename") else None),
|
||||||
|
width=data.get("original_dimensions", {}).get("width"),
|
||||||
|
height=data.get("original_dimensions", {}).get("height"),
|
||||||
|
is_animated=data["__typename"] == "MessageAnimatedImage",
|
||||||
|
thumbnail_url=data.get("thumbnail", {}).get("uri"),
|
||||||
|
preview=data.get("preview") or data.get("preview_image"),
|
||||||
|
large_preview=data.get("large_preview"),
|
||||||
|
animated_preview=data.get("animated_image"),
|
||||||
|
uid=data.get("legacy_attachment_id"),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
@attr.s(cmp=False, init=False)
|
@attr.s(cmp=False, init=False)
|
||||||
class VideoAttachment(Attachment):
|
class VideoAttachment(Attachment):
|
||||||
@@ -195,3 +228,16 @@ class VideoAttachment(Attachment):
|
|||||||
self.large_image_url = large_image.get("uri")
|
self.large_image_url = large_image.get("uri")
|
||||||
self.large_image_width = large_image.get("width")
|
self.large_image_width = large_image.get("width")
|
||||||
self.large_image_height = large_image.get("height")
|
self.large_image_height = large_image.get("height")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _from_graphql(cls, data):
|
||||||
|
return cls(
|
||||||
|
width=data.get("original_dimensions", {}).get("width"),
|
||||||
|
height=data.get("original_dimensions", {}).get("height"),
|
||||||
|
duration=data.get("playable_duration_in_ms"),
|
||||||
|
preview_url=data.get("playable_url"),
|
||||||
|
small_image=data.get("chat_image"),
|
||||||
|
medium_image=data.get("inbox_image"),
|
||||||
|
large_image=data.get("large_image"),
|
||||||
|
uid=data.get("legacy_attachment_id"),
|
||||||
|
)
|
||||||
|
@@ -63,43 +63,13 @@ def get_customization_info(thread):
|
|||||||
def graphql_to_attachment(a):
|
def graphql_to_attachment(a):
|
||||||
_type = a["__typename"]
|
_type = a["__typename"]
|
||||||
if _type in ["MessageImage", "MessageAnimatedImage"]:
|
if _type in ["MessageImage", "MessageAnimatedImage"]:
|
||||||
return ImageAttachment(
|
return ImageAttachment._from_graphql(a)
|
||||||
original_extension=a.get("original_extension")
|
|
||||||
or (a["filename"].split("-")[0] if a.get("filename") else None),
|
|
||||||
width=a.get("original_dimensions", {}).get("width"),
|
|
||||||
height=a.get("original_dimensions", {}).get("height"),
|
|
||||||
is_animated=_type == "MessageAnimatedImage",
|
|
||||||
thumbnail_url=a.get("thumbnail", {}).get("uri"),
|
|
||||||
preview=a.get("preview") or a.get("preview_image"),
|
|
||||||
large_preview=a.get("large_preview"),
|
|
||||||
animated_preview=a.get("animated_image"),
|
|
||||||
uid=a.get("legacy_attachment_id"),
|
|
||||||
)
|
|
||||||
elif _type == "MessageVideo":
|
elif _type == "MessageVideo":
|
||||||
return VideoAttachment(
|
return VideoAttachment._from_graphql(a)
|
||||||
width=a.get("original_dimensions", {}).get("width"),
|
|
||||||
height=a.get("original_dimensions", {}).get("height"),
|
|
||||||
duration=a.get("playable_duration_in_ms"),
|
|
||||||
preview_url=a.get("playable_url"),
|
|
||||||
small_image=a.get("chat_image"),
|
|
||||||
medium_image=a.get("inbox_image"),
|
|
||||||
large_image=a.get("large_image"),
|
|
||||||
uid=a.get("legacy_attachment_id"),
|
|
||||||
)
|
|
||||||
elif _type == "MessageAudio":
|
elif _type == "MessageAudio":
|
||||||
return AudioAttachment(
|
return AudioAttachment._from_graphql(a)
|
||||||
filename=a.get("filename"),
|
|
||||||
url=a.get("playable_url"),
|
|
||||||
duration=a.get("playable_duration_in_ms"),
|
|
||||||
audio_type=a.get("audio_type"),
|
|
||||||
)
|
|
||||||
elif _type == "MessageFile":
|
elif _type == "MessageFile":
|
||||||
return FileAttachment(
|
return FileAttachment._from_graphql(a)
|
||||||
url=a.get("url"),
|
|
||||||
name=a.get("filename"),
|
|
||||||
is_malicious=a.get("is_malicious"),
|
|
||||||
uid=a.get("message_file_fbid"),
|
|
||||||
)
|
|
||||||
else:
|
else:
|
||||||
return Attachment(uid=a.get("legacy_attachment_id"))
|
return Attachment(uid=a.get("legacy_attachment_id"))
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user