def user_bookmarks_artworks(self, user_id, dir_path=None): artwork_ids = [a["id"] for a in self.bookmarks(user_id)] limit = None if dir_path and utils.file_names(dir_path): file_names = utils.file_names(dir_path, separator="_") limit = utils.first_index(artwork_ids, lambda id: id in file_names) with ThreadPool(self.threads) as pool: artworks = pool.map(self.artwork, artwork_ids[:limit]) return artworks
def rankings_artworks(self, mode, content, date, limit, dir_path=None): artwork_ids = [ str(a["illust_id"]) for a in self.rankings(mode, content, date, limit) ] if dir_path and utils.file_names(dir_path): file_names = utils.file_names(dir_path, separator="_") artwork_ids = [a for a in artwork_ids if a not in file_names] with ThreadPool(self.threads) as pool: artworks = pool.map(self.artwork, artwork_ids) return artworks
def user_artworks(self, user_id, dir_path=None): res = self.request( "GET", f"https://www.pixiv.net/ajax/user/{user_id}/profile/all") json = res.json()["body"] artwork_ids = [*json["illusts"], *json["manga"]] # sort ids in descending order, i.e. newest to oldest artwork_ids.sort(key=int, reverse=True) limit = None if dir_path and utils.file_names(dir_path): file_names = utils.file_names(dir_path, separator="_") limit = utils.first_index(artwork_ids, lambda id: id in file_names) with ThreadPool(self.threads) as pool: artworks = pool.map(self.artwork, artwork_ids[:limit]) return artworks
def user_artworks(self, user_id, dir_path=None): url = 'https://www.deviantart.com/_napi/da-user-profile/api/gallery/contents?' artworks = [] offset = 0 # list of artwork ids file_names = utils.file_names( dir_path, pattern=r'-(\d+)\.(.+)$') if dir_path else [] while True: print('load offset ' + str(offset)) payload = { 'username': user_id, 'offset': str(offset), 'limit': '24', 'all_folder': 'true', 'mode': 'newest' } json = self.request('GET', url, params=payload).json() for a in json['results']: if str(a['deviation']['deviationId']) in file_names: return artworks artworks.append(a['deviation']) if not json['hasMore']: break offset += 24 return artworks
def collection_artworks(self, collection, dir_path=None): # e.g. shemetz/favourites/77974139/deviantart-wallpapers username, kind_place, folderid, lowercase_name = collection.split("/") if kind_place == "favourites": kind = "collection" elif kind_place == "gallery": kind = "gallery" else: raise ValueError( f'Expected "favourites" or "gallery" instead of "{kind_place}", in {collection}' ) url = f'https://www.deviantart.com/_napi/da-user-profile/api/{kind}/contents' artworks = [] offset = 0 file_names = utils.file_names( dir_path, pattern=r'-(\d+)\.(.+)$') if dir_path else [] while True: payload = { 'username': username, 'folderid': folderid, 'offset': str(offset), 'limit': '24', } json = self.request('GET', url, params=payload).json() for a in json['results']: if str(a['deviation']['deviationId']) in file_names: return artworks artworks.append(a['deviation']) if not json['hasMore']: break offset += 24 return artworks
def artist_artworks(self, artist_id, dir_path): artist = self.artist(artist_id) artworks = [] file_names = utils.file_names(dir_path, pattern=r"-(\d+)\.(.+)$") with ThreadPool(self.threads) as pool: for artwork in pool.imap(self.artwork, artist["projects"]): for a in artwork["assets"]: if str(a["id"]) in file_names: pool.terminate() break else: artworks.append(artwork) continue break return artworks