Exemplo n.º 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
Exemplo n.º 2
0
    def testFanboxArtistVideo(self):
        reader = open('./test/creator_posts_with_video.json',
                      'r',
                      encoding="utf-8")
        p = reader.read()
        reader.close()

        artist = FanboxArtist(711048, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(711048, p)
        self.assertIsNotNone(result)

        self.assertEqual(artist.artistId, 711048)
        self.assertTrue(artist.hasNextPage)
        self.assertTrue(len(artist.nextUrl) > 0)
        self.assertTrue(len(result) > 0)

        # post-201946 article
        self.assertEqual(result[4].imageId, 330905)
        self.assertTrue(len(result[4].imageTitle) > 0)
        self.assertEqual(
            result[4].coverImageUrl,
            u'https://pixiv.pximg.net/fanbox/public/images/post/330905/cover/3A2zPUg4s6iz17MM0Z45eWBj.jpeg'
        )
        self.assertEqual(result[4].type, "video")
        self.assertEqual(len(result[4].images), 0)
        self.assertEqual(len(result[4].body_text), 109)
        print(result[4].body_text)
Exemplo n.º 3
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
Exemplo n.º 4
0
    def testFanboxNewApi(self):
        reader = open('./test/fanbox-posts-new-api.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()
        artist = FanboxArtist(104409, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(104409, p)
        self.assertIsNotNone(result)

        self.assertEqual(len(result), 10)
        self.assertEqual(result[0].imageId, 577968)
        self.assertEqual(len(result[0].images), 2)
        self.assertEqual(result[1].imageId, 535518)
        self.assertEqual(len(result[1].images), 2)
Exemplo n.º 5
0
    def testFanboxArtistPostsNextPage(self):
        # https://fanbox.pixiv.net/api/post.listCreator?userId=91029&maxPublishedDatetime=2019-07-25%2004%3A27%3A54&maxId=481268&limit=10
        reader = open('./test/Fanbox_artist_posts_nextpage.json', 'r', encoding="utf-8")
        p2 = reader.read()
        reader.close()

        artist = FanboxArtist(91029, "", "", None)
        result = artist.parsePosts(p2)
        # result = FanboxArtist(91029, p2)
        self.assertIsNotNone(result)

        self.assertEqual(artist.artistId, 91029)
        self.assertTrue(artist.hasNextPage)
        self.assertTrue(artist.nextUrl is not None)
        self.assertEqual(len(result), 10)
    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 testFanboxPost_url_embed(self):
        reader = open('./test/fanbox_urlembed.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()

        js = json.loads(p)

        dummy_artist = FanboxArtist(1, "kurikara", "kurikara")

        # https://www.fanbox.cc/@kurikara/posts/4071336 => https://api.fanbox.cc/post.info?postId=4071336
        post = FanboxPost(4071336, dummy_artist, js["body"], None)

        self.assertIsNotNone(post)

        # post-201946 article
        self.assertEqual(post.imageId, 4071336)
        self.assertTrue(len(post.imageTitle) > 0)
        self.assertEqual(
            post.coverImageUrl,
            "https://pixiv.pximg.net/fanbox/public/images/post/4071336/cover/17bKPzVXhXtTz8dCeDMDg8qR.jpeg"
        )
        self.assertEqual(post.type, "article")
        self.assertEqual(len(post.images), 1)
        self.assertEqual(len(post.descriptionUrlList), 2)

        # template = open('./template.html', 'r', encoding="utf-8").read()
        # post.WriteHtml(template, False, "./4071336.html")
        self.assertEqual(len(post.body_text), 3598)
    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
Exemplo n.º 9
0
    def testFanboxArtistPosts(self):
        p = open('./test/Fanbox_artist_posts.json', 'r').read()
        result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 15521131)
        self.assertTrue(result.hasNextPage)
        self.assertTrue(len(result.nextUrl) > 0)
        self.assertTrue(len(result.posts) > 0)

        for post in result.posts:
            self.assertFalse(post.is_restricted)

        # post-136761 image
        self.assertEqual(result.posts[0].imageId, 136761)
        self.assertTrue(len(result.posts[0].imageTitle) > 0)
        self.assertTrue(len(result.posts[0].coverImageUrl) > 0)
        self.assertEqual(result.posts[0].type, "image")
        self.assertEqual(len(result.posts[0].images), 5)

        # post-132919 text
        self.assertEqual(result.posts[2].imageId, 132919)
        self.assertTrue(len(result.posts[2].imageTitle) > 0)
        self.assertIsNone(result.posts[2].coverImageUrl)
        self.assertEqual(result.posts[2].type, "text")
        self.assertEqual(len(result.posts[2].images), 0)

        # post-79695 image
        self.assertEqual(result.posts[3].imageId, 79695)
        self.assertTrue(len(result.posts[3].imageTitle) > 0)
        self.assertIsNone(result.posts[3].coverImageUrl)
        self.assertEqual(result.posts[3].type, "image")
        self.assertEqual(len(result.posts[3].images), 4)
Exemplo n.º 10
0
    def testFanboxOldApi(self):
        reader = open('./test/fanbox-posts-old-api.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()
        artist = FanboxArtist(104409, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(104409, p)
        self.assertIsNotNone(result)

        self.assertEqual(len(result), 2)
        self.assertEqual(result[0].imageId, 916)
        self.assertEqual(len(result[0].images), 8)
        print(result[0].images)
        self.assertEqual(result[1].imageId, 915)
        self.assertEqual(len(result[1].images), 1)
        print(result[1].images)
Exemplo n.º 11
0
    def testFanboxArtistPostsRestrictedNextPage(self):
        reader = open('./test/Fanbox_artist_posts_next_page_restricted.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()
        artist = FanboxArtist(15521131, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)

        self.assertEqual(artist.artistId, 15521131)
        self.assertFalse(artist.hasNextPage)
        self.assertTrue(artist.nextUrl is None)
        self.assertEqual(len(result), 6)

        self.assertTrue(result[0].is_restricted)
        self.assertFalse(result[1].is_restricted)
Exemplo n.º 12
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(url).read()
        result = FanboxArtist(artist_id, response)

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

        return result
Exemplo n.º 13
0
    def testFanboxArtistPostsNextPage(self):
        p2 = open('./test/Fanbox_artist_posts_nextpage.json', 'r').read()
        result = FanboxArtist(15521131, p2)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 15521131)
        self.assertFalse(result.hasNextPage)
        self.assertTrue(result.nextUrl is None)
        self.assertEqual(len(result.posts), 1)
Exemplo n.º 14
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(url).read()
        result = FanboxArtist(artist_id, response)

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

        return result
Exemplo n.º 15
0
    def testFanboxNewApi(self):
        p = open('./test/fanbox-posts-new-api.json', 'r').read()
        result = FanboxArtist(104409, p)
        self.assertIsNotNone(result)

        self.assertEqual(len(result.posts), 10)
        self.assertEqual(result.posts[0].imageId, 577968)
        self.assertEqual(len(result.posts[0].images), 2)
        self.assertEqual(result.posts[1].imageId, 535518)
        self.assertEqual(len(result.posts[1].images), 2)
Exemplo n.º 16
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
    def testFanboxArtistPostsRestrictedNextPage(self):
        p = open('./test/Fanbox_artist_posts_next_page_restricted.json', 'r').read()
        result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 15521131)
        self.assertFalse(result.hasNextPage)
        self.assertTrue(result.nextUrl is None)
        self.assertEqual(len(result.posts), 6)

        self.assertTrue(result.posts[0].is_restricted)
        self.assertFalse(result.posts[1].is_restricted)
Exemplo n.º 18
0
    def testFanboxOldApi(self):
        p = open('./test/fanbox-posts-old-api.json', 'r').read()
        result = FanboxArtist(104409, p)
        self.assertIsNotNone(result)

        self.assertEqual(len(result.posts), 2)
        self.assertEqual(result.posts[0].imageId, 916)
        self.assertEqual(len(result.posts[0].images), 8)
        print(result.posts[0].images)
        self.assertEqual(result.posts[1].imageId, 915)
        self.assertEqual(len(result.posts[1].images), 1)
        print(result.posts[1].images)
Exemplo n.º 19
0
    def testFanboxSupportedArtist(self):
        # https://fanbox.pixiv.net/api/plan.listSupporting
        reader = open('./test/Fanbox_supported_artist.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()
        result = FanboxArtist.parseArtistIds(p)
        self.assertIsNotNone(result)

        self.assertEqual(len(result), 52)
        self.assertTrue('4820' in result)
        self.assertTrue('11443' in result)
        self.assertTrue('226267' in result)
Exemplo n.º 20
0
    def testFanboxArtistPostsRestricted(self):
        p = open('./test/Fanbox_artist_posts_restricted.json', 'r').read()
        result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 15521131)
        self.assertTrue(result.hasNextPage)
        self.assertTrue(len(result.nextUrl) > 0)
        self.assertEqual(len(result.posts), 10)

        for post in result.posts:
            self.assertTrue(post.is_restricted)
Exemplo n.º 21
0
    def testFanboxArtistArticleEmbedTwitter(self):
        reader = open('./test/creator_embedMap.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()

        artist = FanboxArtist(68813, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(68813, p)
        self.assertIsNotNone(result)

        self.assertEqual(artist.artistId, 68813)
        self.assertFalse(artist.hasNextPage)
        self.assertTrue(len(result) > 0)

        # post-201946 article
        self.assertEqual(result[0].imageId, 285502)
        self.assertTrue(len(result[0].imageTitle) > 0)
        self.assertEqual(result[0].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/285502/cover/orx9TCsiPFi5sgDdbvg4zwkX.jpeg')
        self.assertEqual(result[0].type, "article")
        self.assertEqual(len(result[0].images), 7)
        self.assertEqual(len(result[0].body_text), 3164)
Exemplo n.º 22
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
Exemplo n.º 23
0
    def testFanboxArtistArticleFileMap(self):
        reader = open('./test/creator_with_filemap.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()
        artist = FanboxArtist(190026, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(190026, p)
        self.assertIsNotNone(result)

        self.assertEqual(artist.artistId, 190026)
        self.assertTrue(artist.hasNextPage)
        self.assertTrue(len(artist.nextUrl) > 0)
        self.assertTrue(len(result) > 0)

        # post-201946 article
        self.assertEqual(result[0].imageId, 210980)
        self.assertTrue(len(result[0].imageTitle) > 0)
        self.assertIsNone(result[0].coverImageUrl)
        self.assertEqual(result[0].type, "article")
        self.assertEqual(len(result[0].images), 15)
        self.assertEqual(len(result[0].body_text), 3006)
Exemplo n.º 24
0
    def testFanboxArtistPosts(self):
        reader = open('./test/Fanbox_artist_posts.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()

        artist = FanboxArtist(15521131, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)

        self.assertEqual(artist.artistId, 15521131)
        self.assertTrue(artist.hasNextPage)
        self.assertTrue(len(artist.nextUrl) > 0)
        self.assertTrue(len(result) > 0)

        for post in result:
            self.assertFalse(post.is_restricted)

        # post-136761 image
        self.assertEqual(result[0].imageId, 136761)
        self.assertTrue(len(result[0].imageTitle) > 0)
        self.assertTrue(len(result[0].coverImageUrl) > 0)
        self.assertEqual(result[0].type, "image")
        self.assertEqual(len(result[0].images), 5)

        # post-132919 text
        self.assertEqual(result[2].imageId, 132919)
        self.assertTrue(len(result[2].imageTitle) > 0)
        self.assertIsNotNone(result[2].coverImageUrl)
        self.assertEqual(result[2].type, "text")
        self.assertEqual(len(result[2].images), 0)

        # post-79695 image
        self.assertEqual(result[3].imageId, 79695)
        self.assertTrue(len(result[3].imageTitle) > 0)
        self.assertIsNotNone(result[3].coverImageUrl)
        self.assertEqual(result[3].type, "image")
        self.assertEqual(len(result[3].images), 4)
    def testFanboxArtistArticleEmbedTwitter(self):
        p = open('./test/creator_embedMap.json', 'r').read()
        result = FanboxArtist(68813, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 68813)
        self.assertFalse(result.hasNextPage)
        self.assertTrue(len(result.posts) > 0)

        # post-201946 article
        self.assertEqual(result.posts[0].imageId, 285502)
        self.assertTrue(len(result.posts[0].imageTitle) > 0)
        self.assertEqual(result.posts[0].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/285502/cover/orx9TCsiPFi5sgDdbvg4zwkX.jpeg')
        self.assertEqual(result.posts[0].type, "article")
        self.assertEqual(len(result.posts[0].images), 7)
        self.assertEqual(len(result.posts[0].body_text), 3095)
Exemplo n.º 26
0
    def testFanboxArtistVideo(self):
        p = open('./test/creator_posts_with_video.json', 'r').read()
        result = FanboxArtist(711048, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 711048)
        self.assertTrue(result.hasNextPage)
        self.assertTrue(len(result.nextUrl) > 0)
        self.assertTrue(len(result.posts) > 0)

        # post-201946 article
        self.assertEqual(result.posts[4].imageId, 330905)
        self.assertTrue(len(result.posts[4].imageTitle) > 0)
        self.assertEqual(result.posts[4].coverImageUrl, u'https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/330905/cover/3A2zPUg4s6iz17MM0Z45eWBj.jpeg')
        self.assertEqual(result.posts[4].type, "video")
        self.assertEqual(len(result.posts[4].images), 0)
        self.assertEqual(len(result.posts[4].body_text), 99)
Exemplo n.º 27
0
    def testFanboxArtistArticleFileMap(self):
        p = open('./test/creator_with_filemap.json', 'r').read()
        result = FanboxArtist(190026, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 190026)
        self.assertTrue(result.hasNextPage)
        self.assertTrue(len(result.nextUrl) > 0)
        self.assertTrue(len(result.posts) > 0)

        # post-201946 article
        self.assertEqual(result.posts[0].imageId, 210980)
        self.assertTrue(len(result.posts[0].imageTitle) > 0)
        self.assertIsNone(result.posts[0].coverImageUrl)
        self.assertEqual(result.posts[0].type, "article")
        self.assertEqual(len(result.posts[0].images), 15)
        self.assertEqual(len(result.posts[0].body_text), 3006)
Exemplo n.º 28
0
    def testFanboxArtistArticle(self):
        p = open('./test/Fanbox_artist_posts_article.json', 'r').read()
        result = FanboxArtist(190026, p)
        self.assertIsNotNone(result)

        self.assertEqual(result.artistId, 190026)
        self.assertTrue(result.hasNextPage)
        self.assertTrue(len(result.nextUrl) > 0)
        self.assertTrue(len(result.posts) > 0)

        # post-201946 article
        self.assertEqual(result.posts[0].imageId, 201946)
        self.assertTrue(len(result.posts[0].imageTitle) > 0)
        self.assertIsNone(result.posts[0].coverImageUrl)
        self.assertEqual(result.posts[0].type, "article")
        self.assertEqual(len(result.posts[0].images), 5)
        self.assertEqual(len(result.posts[0].body_text), 1292)
Exemplo n.º 29
0
    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
Exemplo n.º 30
0
    def testFanboxFilename(self):
        reader = open('./test/Fanbox_artist_posts.json', 'r', encoding="utf-8")
        p = reader.read()
        reader.close()
        artist = FanboxArtist(15521131, "", "", None)
        result = artist.parsePosts(p)
        # result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)
        root_dir = os.path.abspath(os.path.curdir)
        post = result[0]

        # # 'https://pixiv.pximg.net/fanbox/public/images/post/136761/cover/OqhhcslOfbzZpHyTfJNtnIWm.jpeg'
        # big_cover_url = post.images[0]
        # 'https://fanbox.pixiv.net/images/post/136761/hcXl48iORoJykmrR3zPZEoUu.jpeg'
        image_url = post.images[0]

        # current_page = 0
        # fake_image_url = image_url.replace("{0}/".format(post.imageId), "{0}_p{1}_".format(post.imageId, current_page))

        # # re_page = temp.findall(fake_image_url)
        # re_page = temp.findall(image_url)
        # self.assertIsNotNone(re_page)
        # self.assertEqual(re_page[0], u"0")
        # re_page = temp.findall(big_cover_url)
        # self.assertIsNotNone(re_page)
        # self.assertEqual(re_page[0], u"0")

        def simple_from_images():
            filename_format = '%title%_%urlFilename%'

            filename = PixivHelper.make_filename(filename_format,
                                                 post,
                                                 artistInfo=artist,
                                                 tagsSeparator=" ",
                                                 tagsLimit=0,
                                                 fileUrl=image_url,
                                                 bookmark=None,
                                                 searchTags='')
            filename = PixivHelper.sanitize_filename(filename, root_dir)

            self.assertEqual(
                filename,
                root_dir + os.sep + "アスナさん02_hcXl48iORoJykmrR3zPZEoUu.jpeg")

        simple_from_images()

        def more_format():
            # from images
            filename_format = '%member_id%' + os.sep + '%image_id%_p%page_index%_%title%_%urlFilename%_%works_date%'

            filename = PixivHelper.make_filename(filename_format,
                                                 post,
                                                 artistInfo=artist,
                                                 tagsSeparator=" ",
                                                 tagsLimit=0,
                                                 fileUrl=image_url,
                                                 bookmark=None,
                                                 searchTags='')
            filename = PixivHelper.sanitize_filename(filename, root_dir)

            expected_name = root_dir + os.sep + u"15521131" + os.sep + u"136761_p_アスナさん02_hcXl48iORoJykmrR3zPZEoUu_2018-08-26 20:28:16.jpeg"
            if platform.system() == 'Windows':
                expected_name = root_dir + os.sep + u"15521131" + os.sep + u"136761_p_アスナさん02_hcXl48iORoJykmrR3zPZEoUu_2018-08-26 20_28_16.jpeg"

            self.assertEqual(filename, expected_name)

        more_format()

        def cover_more_format():
            # https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/96862/cover/6SRpcQwIUuJdeZbhn5q85l9x.jpeg
            fake_image_url = post.coverImageUrl.replace(
                "{0}/cover/".format(post.imageId), "{0}_".format(post.imageId))
            print(fake_image_url)
            filename_format = '%member_id%' + os.sep + '%image_id%_%title%_%urlFilename%_%works_date%'

            filename = PixivHelper.make_filename(filename_format,
                                                 post,
                                                 artistInfo=artist,
                                                 tagsSeparator=" ",
                                                 tagsLimit=0,
                                                 fileUrl=fake_image_url,
                                                 bookmark=None,
                                                 searchTags='')
            filename = PixivHelper.sanitize_filename(filename, root_dir)

            expected_name = root_dir + os.sep + u"15521131" + os.sep + u"136761_アスナさん02_136761_OqhhcslOfbzZpHyTfJNtnIWm_2018-08-26 20:28:16.jpeg"
            if platform.system() == 'Windows':
                expected_name = root_dir + os.sep + u"15521131" + os.sep + u"136761_アスナさん02_136761_OqhhcslOfbzZpHyTfJNtnIWm_2018-08-26 20_28_16.jpeg"

            self.assertEqual(filename, expected_name)

        cover_more_format()
Exemplo n.º 31
0
    def testFanboxFilename(self):
        p = open('./test/Fanbox_artist_posts.json', 'r').read()
        result = FanboxArtist(15521131, p)
        self.assertIsNotNone(result)
        root_dir = os.path.abspath(os.path.curdir)
        post = result.posts[0]
        image_url = post.images[0]
        current_page = 0
        fake_image_url = image_url.replace(
            "{0}/".format(post.imageId),
            "{0}_p{1}_".format(post.imageId, current_page))

        re_page = temp.findall(fake_image_url)
        self.assertIsNotNone(re_page)
        self.assertEqual(re_page[0], u"0")

        def simple_from_images():
            filename_format = '%title%_%urlFilename%'

            filename = PixivHelper.make_filename(filename_format,
                                                 post,
                                                 artistInfo=result,
                                                 tagsSeparator=" ",
                                                 tagsLimit=0,
                                                 fileUrl=fake_image_url,
                                                 bookmark=None,
                                                 searchTags='')
            filename = PixivHelper.sanitize_filename(filename, root_dir)

            self.assertEqual(
                filename, root_dir + os.sep +
                u"アスナさん02_136761_p0_hcXl48iORoJykmrR3zPZEoUu.jpeg")

        simple_from_images()

        def more_format():
            # from images
            filename_format = '%member_id%' + os.sep + '%image_id%_p%page_index%_%title%_%urlFilename%_%works_date%'

            filename = PixivHelper.make_filename(filename_format,
                                                 post,
                                                 artistInfo=result,
                                                 tagsSeparator=" ",
                                                 tagsLimit=0,
                                                 fileUrl=fake_image_url,
                                                 bookmark=None,
                                                 searchTags='')
            filename = PixivHelper.sanitize_filename(filename, root_dir)

            self.assertEqual(
                filename, root_dir + os.sep + u"15521131" + os.sep +
                u"136761_p0_アスナさん02_136761_p0_hcXl48iORoJykmrR3zPZEoUu_2018-08-26 20_28_16.jpeg"
            )

        more_format()

        def cover_more_format():
            # https://pixiv.pximg.net/c/1200x630_90_a2_g5/fanbox/public/images/post/96862/cover/6SRpcQwIUuJdeZbhn5q85l9x.jpeg
            fake_image_url = post.coverImageUrl.replace(
                "{0}/cover/".format(post.imageId), "{0}_".format(post.imageId))
            print(fake_image_url)
            filename_format = '%member_id%' + os.sep + '%image_id%_%title%_%urlFilename%_%works_date%'

            filename = PixivHelper.make_filename(filename_format,
                                                 post,
                                                 artistInfo=result,
                                                 tagsSeparator=" ",
                                                 tagsLimit=0,
                                                 fileUrl=fake_image_url,
                                                 bookmark=None,
                                                 searchTags='')
            filename = PixivHelper.sanitize_filename(filename, root_dir)

            self.assertEqual(
                filename, root_dir + os.sep + u"15521131" + os.sep +
                u"136761_アスナさん02_136761_OqhhcslOfbzZpHyTfJNtnIWm_2018-08-26 20_28_16.jpeg"
            )

        cover_more_format()