diff --git a/README.md b/README.md index 4ba007b..db05791 100644 --- a/README.md +++ b/README.md @@ -123,6 +123,7 @@ Requirements: [requests](https://pypi.python.org/pypi/requests) ```python from pixivpy3 import AppPixivAPI +from pixivpy3 import enums access_token = "..." refresh_token = "..." @@ -137,7 +138,7 @@ print(f">>> origin url: {illust.image_urls.large}") # get ranking: 1-30 # mode: [day, week, month, day_male, day_female, week_original, week_rookie, day_manga] -json_result = api.illust_ranking('day') +json_result = api.illust_ranking(mode=enums.RankingMode.DAY) for illust in json_result.illusts: print(f" p1 [{illust.title}] {illust.image_urls.medium}") @@ -167,6 +168,7 @@ while next_qs: ```python from pixivpy3 import AppPixivAPI + aapi = AppPixivAPI() json_result = aapi.illust_ranking() for illust in json_result.illusts[:3]: @@ -179,9 +181,10 @@ for illust in json_result.illusts[:3]: 2. Change deprecated SPAI call to Public-API call ```python -from pixivpy3 import AppPixivAPI +from pixivpy3 import AppPixivAPI, enums + api = AppPixivAPI() -rank_list = api.illust_ranking('day') +rank_list = api.illust_ranking(enums.RankingMode.DAY) print(rank_list) # more fields about response: https://github.com/upbit/pixivpy/wiki/sniffer @@ -208,8 +211,8 @@ Find Pixiv API in **Objective-C**? You might also like ```python from __future__ import annotations from typing import Any +from pixivpy3 import enums from pixivpy3.utils import ParsedJson - from pixivpy3.api import BasePixivAPI @@ -223,20 +226,20 @@ class AppPixivAPI(BasePixivAPI): # 用户作品列表 ## type: [illust, manga] - def user_illusts(self, user_id: int | str, type="illust") -> ParsedJson: ... + def user_illusts(self, user_id: int | str, type=enums.ContentType.ILLUSTRATION) -> ParsedJson: ... # 用户收藏作品列表 # tag: 从 user_bookmark_tags_illust 获取的收藏标签 - def user_bookmarks_illust(self, user_id: int | str, restrict="public") -> ParsedJson: ... + def user_bookmarks_illust(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ... # 用户收藏作品列表中的小说 - def user_bookmarks_novel(self, user_id: int | str, restrict="public") -> ParsedJson: ... + def user_bookmarks_novel(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ... def user_related(self, seed_user_id: int | str) -> ParsedJson: ... # 关注用户的新作 # restrict: [public, private] - def illust_follow(self, restrict="public") -> ParsedJson: ... + def illust_follow(self, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ... # 作品详情 (类似PAPI.works(),iOS中未使用) def illust_detail(self, illust_id: int | str) -> ParsedJson: ... @@ -249,7 +252,7 @@ class AppPixivAPI(BasePixivAPI): # 插画推荐 (Home - Main) # content_type: [illust, manga] - def illust_recommended(self, content_type="illust") -> ParsedJson: ... + def illust_recommended(self, content_type=enums.ContentType.ILLUSTRATION) -> ParsedJson: ... # 小说推荐 def novel_recommended(self) -> ParsedJson: ... @@ -259,7 +262,7 @@ class AppPixivAPI(BasePixivAPI): # date: '2016-08-01' # mode (Past): [day, week, month, day_male, day_female, week_original, week_rookie, # day_r18, day_male_r18, day_female_r18, week_r18, week_r18g] - def illust_ranking(self, mode="day", date=None) -> ParsedJson: ... + def illust_ranking(self, mode=enums.RankingMode.DAY, date=None) -> ParsedJson: ... # 趋势标签 (Search - tags) def trending_tags_illust(self) -> ParsedJson: ... @@ -273,13 +276,13 @@ class AppPixivAPI(BasePixivAPI): # duration: [within_last_day, within_last_week, within_last_month] # start_date, end_date: '2020-07-01' def search_illust( - self, - word: str, - search_target="partial_match_for_tags", - sort="date_desc", - duration=None, - start_date=None, - end_date=None, + self, + word: str, + search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS, + sort=enums.Sort.DATE_DESC, + duration=None, + start_date=None, + end_date=None, ) -> ParsedJson: ... # 搜索小说 (Search Novel) @@ -291,36 +294,36 @@ class AppPixivAPI(BasePixivAPI): # sort: [date_desc, date_asc] # start_date/end_date: 2020-06-01 def search_novel( - self, - word: str, - search_target="partial_match_for_tags", - sort="date_desc", - start_date=None, - end_date=None, + self, + word: str, + search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS, + sort=enums.Sort.DATE_DESC, + start_date=None, + end_date=None, ) -> ParsedJson: ... - def search_user(self, word: str, sort='date_desc', duration=None) -> ParsedJson: ... + def search_user(self, word: str, sort=enums.Sort.DATE_DESC, duration=None) -> ParsedJson: ... # 作品收藏详情 def illust_bookmark_detail(self, illust_id: int | str) -> ParsedJson: ... # 新增收藏 - def illust_bookmark_add(self, illust_id: int | str, restrict="public", tags=None) -> ParsedJson: ... + def illust_bookmark_add(self, illust_id: int | str, restrict=enums.Visibility.PUBLIC, tags=None) -> ParsedJson: ... # 删除收藏 def illust_bookmark_delete(self, illust_id: int | str) -> ParsedJson: ... # 关注用户 - def user_follow_add(self, user_id: int | str, restrict="public") -> ParsedJson: ... + def user_follow_add(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ... # 取消关注用户 def user_follow_delete(self, user_id: int | str) -> ParsedJson: ... # 用户收藏标签列表 - def user_bookmark_tags_illust(self, restrict="public") -> ParsedJson: ... + def user_bookmark_tags_illust(self, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ... # Following用户列表 - def user_following(self, user_id: int | str, restrict="public") -> ParsedJson: ... + def user_following(self, user_id: int | str, restrict=enums.Visibility.PUBLIC) -> ParsedJson: ... # Followers用户列表 def user_follower(self, user_id: int | str) -> ParsedJson: ... @@ -351,7 +354,7 @@ class AppPixivAPI(BasePixivAPI): # 大家的新作 # content_type: [illust, manga] - def illust_new(self, content_type="illust", max_illust_id=None) -> ParsedJson: ... + def illust_new(self, content_type=enums.ContentType.ILLUSTRATION, max_illust_id=None) -> ParsedJson: ... def novel_new(self, max_novel_id=None) -> ParsedJson: ... @@ -362,7 +365,8 @@ class AppPixivAPI(BasePixivAPI): [Usage](https://github.com/upbit/pixivpy/blob/aec177aa7a1979f7ec4c5bbbeed9085cc256bdbd/demo.py#L306): ```python -from pixivpy3 import AppPixivAPI +from pixivpy3 import AppPixivAPI, enums + api = AppPixivAPI() # 作品推荐 @@ -409,7 +413,7 @@ novel = json_result.novels[0] print(f">>> {novel.title}, text_length: {novel.text_length}, series: {novel.series}") # 2016-07-15 日的过去一周排行 -json_result = api.illust_ranking('week', date='2016-07-15') +json_result = api.illust_ranking(enums.RankingMode.WEEK, date='2016-07-15') print(json_result) illust = json_result.illusts[0] print(f">>> {illust.title}, origin url: {illust.image_urls.large}") @@ -421,7 +425,7 @@ illust = json_result.illusts[0] print(f">>> {illust.title}, origin url: {illust.image_urls.large}") # 标签 "水着" 搜索 -json_result = api.search_illust('水着', search_target='partial_match_for_tags') +json_result = api.search_illust('水着', search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS) print(json_result) illust = json_result.illusts[0] print(f">>> {illust.title}, origin url: {illust.image_urls.large}") @@ -437,9 +441,11 @@ json_result = api.novel_comments(16509454, include_total_comments=True) print(f"Total comments = {json_result.total_comments}") for comment in json_result.comments: if comment.parent_comment: - print(f"{comment.user.name} replied to {comment.parent_comment.user.name} at {comment.date} : {comment.comment}") + text = f"{comment.user.name} replied to {comment.parent_comment.user.name} at {comment.date} : {comment.comment}" + print(text) else: - print(f"{comment.user.name} at {comment.date} : {comment.comment}") + text = f"{comment.user.name} at {comment.date} : {comment.comment}" + print(text) ``` ## Develop Instructions diff --git a/demo.py b/demo.py index e63fb5d..827f150 100644 --- a/demo.py +++ b/demo.py @@ -5,7 +5,7 @@ import time from typing import Any -from pixivpy3 import AppPixivAPI, PixivError +from pixivpy3 import AppPixivAPI, PixivError, enums sys.dont_write_bytecode = True @@ -135,7 +135,9 @@ def appapi_search(aapi: AppPixivAPI) -> None: first_tag = trend_tag.tag print(f"{trend_tag.tag} - {trend_tag.illust.title}(id={trend_tag.illust.id})") - json_result = aapi.search_illust(first_tag, search_target="partial_match_for_tags") + json_result = aapi.search_illust( + first_tag, search_target=enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS + ) print(json_result) illust = json_result.illusts[0] print(f">>> {illust.title}, origin url: {illust.image_urls.large}") @@ -149,7 +151,7 @@ def appapi_search(aapi: AppPixivAPI) -> None: print(f">>> {illust.title}, origin url: {illust.image_urls.large}") # novel - json_result = aapi.search_novel("FGO", search_target="keyword") + json_result = aapi.search_novel("FGO", search_target=enums.SearchTarget.KEYWORD) print(json_result) novel = json_result.novels[0] print(f">>> {illust.title}, origin url: {illust.image_urls.large}") @@ -163,10 +165,12 @@ def appapi_search(aapi: AppPixivAPI) -> None: print(f">>> {novel.title}, origin url: {novel.image_urls['large']}") json_result = aapi.search_illust( - "AI生成", search_target="exact_match_for_tags", search_ai_type=0 + "AI生成", + search_target=enums.SearchTarget.EXACT_MATCH_FOR_TAGS, + search_ai_type=0, ) - # 关闭AI搜索选项后,将过滤掉所有illust_ai_type=2的插画,而illust_ai_type=1 or 0 的插画将被保留 - # 但是,加入了"AI生成"的tag却没有在作品提交时打开“AI生成”的开关的作品不会被筛选出结果列表 + # 关闭AI搜索选项后,将过滤掉所有illust_ai_type=2的插画,而illust_ai_type=1 or 0 的插画将被保留 + # 但是,加入了"AI生成"的tag却没有在作品提交时打开“AI生成”的开关的作品不会被筛选出结果列表 print(json_result.illusts[0]) diff --git a/download_illusts.py b/download_illusts.py index 2a0c2a5..eccc160 100644 --- a/download_illusts.py +++ b/download_illusts.py @@ -3,7 +3,7 @@ import os import sys -from pixivpy3 import AppPixivAPI, ByPassSniApi +from pixivpy3 import AppPixivAPI, ByPassSniApi, enums sys.dont_write_bytecode = True @@ -23,7 +23,7 @@ def main() -> None: api.auth(refresh_token=_REFRESH_TOKEN) # get rankings - json_result = api.illust_ranking("day", date="2019-01-01") + json_result = api.illust_ranking(enums.RankingMode.DAY, date="2019-01-01") directory = "illusts" if not os.path.exists(directory): diff --git a/example_bypass_sni.py b/example_bypass_sni.py index 8ad8ad6..e22b907 100644 --- a/example_bypass_sni.py +++ b/example_bypass_sni.py @@ -1,7 +1,7 @@ import sys from datetime import datetime, timedelta -from pixivpy3 import ByPassSniApi +from pixivpy3 import ByPassSniApi, enums sys.dont_write_bytecode = True @@ -20,7 +20,7 @@ def main() -> None: # api.login(_USERNAME, _PASSWORD) print(api.auth(refresh_token=_REFRESH_TOKEN)) date = datetime.now() - timedelta(days=5) - json_result = api.illust_ranking("day", date=date) + json_result = api.illust_ranking(enums.RankingMode.DAY, date=date) print( "Printing image titles and tags with English tag translations present when available" diff --git a/example_tag_translations.py b/example_tag_translations.py index 8c6c65f..87ca5ed 100644 --- a/example_tag_translations.py +++ b/example_tag_translations.py @@ -3,7 +3,7 @@ import sys from datetime import datetime, timedelta -from pixivpy3 import AppPixivAPI +from pixivpy3 import AppPixivAPI, enums sys.dont_write_bytecode = True @@ -20,7 +20,7 @@ def main() -> None: aapi.auth(refresh_token=_REFRESH_TOKEN) date = datetime.now() - timedelta(days=5) - json_result = aapi.illust_ranking("day", date=date) + json_result = aapi.illust_ranking(enums.RankingMode.DAY, date=date) print( "Printing image titles and tags with English tag translations present when available" diff --git a/pixivpy3/aapi.py b/pixivpy3/aapi.py index f6ffd24..feccdd8 100644 --- a/pixivpy3/aapi.py +++ b/pixivpy3/aapi.py @@ -8,50 +8,24 @@ import datetime as dt import re import urllib.parse as up -from typing import Any, Literal, Union - -try: - # Python>=3.10 - from typing import TypeAlias -except ImportError: - from typing_extensions import TypeAlias +from typing import Any, Literal, TypeVar, Union +from pydantic import BaseModel from requests.structures import CaseInsensitiveDict +from typing_extensions import TypeAlias # present in `typing` only from `3.10` -from . import models +from . import enums, models from .api import BasePixivAPI -from .models import ModelT from .utils import ParamDict, ParsedJson, PixivError, Response # from typeguard import typechecked -_FILTER: TypeAlias = Literal["for_ios", ""] -_TYPE: TypeAlias = Literal["illust", "manga", ""] -_RESTRICT: TypeAlias = Literal["public", "private", ""] -_CONTENT_TYPE: TypeAlias = Literal["illust", "manga", ""] -_MODE: TypeAlias = Literal[ - "day", - "week", - "month", - "day_male", - "day_female", - "week_original", - "week_rookie", - "day_manga", - "day_r18", - "day_male_r18", - "day_female_r18", - "week_r18", - "week_r18g", - "", -] -_SEARCH_TARGET: TypeAlias = Literal[ - "partial_match_for_tags", "exact_match_for_tags", "title_and_caption", "keyword", "" -] -_SORT: TypeAlias = Literal["date_desc", "date_asc", "popular_desc", ""] -_DURATION: TypeAlias = Literal[ - "within_last_day", "within_last_week", "within_last_month", "", None -] -_BOOL: TypeAlias = Literal["true", "false"] +__all__ = ("AppPixivAPI",) + +ModelT = TypeVar("ModelT", bound=BaseModel) + +BoolStr: TypeAlias = Literal["true", "false"] +Filter: TypeAlias = Literal["for_ios"] +FILTER = "for_ios" DateOrStr = Union[dt.date, str] @@ -119,7 +93,7 @@ def _load_model(cls, data: ParsedJson, model: type[ModelT], /) -> ModelT: raise PixivError(msg, body=data) from e @classmethod - def format_bool(cls, bool_value: bool | str | None) -> _BOOL: + def format_bool(cls, bool_value: bool | str | None) -> BoolStr: if isinstance(bool_value, bool): return "true" if bool_value else "false" if bool_value in {"true", "True"}: @@ -157,7 +131,7 @@ def parse_qs(cls, next_url: str | None) -> dict[str, Any] | None: def user_detail( self, user_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, req_auth: bool = True, ) -> models.UserInfoDetailed: url = f"{self.hosts}/v1/user/detail" @@ -173,8 +147,8 @@ def user_detail( def user_illusts( self, user_id: int | str, - type: _TYPE = "illust", - filter: _FILTER = "for_ios", + type: enums.ContentType = enums.ContentType.ILLUSTRATION, + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> models.UserIllustrations: @@ -195,8 +169,8 @@ def user_illusts( def user_bookmarks_illust( self, user_id: int | str, - restrict: _RESTRICT = "public", - filter: _FILTER = "for_ios", + restrict: enums.Visibility = enums.Visibility.PUBLIC, + filter: Filter = FILTER, max_bookmark_id: int | str | None = None, tag: str | None = None, req_auth: bool = True, @@ -218,8 +192,8 @@ def user_bookmarks_illust( def user_bookmarks_novel( self, user_id: int | str, - restrict: _RESTRICT = "public", - filter: _FILTER = "for_ios", + restrict: enums.Visibility = enums.Visibility.PUBLIC, + filter: Filter = FILTER, max_bookmark_id: int | str | None = None, tag: str | None = None, req_auth: bool = True, @@ -240,7 +214,7 @@ def user_bookmarks_novel( def user_related( self, seed_user_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -256,7 +230,7 @@ def user_related( def user_recommended( self, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -274,7 +248,7 @@ def user_recommended( # restrict: [public, private] def illust_follow( self, - restrict: _RESTRICT = "public", + restrict: enums.Visibility = enums.Visibility.PUBLIC, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -319,7 +293,7 @@ def illust_comments( def illust_related( self, illust_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, seed_illust_ids: int | str | list[str] | None = None, offset: int | str | None = None, viewed: str | list[str] | None = None, @@ -346,9 +320,9 @@ def illust_related( # content_type: [illust, manga] def illust_recommended( self, - content_type: _CONTENT_TYPE = "illust", + content_type: enums.ContentType = enums.ContentType.ILLUSTRATION, include_ranking_label: bool | str = True, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, max_bookmark_id_for_recommend: int | str | None = None, min_bookmark_id_for_recent_illust: int | str | None = None, offset: int | str | None = None, @@ -420,7 +394,7 @@ def novel_comments( def novel_recommended( self, include_ranking_label: bool | str = True, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, offset: int | str | None = None, include_ranking_novels: str | bool | None = None, already_recommended: str | list[str] | None = None, @@ -459,8 +433,8 @@ def novel_recommended( # day_r18, day_male_r18, day_female_r18, week_r18, week_r18g] def illust_ranking( self, - mode: _MODE = "day", - filter: _FILTER = "for_ios", + mode: enums.RankingMode = enums.RankingMode.DAY, + filter: Filter = FILTER, date: DateOrStr | None = None, offset: int | str | None = None, req_auth: bool = True, @@ -479,9 +453,9 @@ def illust_ranking( # 趋势标签 (Search - tags) def trending_tags_illust( - self, filter: _FILTER = "for_ios", req_auth: bool = True + self, filter: Filter = FILTER, req_auth: bool = True ) -> ParsedJson: - url = f"{self.hosts}/v1/trending-tags/illust" + url = "%s/v1/trending-tags/illust" % self.hosts params = { "filter": filter, } @@ -500,12 +474,12 @@ def trending_tags_illust( def search_illust( self, word: str, - search_target: _SEARCH_TARGET = "partial_match_for_tags", - sort: _SORT = "date_desc", - duration: _DURATION = None, + search_target: enums.SearchTarget = enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS, + sort: enums.Sort = enums.Sort.DATE_DESC, + duration: enums.Duration | None = None, start_date: DateOrStr | None = None, end_date: DateOrStr | None = None, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, search_ai_type: Literal[0, 1] | None = None, offset: int | str | None = None, req_auth: bool = True, @@ -542,10 +516,10 @@ def search_illust( def search_novel( self, word: str, - search_target: _SEARCH_TARGET = "partial_match_for_tags", - sort: _SORT = "date_desc", - merge_plain_keyword_results: _BOOL = "true", - include_translated_tag_results: _BOOL = "true", + search_target: enums.SearchTarget = enums.SearchTarget.PARTIAL_MATCH_FOR_TAGS, + sort: enums.Sort = enums.Sort.DATE_DESC, + merge_plain_keyword_results: BoolStr = "true", + include_translated_tag_results: BoolStr = "true", start_date: DateOrStr | None = None, end_date: DateOrStr | None = None, filter: str | None = None, @@ -576,9 +550,9 @@ def search_novel( def search_user( self, word: str, - sort: _SORT = "date_desc", - duration: _DURATION = None, - filter: _FILTER = "for_ios", + sort: enums.Sort = enums.Sort.DATE_DESC, + duration: enums.Duration | None = None, + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -610,7 +584,7 @@ def illust_bookmark_detail( def illust_bookmark_add( self, illust_id: int | str, - restrict: _RESTRICT = "public", + restrict: enums.Visibility = enums.Visibility.PUBLIC, tags: str | list[str] | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -642,7 +616,7 @@ def illust_bookmark_delete( def user_follow_add( self, user_id: int | str, - restrict: _RESTRICT = "public", + restrict: enums.Visibility = enums.Visibility.PUBLIC, req_auth: bool = True, ) -> ParsedJson: url = f"{self.hosts}/v1/user/follow/add" @@ -661,7 +635,7 @@ def user_follow_delete( # 设置用户选项中是否展现AI生成作品 def user_edit_ai_show_settings( - self, setting: _BOOL, req_auth: bool = True + self, setting: BoolStr, req_auth: bool = True ) -> ParsedJson: url = f"{self.hosts}/v1/user/ai-show-settings/edit" data = {"show_ai": setting} @@ -672,7 +646,7 @@ def user_edit_ai_show_settings( def user_bookmark_tags_illust( self, user_id: int | str, - restrict: _RESTRICT = "public", + restrict: enums.Visibility = enums.Visibility.PUBLIC, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -690,7 +664,7 @@ def user_bookmark_tags_illust( def user_following( self, user_id: int | str, - restrict: _RESTRICT = "public", + restrict: enums.Visibility = enums.Visibility.PUBLIC, offset: int | str | None = None, req_auth: bool = True, ) -> models.UserFollowing: @@ -709,7 +683,7 @@ def user_following( def user_follower( self, user_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -745,7 +719,7 @@ def user_mypixiv( def user_list( self, user_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -776,7 +750,7 @@ def ugoira_metadata( def user_novels( self, user_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, offset: int | str | None = None, req_auth: bool = True, ) -> models.UserNovels: @@ -794,7 +768,7 @@ def user_novels( def novel_series( self, series_id: int | str, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, last_order: str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -825,7 +799,7 @@ def novel_detail( def novel_new( self, - filter: _FILTER = "for_ios", + filter: Filter = FILTER, max_novel_id: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -842,7 +816,7 @@ def novel_new( # restrict: [public, private, all] def novel_follow( self, - restrict: _RESTRICT = "public", + restrict: enums.Visibility = enums.Visibility.PUBLIC, offset: int | None = None, req_auth: bool = True, ) -> ParsedJson: @@ -894,8 +868,8 @@ def novel_text( # content_type: [illust, manga] def illust_new( self, - content_type: _CONTENT_TYPE = "illust", - filter: _FILTER = "for_ios", + content_type: enums.ContentType = enums.ContentType.ILLUSTRATION, + filter: Filter = FILTER, max_illust_id: int | str | None = None, req_auth: bool = True, ) -> ParsedJson: diff --git a/pixivpy3/enums.py b/pixivpy3/enums.py new file mode 100644 index 0000000..eccffeb --- /dev/null +++ b/pixivpy3/enums.py @@ -0,0 +1,55 @@ +from enum import Enum + +__all__ = ( + "ContentType", + "Visibility", + "RankingMode", + "SearchTarget", + "Sort", + "Duration", +) + + +class ContentType(str, Enum): + ILLUSTRATION = "illust" + MANGA = "manga" + + +class Visibility(str, Enum): + PUBLIC = "public" + PRIVATE = "private" + + +class RankingMode(str, Enum): + DAY = "day" + WEEK = "week" + MONTH = "month" + DAY_MALE = "day_male" + DAY_FEMALE = "day_female" + WEEK_ORIGINAL = "week_original" + WEEK_ROOKIE = "week_rookie" + DAY_MANGA = "day_manga" + DAY_R18 = "day_r18" + DAY_MALE_R18 = "day_male_r18" + DAY_FEMALE_R18 = "day_female_r18" + WEEK_R18 = "week_r18" + WEEK_R18G = "week_r18g" + + +class SearchTarget(str, Enum): + PARTIAL_MATCH_FOR_TAGS = "partial_match_for_tags" + EXACT_MATCH_FOR_TAGS = "exact_match_for_tags" + TITLE_AND_CAPTION = "title_and_caption" + KEYWORD = "keyword" + + +class Sort(str, Enum): + DATE_DESC = "date_desc" + DATE_ASC = "date_asc" + POPULAR_DESC = "popular_desc" + + +class Duration(str, Enum): + WITHIN_LAST_DAY = "within_last_day" + WITHIN_LAST_WEEK = "within_last_week" + WITHIN_LAST_MONTH = "within_last_month" diff --git a/pixivpy3/models.py b/pixivpy3/models.py index fa9a950..c7c15c0 100644 --- a/pixivpy3/models.py +++ b/pixivpy3/models.py @@ -1,4 +1,4 @@ -from typing import Any, List, Optional, TypeVar, Union +from typing import Any, List, Optional, Union import pydantic from typing_extensions import Self @@ -70,8 +70,6 @@ def _to_camel(string: str) -> str: msg = f"Unsupported Pydantic version: {pydantic.__version__}" raise ValueError(msg) -ModelT = TypeVar("ModelT", bound=BaseModel) - class BasePixivpyModel(BaseModel): if _PYDANTIC_MAJOR_VERSION == 2: