Beispiel #1
0
 def multi(item):
     link = item
     # link = item["link"]
     # session = item["session"]
     subscriptions = self.session_manager.json_request(link)
     valid_subscriptions = []
     extras = {}
     extras["auth_check"] = ""
     if isinstance(subscriptions, str):
         input(subscriptions)
         return
     subscriptions = [
         subscription for subscription in subscriptions
         if "error" != subscription
     ]
     for subscription in subscriptions:
         subscription["session_manager"] = self.session_manager
         if extra_info:
             subscription2 = self.get_user(subscription["username"])
             if isinstance(subscription2, dict):
                 if "error" in subscription2:
                     continue
             subscription = subscription | subscription2.__dict__
         subscription = create_user(subscription)
         subscription.session_manager = self.session_manager
         subscription.subscriber = self
         valid_subscriptions.append(subscription)
     return valid_subscriptions
Beispiel #2
0
 async def multi(item):
     link = item
     subscriptions = await self.session_manager.json_request(link)
     valid_subscriptions = []
     extras = {}
     extras["auth_check"] = ""
     if isinstance(subscriptions, error_details):
         return
     subscriptions = [
         subscription for subscription in subscriptions
         if "error" != subscription
     ]
     tasks = []
     for subscription in subscriptions:
         subscription["session_manager"] = self.session_manager
         if extra_info:
             task = self.get_user(subscription["username"])
             tasks.append(task)
     tasks = await asyncio.gather(*tasks)
     for task in tasks:
         if isinstance(task, error_details):
             continue
         subscription2: create_user = task
         for subscription in subscriptions:
             if subscription["id"] != subscription2.id:
                 continue
             subscription = subscription | subscription2.__dict__
             subscription = create_user(subscription, self)
             if subscription.isBlocked:
                 continue
             subscription.session_manager = self.session_manager
             subscription.subscriber = self
             valid_subscriptions.append(subscription)
     return valid_subscriptions
Beispiel #3
0
 def __init__(
     self,
     option: dict[str, Any] = {},
     user: create_user = create_user(),
     pool: Optional[Pool] = None,
     max_threads: int = -1,
 ) -> None:
     self.id = user.id
     self.username = user.username
     if not self.username:
         self.username = f"u{self.id}"
     self.name = user.name
     self.email = user.email
     self.isPerformer = user.isPerformer
     self.chatMessagesCount = user.chatMessagesCount
     self.subscribesCount = user.subscribesCount
     self.lists = {}
     self.links = content_types()
     self.subscriptions: list[create_user] = []
     self.chats = None
     self.archived_stories = {}
     self.mass_messages = []
     self.paid_content = []
     self.pool = pool
     self.session_manager = api_helper.session_manager(self, max_threads=max_threads)
     self.auth_details: Optional[auth_details] = None
     self.cookies: Dict[str, Any] = {}
     self.profile_directory = option.get("profile_directory", "")
     self.guest = False
     self.active: bool = False
     self.errors: list[error_details] = []
     self.extras: Dict[str, Any] = {}
Beispiel #4
0
 async def get_user(
         self, identifier: Union[str,
                                 int]) -> Union[create_user, error_details]:
     link = endpoint_links(identifier).users
     response = await self.session_manager.json_request(link)
     if not isinstance(response, error_details):
         response["session_manager"] = self.session_manager
         response = create_user(response, self)
     return response
Beispiel #5
0
 async def get_paid_content(
     self,
     check: bool = False,
     refresh: bool = True,
     limit: int = 99,
     offset: int = 0,
     inside_loop: bool = False,
 ) -> list[Union[create_message, create_post]]:
     api_type = "paid_content"
     if not self.active:
         return []
     if not refresh:
         result = handle_refresh(self, api_type)
         if result:
             return result
     link = endpoint_links(global_limit=limit,
                           global_offset=offset).paid_api
     final_results = await self.session_manager.json_request(link)
     if not isinstance(final_results, error_details):
         if len(final_results) >= limit and not check:
             results2 = self.get_paid_content(limit=limit,
                                              offset=limit + offset,
                                              inside_loop=True)
             final_results.extend(results2)
         if not inside_loop:
             temp = []
             for final_result in final_results:
                 content = None
                 if final_result["responseType"] == "message":
                     user = create_user(final_result["fromUser"], self)
                     content = create_message(final_result, user)
                     print
                 elif final_result["responseType"] == "post":
                     user = create_user(final_result["author"], self)
                     content = create_post(final_result, user)
                 if content:
                     temp.append(content)
             final_results = temp
         self.paid_content = final_results
     return final_results
Beispiel #6
0
 def __init__(self, option, user) -> None:
     self.responseType: str = option.get("responseType")
     self.id: int = option.get("id")
     self.postedAt: str = option.get("postedAt")
     self.postedAtPrecise: str = option.get("postedAtPrecise")
     self.expiredAt: Any = option.get("expiredAt")
     self.author = create_user.create_user(option.get("author", {}))
     self.text: str = option.get("text")
     self.rawText: str = option.get("rawText")
     self.lockedText: bool = option.get("lockedText")
     self.isFavorite: bool = option.get("isFavorite")
     self.isReportedByMe: bool = option.get("isReportedByMe")
     self.canReport: bool = option.get("canReport")
     self.canDelete: bool = option.get("canDelete")
     self.canComment: bool = option.get("canComment")
     self.canEdit: bool = option.get("canEdit")
     self.isPinned: bool = option.get("isPinned")
     self.favoritesCount: int = option.get("favoritesCount")
     self.mediaCount: int = option.get("mediaCount")
     self.isMediaReady: bool = option.get("isMediaReady")
     self.voting: list = option.get("voting")
     self.isOpened: bool = option.get("isOpened")
     self.canToggleFavorite: bool = option.get("canToggleFavorite")
     self.streamId: Any = option.get("streamId")
     self.price: Any = option.get("price")
     self.hasVoting: bool = option.get("hasVoting")
     self.isAddedToBookmarks: bool = option.get("isAddedToBookmarks")
     self.isArchived: bool = option.get("isArchived")
     self.isDeleted: bool = option.get("isDeleted")
     self.hasUrl: bool = option.get("hasUrl")
     self.commentsCount: int = option.get("commentsCount")
     self.mentionedUsers: list = option.get("mentionedUsers")
     self.linkedUsers: list = option.get("linkedUsers")
     self.linkedPosts: list = option.get("linkedPosts")
     self.media: list = option.get("media", [])
     self.canViewMedia: bool = option.get("canViewMedia")
     self.preview: list = option.get("preview")
     self.canPurchase: bool = option.get("canPurchase")
     self.user: create_user.create_user = user
Beispiel #7
0
    def get_subscriptions(
        self,
        resume=None,
        refresh=True,
        identifiers: list = [],
        extra_info=True,
        limit=20,
        offset=0,
    ) -> list[create_user]:
        if not self.active:
            return []
        if not refresh:
            subscriptions = self.subscriptions
            return subscriptions
        link = endpoint_links(global_limit=limit,
                              global_offset=offset).subscriptions
        session = self.session_manager.sessions[0]
        ceil = math.ceil(self.subscribesCount / limit)
        a = list(range(ceil))
        offset_array = []
        for b in a:
            b = b * limit
            link = endpoint_links(global_limit=limit,
                                  global_offset=b).subscriptions
            offset_array.append(link)

        # Following logic is unique to creators only
        results = []
        if self.isPerformer:
            temp_session_manager = self.session_manager
            temp_pool = self.pool
            delattr(self, "session_manager")
            delattr(self, "pool")
            json_authed = jsonpickle.encode(self, unpicklable=False)
            json_authed = jsonpickle.decode(json_authed)
            self.session_manager = temp_session_manager
            self.pool = temp_pool
            json_authed = json_authed | self.get_user(self.username).__dict__

            subscription = create_user(json_authed)
            subscription.subscriber = self
            subscription.subscribedByData = {}
            new_date = datetime.now() + relativedelta(years=1)
            subscription.subscribedByData["expiredAt"] = new_date.isoformat()
            subscription = [subscription]
            results.append(subscription)
        if not identifiers:

            def multi(item):
                link = item
                # link = item["link"]
                # session = item["session"]
                subscriptions = self.session_manager.json_request(link)
                valid_subscriptions = []
                extras = {}
                extras["auth_check"] = ""
                if isinstance(subscriptions, str):
                    input(subscriptions)
                    return
                subscriptions = [
                    subscription for subscription in subscriptions
                    if "error" != subscription
                ]
                for subscription in subscriptions:
                    subscription["session_manager"] = self.session_manager
                    if extra_info:
                        subscription2 = self.get_user(subscription["username"])
                        if isinstance(subscription2, dict):
                            if "error" in subscription2:
                                continue
                        subscription = subscription | subscription2.__dict__
                    subscription = create_user(subscription)
                    subscription.session_manager = self.session_manager
                    subscription.subscriber = self
                    valid_subscriptions.append(subscription)
                return valid_subscriptions

            pool = self.pool
            # offset_array= offset_array[:16]
            results += pool.starmap(multi, product(offset_array))
        else:
            for identifier in identifiers:
                if self.id == identifier or self.username == identifier:
                    continue
                link = endpoint_links(identifier=identifier).users
                result = self.session_manager.json_request(link)
                if "error" in result or not result["subscribedBy"]:
                    continue
                subscription = create_user(result)
                subscription.session_manager = self.session_manager
                subscription.subscriber = self
                results.append([subscription])
                print
            print
        results = [x for x in results if x is not None]
        results = list(chain(*results))
        self.subscriptions = results
        return results
Beispiel #8
0
 def get_user(self, identifier: Union[str, int]):
     link = endpoint_links(identifier).users
     result = self.session_manager.json_request(link)
     result["session_manager"] = self.session_manager
     result = create_user(result) if "error" not in result else result
     return result
Beispiel #9
0
    async def get_subscriptions(
        self,
        resume=None,
        refresh=True,
        identifiers: list = [],
        extra_info=True,
        limit=20,
        offset=0,
    ) -> list[create_user]:
        if not self.active:
            return []
        if not refresh:
            subscriptions = self.subscriptions
            return subscriptions
        ceil = math.ceil(self.subscribesCount / limit)
        a = list(range(ceil))
        offset_array = []
        for b in a:
            b = b * limit
            link = endpoint_links(global_limit=limit,
                                  global_offset=b).subscriptions
            offset_array.append(link)

        # Following logic is unique to creators only
        results = []
        if self.isPerformer:
            temp_session_manager = self.session_manager
            temp_pool = self.pool
            temp_paid_content = self.paid_content
            delattr(self, "session_manager")
            delattr(self, "pool")
            delattr(self, "paid_content")
            json_authed = jsonpickle.encode(self, unpicklable=False)
            json_authed = jsonpickle.decode(json_authed)
            self.session_manager = temp_session_manager
            self.pool = temp_pool
            self.paid_content = temp_paid_content
            temp_auth = await self.get_user(self.username)
            if isinstance(json_authed, dict):
                json_authed = json_authed | temp_auth.__dict__

            subscription = create_user(json_authed, self)
            subscription.subscriber = self
            subscription.subscribedByData = {}
            new_date = datetime.now() + relativedelta(years=1)
            subscription.subscribedByData["expiredAt"] = new_date.isoformat()
            subscription = [subscription]
            results.append(subscription)
        if not identifiers:

            async def multi(item):
                link = item
                subscriptions = await self.session_manager.json_request(link)
                valid_subscriptions = []
                extras = {}
                extras["auth_check"] = ""
                if isinstance(subscriptions, error_details):
                    return
                subscriptions = [
                    subscription for subscription in subscriptions
                    if "error" != subscription
                ]
                tasks = []
                for subscription in subscriptions:
                    subscription["session_manager"] = self.session_manager
                    if extra_info:
                        task = self.get_user(subscription["username"])
                        tasks.append(task)
                tasks = await asyncio.gather(*tasks)
                for task in tasks:
                    if isinstance(task, error_details):
                        continue
                    subscription2: create_user = task
                    for subscription in subscriptions:
                        if subscription["id"] != subscription2.id:
                            continue
                        subscription = subscription | subscription2.__dict__
                        subscription = create_user(subscription, self)
                        if subscription.isBlocked:
                            continue
                        subscription.session_manager = self.session_manager
                        subscription.subscriber = self
                        valid_subscriptions.append(subscription)
                return valid_subscriptions

            pool = self.pool
            tasks = pool.starmap(multi, product(offset_array))
            results += await asyncio.gather(*tasks)
        else:
            for identifier in identifiers:
                if self.id == identifier or self.username == identifier:
                    continue
                link = endpoint_links(identifier=identifier).users
                result = await self.session_manager.json_request(link)
                if isinstance(result,
                              error_details) or not result["subscribedBy"]:
                    continue
                subscription = create_user(result, self)
                if subscription.isBlocked:
                    continue
                subscription.session_manager = self.session_manager
                subscription.subscriber = self
                results.append([subscription])
                print
            print
        results = [x for x in results if x is not None]
        results = list(chain(*results))
        self.subscriptions = results
        return results