diff --git a/poetry.lock b/poetry.lock index 927f11d..807e72e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -344,13 +344,13 @@ yaml = ["pyyaml (==6.0.1)"] [[package]] name = "httpcore" -version = "1.0.4" +version = "1.0.5" description = "A minimal low-level HTTP client." optional = false python-versions = ">=3.8" files = [ - {file = "httpcore-1.0.4-py3-none-any.whl", hash = "sha256:ac418c1db41bade2ad53ae2f3834a3a0f5ae76b56cf5aa497d2d033384fc7d73"}, - {file = "httpcore-1.0.4.tar.gz", hash = "sha256:cb2839ccfcba0d2d3c1131d3c3e26dfc327326fbe7a5dc0dbfe9f6c9151bb022"}, + {file = "httpcore-1.0.5-py3-none-any.whl", hash = "sha256:421f18bac248b25d310f3cacd198d55b8e6125c107797b609ff9b7a6ba7991b5"}, + {file = "httpcore-1.0.5.tar.gz", hash = "sha256:34a38e2f9291467ee3b44e89dd52615370e152954ba21721378a87b2960f7a61"}, ] [package.dependencies] @@ -361,7 +361,7 @@ h11 = ">=0.13,<0.15" asyncio = ["anyio (>=4.0,<5.0)"] http2 = ["h2 (>=3,<5)"] socks = ["socksio (==1.*)"] -trio = ["trio (>=0.22.0,<0.25.0)"] +trio = ["trio (>=0.22.0,<0.26.0)"] [[package]] name = "httpx" @@ -1578,4 +1578,4 @@ testing = ["big-O", "jaraco.functools", "jaraco.itertools", "more-itertools", "p [metadata] lock-version = "2.0" python-versions = ">=3.9" -content-hash = "edc8ca1a4531a466936e041cd80e5f5ab8e7b1413c3bcedafcadf83d0b52e7c6" +content-hash = "a1973cc00715d5837d905a2b221cd0d71e2f3d237c896e7c96d1a22680d5608d" diff --git a/pyproject.toml b/pyproject.toml index 5c30f0c..dca704f 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,6 +29,7 @@ lxml = ">=5.1.0" hishel = ">=0.0.25" torf = ">=4.2.6" typing-extensions = ">=4.10.0" +platformdirs = ">=4.2.0" strenum = { version = ">=0.4.15", python = "<3.11" } importlib-metadata = { version = ">=7.1.0", python = "<3.10" } eval-type-backport = { version = ">=0.1.3", python = "<3.10" } diff --git a/src/pynyaa/_clients/_async.py b/src/pynyaa/_clients/_async.py index 431a7db..147bf02 100644 --- a/src/pynyaa/_clients/_async.py +++ b/src/pynyaa/_clients/_async.py @@ -3,8 +3,8 @@ from io import BytesIO from typing import Any -import hishel from bs4 import BeautifulSoup +from hishel import AsyncCacheClient, AsyncFileStorage from pydantic import validate_call from pydantic_core import Url from torf import Torrent @@ -12,6 +12,7 @@ from .._exceptions import HTMLParsingError from .._models import NyaaTorrentPage from .._types import HTTPXAsyncClientKwargs +from .._utils import _get_user_cache_path class AsyncNyaa: @@ -191,7 +192,9 @@ async def get(self, page: int | str) -> NyaaTorrentPage: host = Url(page).host self.base_url = f"https://{host}" if host is not None else "https://nyaa.si" - async with hishel.AsyncCacheClient(**self.kwargs) as client: + async with AsyncCacheClient( + storage=AsyncFileStorage(base_path=_get_user_cache_path()), **self.kwargs + ) as client: extensions = {"force_cache": self.cache, "cache_disabled": not self.cache} nyaa = await client.get(url, extensions=extensions) nyaa.raise_for_status() diff --git a/src/pynyaa/_clients/_sync.py b/src/pynyaa/_clients/_sync.py index f4a08d1..643cb5b 100644 --- a/src/pynyaa/_clients/_sync.py +++ b/src/pynyaa/_clients/_sync.py @@ -3,8 +3,8 @@ from io import BytesIO from typing import Any -import hishel from bs4 import BeautifulSoup +from hishel import CacheClient, FileStorage from pydantic import validate_call from pydantic_core import Url from torf import Torrent @@ -12,6 +12,7 @@ from .._exceptions import HTMLParsingError from .._models import NyaaTorrentPage from .._types import HTTPXClientKwargs +from .._utils import _get_user_cache_path class Nyaa: @@ -191,7 +192,7 @@ def get(self, page: int | str) -> NyaaTorrentPage: host = Url(page).host self.base_url = f"https://{host}" if host is not None else "https://nyaa.si" - with hishel.CacheClient(**self.kwargs) as client: + with CacheClient(storage=FileStorage(base_path=_get_user_cache_path()), **self.kwargs) as client: extensions = {"force_cache": self.cache, "cache_disabled": not self.cache} nyaa = client.get(url, extensions=extensions).raise_for_status() diff --git a/src/pynyaa/_utils.py b/src/pynyaa/_utils.py new file mode 100644 index 0000000..f094fa2 --- /dev/null +++ b/src/pynyaa/_utils.py @@ -0,0 +1,12 @@ +from __future__ import annotations + +from typing import TYPE_CHECKING + +from platformdirs import user_cache_path + +if TYPE_CHECKING: + from pathlib import Path + + +def _get_user_cache_path() -> Path: + return user_cache_path(appname="pynaa", ensure_exists=True)