Beispiel #1
0
    def fanboxGetPostsFromArtist(self, artist_id, next_url=""):
        ''' get all posts from the supported user from https://www.pixiv.net/ajax/fanbox/creator?userId=15521131 '''
        if next_url is None or next_url == "":
            url = "https://www.pixiv.net/ajax/fanbox/creator?userId={0}".format(
                artist_id)
        elif next_url.startswith("https://"):
            url = next_url
        else:
            url = "https://www.pixiv.net" + next_url

        # Fix #494
        PixivHelper.print_and_log('info', 'Getting posts from ' + url)
        referer = "https://www.pixiv.net/fanbox/creator/{0}".format(artist_id)
        req = mechanize.Request(url)
        req.add_header('Accept', 'application/json, text/plain, */*')
        req.add_header('Referer', referer)
        req.add_header('Origin', 'https://www.pixiv.net')
        req.add_header('User-Agent', self._config.useragent)

        response = self.open_with_retry(req).read()
        # Issue #420
        _tzInfo = None
        if self._config.useLocalTimezone:
            _tzInfo = PixivHelper.LocalUTCOffsetTimezone()
        result = FanboxArtist(artist_id, response, tzInfo=_tzInfo)

        pixivArtist = PixivArtist(artist_id)
        self.getMemberInfoWhitecube(artist_id, pixivArtist)
        result.artistName = pixivArtist.artistName
        result.artistToken = pixivArtist.artistToken

        return result
Beispiel #2
0
    def getImagePage(self,
                     image_id,
                     parent=None,
                     from_bookmark=False,
                     bookmark_count=-1,
                     image_response_count=-1):
        image = None
        response = None
        PixivHelper.get_logger().debug("Getting image page: %s", image_id)
        # https://www.pixiv.net/en/artworks/76656661
        url = "https://www.pixiv.net{1}/artworks/{0}".format(
            image_id, self._locale)
        response = self.getPixivPage(url,
                                     returnParsed=False,
                                     enable_cache=False)
        self.handleDebugMediumPage(response, image_id)

        # Issue #355 new ui handler
        image = None
        try:
            if response.find("meta-preload-data") > 0:
                PixivHelper.print_and_log('debug', 'New UI Mode')

                # Issue #420
                _tzInfo = None
                if self._config.useLocalTimezone:
                    _tzInfo = PixivHelper.LocalUTCOffsetTimezone()

                image = PixivImage(image_id,
                                   response,
                                   parent,
                                   from_bookmark,
                                   bookmark_count,
                                   image_response_count,
                                   dateFormat=self._config.dateFormat,
                                   tzInfo=_tzInfo)

                if image.imageMode == "ugoira_view":
                    ugoira_meta_url = "https://www.pixiv.net/ajax/illust/{0}/ugoira_meta".format(
                        image_id)
                    res = self.open_with_retry(ugoira_meta_url)
                    meta_response = res.read()
                    image.ParseUgoira(meta_response)
                    res.close()

                if parent is None:
                    if from_bookmark:
                        image.originalArtist.reference_image_id = image_id
                        self.getMemberInfoWhitecube(
                            image.originalArtist.artistId,
                            image.originalArtist)
                    else:
                        image.artist.reference_image_id = image_id
                        self.getMemberInfoWhitecube(image.artist.artistId,
                                                    image.artist)
        except BaseException:
            PixivHelper.get_logger().error("Respose data: \r\n %s", response)
            raise

        return (image, response)
    def fanboxGetPost(self, post_id, artist=None):
        self.fanbox_is_logged_in()
        # https://fanbox.pixiv.net/api/post.info?postId=279561
        # https://www.pixiv.net/fanbox/creator/104409/post/279561
        p_url = f"https://api.fanbox.cc/post.info?postId={post_id}"
        # referer doesn't seeem to be essential
        p_referer = f"https://www.fanbox.cc/@{artist.creatorId if artist else ''}/posts/{post_id}"
        PixivHelper.get_logger().debug('Getting post detail from %s', p_url)
        p_req = mechanize.Request(p_url)
        p_req.add_header('Accept', 'application/json, text/plain, */*')
        p_req.add_header('Referer', p_referer)
        p_req.add_header('Origin', 'https://www.fanbox.cc')
        p_req.add_header('User-Agent', self._config.useragent)

        p_res = self.open_with_retry(p_req)
        p_response = p_res.read()
        PixivHelper.get_logger().debug(p_response.decode('utf8'))
        p_res.close()
        js = demjson.decode(p_response)
        if artist:
            return js
        else:
            _tzInfo = None
            if self._config.useLocalTimezone:
                _tzInfo = PixivHelper.LocalUTCOffsetTimezone()
            artist = FanboxArtist(js["body"]["user"]["userId"], js["body"]["creatorId"], js["body"]["user"]["name"])
            self.fanboxUpdateArtistToken(artist)
            post = FanboxPost(post_id, artist, js["body"], _tzInfo)
            return post
    def fanboxGetUsers(self, via):
        self.fanbox_is_logged_in()
        if via == FanboxArtist.SUPPORTED:
            url = 'https://api.fanbox.cc/plan.listSupporting'
            PixivHelper.print_and_log('info', f'Getting supported artists from {url}')
            referer = "https://www.fanbox.cc/creators/supporting"
        elif via == FanboxArtist.FOLLOWED:
            url = 'https://api.fanbox.cc/creator.listFollowing'
            PixivHelper.print_and_log('info', f'Getting supported artists from {url}')
            referer = "https://www.fanbox.cc/creators/following"

        req = mechanize.Request(url)
        req.add_header('Accept', 'application/json, text/plain, */*')
        req.add_header('Referer', referer)
        req.add_header('Origin', 'https://www.fanbox.cc')
        req.add_header('User-Agent', self._config.useragent)

        res = self.open_with_retry(req)
        # read the json response
        response = res.read()
        res.close()
        _tzInfo = None
        if self._config.useLocalTimezone:
            _tzInfo = PixivHelper.LocalUTCOffsetTimezone()
        artists = FanboxArtist.parseArtists(page=response, tzInfo=_tzInfo)
        return artists
    def getImagePage(self,
                     image_id,
                     parent=None,
                     from_bookmark=False,
                     bookmark_count=-1,
                     image_response_count=-1):
        image = None
        response = None
        PixivHelper.GetLogger().debug("Getting image page: %s", image_id)
        url = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id={0}".format(
            image_id)
        # response = self.open(url).read()
        response = self.getPixivPage(url, returnParsed=False).read()
        self.handleDebugMediumPage(response, image_id)

        # Issue #355 new ui handler
        image = None
        try:
            if response.find("globalInitData") > 0:
                PixivHelper.print_and_log('debug', 'New UI Mode')

                # Issue #420
                _tzInfo = None
                if self._config.useLocalTimezone:
                    _tzInfo = PixivHelper.LocalUTCOffsetTimezone()

                image = PixivModelWhiteCube.PixivImage(
                    image_id,
                    response,
                    parent,
                    from_bookmark,
                    bookmark_count,
                    image_response_count,
                    dateFormat=self._config.dateFormat,
                    tzInfo=_tzInfo)

                if image.imageMode == "ugoira_view":
                    ugoira_meta_url = "https://www.pixiv.net/ajax/illust/{0}/ugoira_meta".format(
                        image_id)
                    meta_response = self.open_with_retry(
                        ugoira_meta_url).read()
                    image.ParseUgoira(meta_response)

                if parent is None:
                    if from_bookmark:
                        image.originalArtist.reference_image_id = image_id
                        self.getMemberInfoWhitecube(
                            image.originalArtist.artistId,
                            image.originalArtist)
                    else:
                        image.artist.reference_image_id = image_id
                        self.getMemberInfoWhitecube(image.artist.artistId,
                                                    image.artist)
        except:
            PixivHelper.GetLogger().error("Respose data: \r\n %s", response)
            raise

        return (image, response)
Beispiel #6
0
    def fanboxGetPostsFromArtist(self, artist_id, next_url=""):
        ''' get all posts from the supported user from https://www.pixiv.net/ajax/fanbox/creator?userId=15521131 '''
        if next_url is None or next_url == "":
            url = "https://www.pixiv.net/ajax/fanbox/creator?userId={0}".format(
                artist_id)
        elif next_url.startswith("https://"):
            url = next_url
        else:
            url = "https://www.pixiv.net" + next_url

        # Fix #494
        PixivHelper.print_and_log('info', 'Getting posts from ' + url)
        referer = "https://www.pixiv.net/fanbox/creator/{0}".format(artist_id)
        req = mechanize.Request(url)
        req.add_header('Accept', 'application/json, text/plain, */*')
        req.add_header('Referer', referer)
        req.add_header('Origin', 'https://www.pixiv.net')
        req.add_header('User-Agent', self._config.useragent)

        res = self.open_with_retry(req)
        response = res.read()
        PixivHelper.get_logger().debug(response.decode('utf8'))
        res.close()
        # Issue #420
        _tzInfo = None
        if self._config.useLocalTimezone:
            _tzInfo = PixivHelper.LocalUTCOffsetTimezone()
        result = FanboxArtist(artist_id, response, tzInfo=_tzInfo)

        pixivArtist = PixivArtist(artist_id)
        self.getMemberInfoWhitecube(artist_id, pixivArtist)
        result.artistName = pixivArtist.artistName
        result.artistToken = pixivArtist.artistToken

        for post in result.posts:
            # https://fanbox.pixiv.net/api/post.info?postId=279561
            # https://www.pixiv.net/fanbox/creator/104409/post/279561
            p_url = "https://fanbox.pixiv.net/api/post.info?postId={0}".format(
                post.imageId)
            p_referer = "https://www.pixiv.net/fanbox/creator/{0}/post/{1}".format(
                artist_id, post.imageId)
            PixivHelper.get_logger().debug('Getting post detail from %s',
                                           p_url)
            p_req = mechanize.Request(p_url)
            p_req.add_header('Accept', 'application/json, text/plain, */*')
            p_req.add_header('Referer', p_referer)
            p_req.add_header('Origin', 'https://www.pixiv.net')
            p_req.add_header('User-Agent', self._config.useragent)

            p_res = self.open_with_retry(p_req)
            p_response = p_res.read()
            PixivHelper.get_logger().debug(p_response.decode('utf8'))
            p_res.close()
            js = demjson.decode(p_response)
            post.parsePost(js["body"])

        return result
Beispiel #7
0
    def fanboxGetPostsFromArtist(self, artist_id, next_url=""):
        ''' get all posts from the supported user from https://www.pixiv.net/ajax/fanbox/creator?userId=15521131 '''
        if next_url is None or next_url == "":
            url = "https://www.pixiv.net/ajax/fanbox/creator?userId={0}".format(artist_id)
        else:
            url = "https://www.pixiv.net" + next_url

        PixivHelper.print_and_log('info', 'Getting posts from ' + url)
        response = self.open_with_retry(url).read()
        # Issue #420
        _tzInfo = None
        if self._config.useLocalTimezone:
            _tzInfo = PixivHelper.LocalUTCOffsetTimezone()
        result = FanboxArtist(artist_id, response, tzInfo=_tzInfo)

        pixivArtist = PixivModelWhiteCube.PixivArtist(artist_id)
        self.getMemberInfoWhitecube(artist_id, pixivArtist)
        result.artistName = pixivArtist.artistName
        result.artistToken = pixivArtist.artistToken

        return result
Beispiel #8
0
    def __init__(self,
                 username,
                 password,
                 proxies=None,
                 validate_ssl=True,
                 refresh_token=None):
        if username is None or len(username) <= 0:
            raise Exception("Username cannot empty!")
        if password is None or len(password) <= 0:
            raise Exception("Password cannot empty!")

        self._username = username
        self._password = password
        self._proxies = proxies
        if refresh_token is not None and len(refresh_token) > 0:
            self._refresh_token = refresh_token
        else:
            self._refresh_token = None
        self._access_token = None
        self._tzInfo = PixivHelper.LocalUTCOffsetTimezone()
        self._validate_ssl = validate_ssl
    def fanboxGetArtistById(self, id):
        self.fanbox_is_logged_in()
        if re.match(r"^\d+$", id):
            id_type = "userId"
        else:
            id_type = "creatorId"

        url = f'https://api.fanbox.cc/creator.get?{id_type}={id}'
        PixivHelper.print_and_log('info', f'Getting artist information from {url}')
        referer = "https://www.fanbox.cc"
        if id_type == "creatorId":
            referer += f"/@{id}"

        req = mechanize.Request(url)
        req.add_header('Accept', 'application/json, text/plain, */*')
        req.add_header('Referer', referer)
        req.add_header('Origin', 'https://www.fanbox.cc')
        req.add_header('User-Agent', self._config.useragent)

        res = self.open_with_retry(req)
        # read the json response
        response = res.read()
        res.close()
        _tzInfo = None
        if self._config.useLocalTimezone:
            _tzInfo = PixivHelper.LocalUTCOffsetTimezone()

        js = demjson.decode(response)
        if "error" in js and js["error"]:
            raise PixivException("Error when requesting Fanbox", 9999, js)

        if "body" in js and js["body"] is not None:
            js_body = js["body"]
            artist = FanboxArtist(js_body["user"]["userId"],
                                  js_body["user"]["name"],
                                  js_body["creatorId"],
                                  tzInfo=_tzInfo)
            self.fanboxUpdateArtistToken(artist)
            return artist
Beispiel #10
0
    def getImagePage(self,
                     image_id,
                     parent=None,
                     from_bookmark=False,
                     bookmark_count=-1,
                     image_response_count=-1):
        image = None
        response = None
        PixivHelper.GetLogger().debug("Getting image page: %s", image_id)
        if self._isWhitecube:
            pass
##            url = "https://www.pixiv.net/rpc/whitecube/index.php?mode=work_details_modal_whitecube&id={0}&tt={1}".format(image_id, self._whitecubeToken)
##            response = self.open(url).read()
##            self.handleDebugMediumPage(response, image_id)
##            # PixivHelper.GetLogger().debug(response)
##
##            image = PixivModelWhiteCube.PixivImage(image_id,
##                                                   response,
##                                                   parent,
##                                                   from_bookmark,
##                                                   bookmark_count,
##                                                   image_response_count,
##                                                   dateFormat=self._config.dateFormat)
##            # overwrite artist info
##            if from_bookmark:
##                self.getMemberInfoWhitecube(image.originalArtist.artistId, image.originalArtist)
##            else:
##                self.getMemberInfoWhitecube(image.artist.artistId, image.artist)

        else:
            url = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id={0}".format(
                image_id)
            # response = self.open(url).read()
            response = self.getPixivPage(url, returnParsed=False).read()
            self.handleDebugMediumPage(response, image_id)

            # Issue #355 new ui handler
            image = None
            try:
                if response.find("globalInitData") > 0:
                    PixivHelper.print_and_log('debug', 'New UI Mode')

                    # Issue #420
                    _tzInfo = None
                    if self._config.useLocalTimezone:
                        _tzInfo = PixivHelper.LocalUTCOffsetTimezone()

                    image = PixivModelWhiteCube.PixivImage(
                        image_id,
                        response,
                        parent,
                        from_bookmark,
                        bookmark_count,
                        image_response_count,
                        dateFormat=self._config.dateFormat,
                        tzInfo=_tzInfo)

                    if image.imageMode == "ugoira_view":
                        ugoira_meta_url = "https://www.pixiv.net/ajax/illust/{0}/ugoira_meta".format(
                            image_id)
                        meta_response = self.open(ugoira_meta_url).read()
                        image.ParseUgoira(meta_response)

    ##                    PixivHelper.GetLogger().debug("animation.js")
    ##                    PixivHelper.GetLogger().debug(image.ugoira_data)

                    if parent is None:
                        if from_bookmark:
                            self.getMemberInfoWhitecube(
                                image.originalArtist.artistId,
                                image.originalArtist)
                        else:
                            self.getMemberInfoWhitecube(
                                image.artist.artistId, image.artist)

                else:
                    parsed = BeautifulSoup(response)
                    image = PixivModel.PixivImage(
                        image_id,
                        parsed,
                        parent,
                        from_bookmark,
                        bookmark_count,
                        image_response_count,
                        dateFormat=self._config.dateFormat)
                    if image.imageMode == "ugoira_view" or image.imageMode == "bigNew":
                        image.ParseImages(parsed)
                    parsed.decompose()
            except:
                PixivHelper.GetLogger().error("Respose data: \r\n %s",
                                              response)
                raise

        return (image, response)