def _init_properties_custom(self, value, prop, arr): if prop == 'id': self.identifier = value standart_properties = [ 'type', 'link', 'thumbnail_src', 'caption', 'video_view_count', 'caption_is_edited', 'is_ad' ] if prop in standart_properties: self.__setattr__(prop, value) elif prop == 'created_time' or prop == 'taken_at_timestamp' or prop == 'date': self.created_time = int(value) elif prop == 'code': self.short_code = value self.link = endpoints.get_media_page_link(self.short_code) elif prop == 'comments': self.comments_count = arr[prop]['count'] elif prop == 'likes': self.likes_count = arr[prop]['count'] elif prop == 'display_resources': medias_url = [] for media in value: medias_url.append(media['src']) if media['config_width'] == 640: self.image_thumbnail_url = media['src'] elif media['config_width'] == 750: self.image_low_resolution_url = media['src'] elif media['config_width'] == 1080: self.image_standard_resolution_url = media['src'] elif prop == 'display_src' or prop == 'display_url': self.image_high_resolution_url = value if self.type is None: self.type = Media.TYPE_IMAGE elif prop == 'thumbnail_resources': square_images_url = [] for square_image in value: square_images_url.append(square_image['src']) self.square_images = square_images_url elif prop == 'carousel_media': self.type = Media.TYPE_CAROUSEL self.carousel_media = [] # print(arr["carousel_media"]) exit() for carousel_array in arr["carousel_media"]: self.set_carousel_media(arr, carousel_array) elif prop == 'video_views': self.video_views = value self.type = Media.TYPE_VIDEO elif prop == 'videos': self.video_low_resolution_url = arr[prop]['low_resolution']['url'] self.video_standard_resolution_url = \ arr[prop]['standard_resolution']['url'] self.video_low_bandwith_url = arr[prop]['low_bandwidth']['url'] elif prop == 'video_resources': for video in value: if video['profile'] == 'MAIN': self.video_standard_resolution_url = video['src'] elif video['profile'] == 'BASELINE': self.video_low_resolution_url = video['src'] self.video_low_bandwith_url = video['src'] elif prop == 'location' and value is not None: self.location_id = arr[prop]['id'] self.location_name = arr[prop]['name'] self.location_slug = arr[prop]['slug'] elif prop == 'user' or prop == 'owner': from .account import Account self.owner = Account(arr[prop]) elif prop == 'is_video': if bool(value): self.type = Media.TYPE_VIDEO elif prop == 'video_url': self.video_standard_resolution_url = value elif prop == 'shortcode': self.short_code = value self.link = endpoints.get_media_page_link(self.short_code) elif prop == 'edge_media_to_comment': try: self.comments_count = int(arr[prop]['count']) except KeyError: pass try: edges = arr[prop]['edges'] for comment_data in edges: self.comments.append(Comment(comment_data['node'])) except KeyError: pass try: self.has_more_comments = bool( arr[prop]['page_info']['has_next_page']) except KeyError: pass try: self.comments_next_page = str( arr[prop]['page_info']['end_cursor']) except KeyError: pass elif prop == 'edge_media_preview_like': self.likes_count = arr[prop]['count'] elif prop == 'edge_liked_by': self.likes_count = arr[prop]['count'] elif prop == 'edge_media_to_caption': try: self.caption = arr[prop]['edges'][0]['node']['text'] except (KeyError, IndexError): pass elif prop == 'edge_sidecar_to_children': pass # #TODO implement # if (!is_array($arr[$prop]['edges'])) { # break; # } # foreach ($arr[$prop]['edges'] as $edge) { # if (!isset($edge['node'])) { # continue; # } # $this->sidecarMedias[] = static::create($edge['node']); # } elif prop == '__typename': if value == 'GraphImage': self.type = Media.TYPE_IMAGE elif value == 'GraphVideo': self.type = Media.TYPE_VIDEO elif value == 'GraphSidecar': self.type = Media.TYPE_SIDECAR
def get_link_from_id(id): code = Media.get_code_from_id(id) return endpoints.get_media_page_link(code)