diff --git a/instaloader/structures.py b/instaloader/structures.py index 8160751..0348b84 100644 --- a/instaloader/structures.py +++ b/instaloader/structures.py @@ -413,6 +413,30 @@ class Post: lambda d: d['data']['shortcode_media']['edge_liked_by'], self._rhx_gis)) + @property + def is_sponsored(self) -> bool: + """ + Whether Post is a sponsored post, equivalent to non-empty :meth:`Post.sponsor_users`. + + .. versionadded:: 4.4 + """ + try: + sponsor_edges = self._field('edge_media_to_sponsor_user', 'edges') + except KeyError: + return False + return bool(sponsor_edges) + + @property + def sponsor_users(self) -> List['Profile']: + """ + The Post's sponsors. + + .. versionadded:: 4.4 + """ + return ([] if not self.is_sponsored else + [Profile(self._context, edge['node']['sponsor']) for edge in + self._field('edge_media_to_sponsor_user', 'edges')]) + @property def location(self) -> Optional[PostLocation]: """