Example #1
0
class pixivComm:
    token = ""
    pixivClient = None
    def __init__(self, pixivCreds):
        self.pixivClient = Client()
        self.pixivClient.login(pixivCreds["user"], pixivCreds["pw"])
        self.token = self.pixivClient.refresh_token

    def searchImage(self, tag):
        self.pixivClient.authenticate(self.token)
        searchStr = tag.replace('_', ' ')
        print(searchStr, tag)

        results = self.pixivClient.search_illustrations(searchStr)
        illustrations = results["illustrations"]
        randIllust = illustrations[randint(0,len(illustrations) - 1)]
        print(dir(randIllust))
        while randIllust.type != enums.ContentType.ILLUSTRATION:
            randIllust = illustrations[randint(0,len(illustrations) - 1)]
    
        self.getImage(randIllust)
        imageURL =  randIllust.image_urls[enums.Size.ORIGINAL]
        imageURL = glob.glob("./pixiv/" + str(randIllust.id) + "*")[0]
        return imageURL

    def getImage(self, illustration):
        illustration.download(pathlib.Path("./pixiv", size=enums.Size.ORIGINAL), filename = illustration.id)

    def testFetch(self):
        self.pixivClient.authenticate(self.token)
        illus = self.pixivClient.fetch_illustration(82417326)
        self.getImage(illus)
Example #2
0
                break
        if not get['next']:
            print("No more art to download.")
            break
    get = client.fetch_user_illustrations(artist_id, offset=get['next'])

#searches for tags provided.

if needs == "search":
    tags = input("Enter the tags you want to look up.\n")
    downloaded = 0
    num = input("How much art do you want to donwload?\n")
    print(f"Looking for {num} images.")
    directory = Path.home() / 'PixivImages'
    get = client.search_illustrations(word=tags,
                                      search_target=SearchTarget.TAGS_PARTIAL,
                                      sort=Sort.DATE_DESC)
    print(f"Searching for {tags}")
    while True:
        for illustration in get['illustrations']:
            illustration.download(directory=directory, size=Size.ORIGINAL)
            downloaded += 1

            if int(downloaded) == int(num):
                print("Finished downloading all the images.")
                stop = True
                break
        if stop:
            break
        if not get['next']:
            print("No more art to download.")