diff --git a/CHANGELOG.md b/CHANGELOG.md index a50efc3..af8543a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ### 💡 Feature -- Add `--offset`, `--length` options in `sync-creator` command +- Added support for downloading works within a specified range of quantity. + - Added `--offset`, `--length` options in `sync-creator` command - `--offset`: Posts result offset (or start offset) - `--length`: The number of posts to fetch, defaults to fetching all posts @@ -21,7 +22,8 @@ ### 💡 新特性 -- 在 `sync-creator` 命令中增加了 `--offset`, `--length` 选项 +- 增加下载指定数量范围作品的支持 + - 在 `sync-creator` 命令中增加了 `--offset`, `--length` 选项 - `--offset`:作品结果偏移量(或起始偏移量) - `--length`:要获取的作品数量,默认获取所有作品 diff --git a/ktoolbox/action/job.py b/ktoolbox/action/job.py index 93517f4..f6b1e8e 100644 --- a/ktoolbox/action/job.py +++ b/ktoolbox/action/job.py @@ -98,7 +98,7 @@ async def create_job_from_creator( *, all_pages: bool = False, offset: int = 0, - length: int = 50, + length: Optional[int] = 50, save_creator_indices: bool = True, mix_posts: bool = None, start_time: Optional[datetime], @@ -125,8 +125,11 @@ async def create_job_from_creator( logger.info(f"Start fetching posts from creator {creator_id}") post_list: List[Post] = [] start_offset = offset - offset % 50 - page_num = length // 50 + 1 - page_counter = count() if all_pages else iter(range(page_num)) + if all_pages: + page_counter = count() + else: + page_num = length // 50 + 1 + page_counter = iter(range(page_num)) try: async for part in fetch_creator_posts(service=service, creator_id=creator_id, o=start_offset): @@ -139,6 +142,8 @@ async def create_job_from_creator( if not all_pages: post_list = post_list[offset % 50:][:length] + else: + post_list = post_list[offset % 50:] # Filter posts by publish time if start_time or end_time: diff --git a/ktoolbox/cli.py b/ktoolbox/cli.py index 51c79ce..d676e7b 100644 --- a/ktoolbox/cli.py +++ b/ktoolbox/cli.py @@ -247,7 +247,7 @@ async def sync_creator( Set to latest time (infinity) if ``None`` was given. \ Time format: ``%Y-%m-%d`` :param offset: Result offset (or start offset) - :param length: The number of posts to fetch, defaults to fetching all posts. + :param length: The number of posts to fetch, defaults to fetching all posts after ``offset``. """ # Get service, creator_id if url: