Skip to content

Commit

Permalink
Merge pull request #34 from Ljzd-PRO/devel
Browse files Browse the repository at this point in the history
Bump to v0.3.4
  • Loading branch information
Ljzd-PRO authored Dec 14, 2023
2 parents 4960de3 + b6c0fd6 commit a485dbf
Show file tree
Hide file tree
Showing 14 changed files with 197 additions and 163 deletions.
4 changes: 4 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[run]
branch = True
source = ktoolbox
omit = tests/*
13 changes: 3 additions & 10 deletions .github/workflows/codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,19 +48,12 @@ jobs:

- name: Run Pytest
run: |
cd tests/
poetry run pytest -v --capture=sys --cov --cov-report=xml --html=${{ env.PYTEST_REPORT_FILENAME }} --self-contained-html
poetry run pytest -v --capture=sys --cov --cov-report=xml tests/
- name: Upload coverage report
uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
files: ./tests/coverage.xml
flags: ${{ github.ref_name }}

- name: Upload pytest HTML result
uses: actions/upload-artifact@v3
with:
name: ${{ env.PYTEST_REPORT_FILENAME }}
path: ./tests/${{ env.PYTEST_REPORT_FILENAME }}
files: coverage.xml
flags: ${{ matrix.os }}-${{ matrix.python-version }}
3 changes: 3 additions & 0 deletions docs/en/configuration/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ KTOOLBOX_JOB__POST_STRUCTURE__ATTACHMENTS=./
# Disable SSL certificate verification for Kemono API server and download server
# It's useful when certificate on Kemono server expired. (SSL: CERTIFICATE_VERIFY_FAILED)
KTOOLBOX_SSL_VERIFY=False
# Rename attachments in numerical order, e.g. `1.png`, `2.png`, ...
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
```
3 changes: 3 additions & 0 deletions docs/zh/configuration/guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,7 @@ KTOOLBOX_JOB__POST_STRUCTURE__ATTACHMENTS=./
# 为Kemono API服务器和下载服务器禁用SSL证书检查
# 在Kemono服务器的证书过期时很有用 (SSL: CERTIFICATE_VERIFY_FAILED)
KTOOLBOX_SSL_VERIFY=False
# 按照数字顺序重命名附件, 例如 `1.png`, `2.png`, ...
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
```
5 changes: 4 additions & 1 deletion example.env
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ KTOOLBOX_JOB__POST_STRUCTURE__ATTACHMENTS=./

# Disable SSL certificate verification for Kemono API server and download server
# It's useful when certificate on Kemono server expired. (SSL: CERTIFICATE_VERIFY_FAILED)
KTOOLBOX_SSL_VERIFY=False
KTOOLBOX_SSL_VERIFY=False

# Rename attachments in numerical order, e.g. `1.png`, `2.png`, ...
KTOOLBOX_JOB__SEQUENTIAL_FILENAME=True
2 changes: 1 addition & 1 deletion ktoolbox/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
__title__ = "KToolBox"
# noinspection SpellCheckingInspection
__description__ = "A useful CLI tool for downloading posts in Kemono.party / .su"
__version__ = "0.3.2"
__version__ = "0.3.4"
7 changes: 4 additions & 3 deletions ktoolbox/action/job.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

from ktoolbox.action import ActionRet, fetch_all_creator_posts, FetchInterruptError
from ktoolbox.action.utils import generate_post_path_name, filter_posts_by_time, filter_posts_by_indices
from ktoolbox.api.model import Post
from ktoolbox.api.model import Post, Attachment
from ktoolbox.api.posts import get_creator_post
from ktoolbox.configuration import config, PostStructureConfiguration
from ktoolbox.enum import PostFileTypeEnum, DataStorageNameEnum
Expand Down Expand Up @@ -49,13 +49,14 @@ async def create_job_from_post(

# Create jobs
jobs: List[Job] = []
for attachment in post.attachments or []: # attachments
for i, attachment in enumerate(post.attachments or []): # type: int, Attachment
if not attachment.path:
continue
alt_filename = f"{i + 1}{Path(attachment.name).suffix}" if config.job.sequential_filename else attachment.name
jobs.append(
Job(
path=attachments_path,
alt_filename=attachment.name,
alt_filename=alt_filename,
server_path=attachment.path,
type=PostFileTypeEnum.Attachment
)
Expand Down
10 changes: 7 additions & 3 deletions ktoolbox/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,9 @@ async def sync_creator(
update_from: Path = None,
save_creator_indices: bool = True,
mix_posts: bool = None,
time_range: Tuple[str, str] = None
time_range: Tuple[str, str] = None,
start_time: str = None,
end_time: str = None
):
...

Expand All @@ -206,7 +208,9 @@ async def sync_creator(
update_from: Path = None,
save_creator_indices: bool = True,
mix_posts: bool = None,
time_range: Tuple[str, str] = None
time_range: Tuple[str, str] = None,
start_time: str = None,
end_time: str = None
):
...

Expand All @@ -221,7 +225,7 @@ async def sync_creator(
save_creator_indices: bool = True,
mix_posts: bool = None,
start_time: str = None,
end_time: str = None,
end_time: str = None
):
"""
Sync all posts from a creator
Expand Down
6 changes: 4 additions & 2 deletions ktoolbox/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,13 +99,15 @@ class JobConfiguration(BaseModel):
:ivar mix_posts: Save all files from different posts at same path in creator directory. \
It would not create any post directory, and ``CreatorIndices`` would not been recorded, \
without ``CreatorIndices`` you **cannot update** the creator directory.
:ivar job_list_filepath: Filepath for job list data saving, ``None`` for disable job list saving
:ivar sequential_filename: Rename attachments in numerical order, e.g. ``1.png``, ``2.png``, ...
"""
count: int = 4
post_id_as_path: bool = False
post_structure: PostStructureConfiguration = PostStructureConfiguration()
mix_posts: bool = False
job_list_filepath: Optional[Path] = None
sequential_filename: bool = False
# job_list_filepath: Optional[Path] = None
# """Filepath for job list data saving, ``None`` for disable job list saving"""


class LoggerConfiguration(BaseModel):
Expand Down
8 changes: 4 additions & 4 deletions ktoolbox/downloader/downloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ def __init__(
Initialize a file downloader
- About filename:
* If ``Content-Disposition`` is set in headers, use filename from it.
* Else if ``alt_filename`` parameter is set, use it.
* If ``alt_filename`` parameter is set, use it.
* Else if ``Content-Disposition`` is set in headers, use filename from it.
* Else use filename from URL 'path' part.
:param url: Download URL
Expand Down Expand Up @@ -165,8 +165,8 @@ async def run(
)

# Get filename
if not (filename := filename_from_headers(res.headers)):
if not (filename := self._alt_filename):
if not (filename := self._alt_filename):
if not (filename := filename_from_headers(res.headers)):
filename = urllib.parse.unquote(Path(self._url).name)
self._filename = filename

Expand Down
Loading

0 comments on commit a485dbf

Please sign in to comment.