Beispiel #1
0
def download_other_user_items_example():
    pixiv = Pikax(settings.username, settings.password)

    other_user = pixiv.visits(user_id=201323)  # visit other user by id

    illusts = other_user.illusts(limit=25)  # get his illustrations
    pixiv.download(illusts)  # download

    mangas = other_user.mangas(limit=10)  # get his mangas
    pixiv.download(mangas)  # download

    bookmarks = other_user.bookmarks(limit=15)  # get his bookmarks
    pixiv.download(bookmarks)  # download
Beispiel #2
0
class PikaxHandler:
    def __init__(self):
        self.pikax = Pikax()
        self.user = None
        self.logged = False

    def login(self, username, password):
        status, client = LoginHandler().android_login(username, password)
        if status is LoginHandler.LoginStatus.ANDROID:
            self.pikax.logged_client = client
            self.logged = True
        else:
            raise PikaxException(texts.get('PIKAX_FAILED_LOGIN'))

    def rank(self, rank_type, limit, date, content, folder, pages_limit):
        try:
            old_limit = settings.MAX_PAGES_PER_ARTWORK
            if pages_limit:
                settings.MAX_PAGES_PER_ARTWORK = 1
            result = self.pikax.rank(rank_type=rank_type, limit=limit, date=date, content=content)
            self.pikax.download(result, folder=folder)
            settings.MAX_PAGES_PER_ARTWORK = old_limit
        except PikaxException as e:
            import sys
            sys.stdout.write(texts.get('PIKAX_RANK_FAILED').format(error=e))

    def search(self, keyword, limit, sort, match, popularity, folder, pages_limit):
        try:
            old_limit = settings.MAX_PAGES_PER_ARTWORK
            if pages_limit:
                settings.MAX_PAGES_PER_ARTWORK = 1
            result = self.pikax.search(keyword=keyword, limit=limit, sort=sort, match=match, popularity=popularity)
            self.pikax.download(result, folder)
            settings.MAX_PAGES_PER_ARTWORK = old_limit
        except PikaxException as e:
            import sys
            sys.stdout.write(texts.get('PIKAX_SEARCH_FAILED').format(error=e))

    def download_by_illust_ids(self, illust_ids):
        try:
            artworks, fails = self.pikax.get_id_processor().process(ids=illust_ids,
                                                                    process_type=params.ProcessType.ILLUST)
            result = DefaultPikaxResult(artworks, download_type=params.DownloadType.ILLUST)
            self.pikax.download(result)
        except ArtworkError as e:
            sys.stdout.write(texts.get('PIKAX_ILLUST_ID_FAILED').format(error=e))

    def download_by_artist_id(self, artist_id, limit, content, folder, likes, pages_limit):
        try:
            old_limit = settings.MAX_PAGES_PER_ARTWORK
            if pages_limit:
                settings.MAX_PAGES_PER_ARTWORK = 1

            artist = self.pikax.visits(user_id=artist_id)

            content_to_method = {
                params.Content.ILLUST: artist.illusts,
                params.Content.MANGA: artist.mangas
            }
            if not likes:
                limit = None

            try:
                result = content_to_method[content](limit=limit)
            except KeyError:
                # bookmark is not included in the method
                result = artist.bookmarks(limit=limit)

            if likes:
                result = (result.likes > likes).renew_artworks(util.trim_to_limit(result.likes > likes, limit))

            self.pikax.download(result, folder=folder)

            settings.MAX_PAGES_PER_ARTWORK = old_limit

        except PikaxException as e:
            sys.stdout.write(str(e))