diff --git a/ncmlyrics/__init__.py b/ncmlyrics/__init__.py new file mode 100644 index 0000000..f90ed5f --- /dev/null +++ b/ncmlyrics/__init__.py @@ -0,0 +1,4 @@ +from .__version__ import __title__, __description__, __version__ +from .__main__ import main + +__all__ = ["__title__", "__description__", "__version__", "main"] diff --git a/src/ncmlyrics/__main__.py b/ncmlyrics/__main__.py similarity index 100% rename from src/ncmlyrics/__main__.py rename to ncmlyrics/__main__.py diff --git a/ncmlyrics/__version__.py b/ncmlyrics/__version__.py new file mode 100644 index 0000000..9a6dbe8 --- /dev/null +++ b/ncmlyrics/__version__.py @@ -0,0 +1,3 @@ +__title__ = "ncmlyrics" +__description__ = "No description at now." +__version__ = "0.1.0a2" diff --git a/src/ncmlyrics/api.py b/ncmlyrics/api.py similarity index 83% rename from src/ncmlyrics/api.py rename to ncmlyrics/api.py index c8aa723..9f6733e 100644 --- a/src/ncmlyrics/api.py +++ b/ncmlyrics/api.py @@ -16,14 +16,38 @@ __all__ = ["NCMApi"] REQUEST_HEADERS = { "Accept": "application/json", - "Accept-Encoding": "zstd, br, gzip, deflate", + "Accept-Encoding": "gzip, deflate", "Connection": "keep-alive", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36", } +try: + import brotlicffi as brotli # type: ignore +except ImportError: + try: + import brotli # type: ignore # noqa: F401 + except ImportError: + pass + else: + REQUEST_HEADERS["Accept-Encoding"] = "br, " + REQUEST_HEADERS["Accept-Encoding"] +else: + REQUEST_HEADERS["Accept-Encoding"] = "br, " + REQUEST_HEADERS["Accept-Encoding"] + +try: + import zstandard # type: ignore # noqa: F401 +except ImportError: + pass +else: + REQUEST_HEADERS["Accept-Encoding"] = "zstd, " + REQUEST_HEADERS["Accept-Encoding"] + +try: + import h2 # type: ignore +except ImportError: + h2 = None + class NCMApi: - def __init__(self, http2: bool = True) -> None: + def __init__(self) -> None: self._cookiePath = PLATFORM.user_config_path / "cookies.txt" self._cookieJar = MozillaCookieJar() @@ -36,7 +60,7 @@ class NCMApi: base_url=NCM_API_BASE_URL, cookies=self._cookieJar, headers=REQUEST_HEADERS, - http2=http2, + http2=h2 is not None, ) def _fetch(self, request: HttpXRequest, retry: int | None = 4) -> HttpXResponse: diff --git a/src/ncmlyrics/constant.py b/ncmlyrics/constant.py similarity index 68% rename from src/ncmlyrics/constant.py rename to ncmlyrics/constant.py index 58a84d4..7310e4e 100644 --- a/src/ncmlyrics/constant.py +++ b/ncmlyrics/constant.py @@ -1,8 +1,7 @@ from httpx import URL from platformdirs import PlatformDirs -APP_NAME = "ncmlyrics" -APP_VERSION = "0.1.0a2" +from .__version__ import __title__ NCM_API_BASE_URL = URL("https://interface.music.163.com/api") @@ -11,4 +10,4 @@ CONFIG_LRC_AUTO_MERGE_OFFSET = 50 CONFIG_API_DETAIL_TRACK_PER_REQUEST = 150 -PLATFORM = PlatformDirs(appname=APP_NAME, ensure_exists=True) +PLATFORM = PlatformDirs(appname=__title__, ensure_exists=True) diff --git a/src/ncmlyrics/enum.py b/ncmlyrics/enum.py similarity index 100% rename from src/ncmlyrics/enum.py rename to ncmlyrics/enum.py diff --git a/src/ncmlyrics/error.py b/ncmlyrics/error.py similarity index 100% rename from src/ncmlyrics/error.py rename to ncmlyrics/error.py diff --git a/src/ncmlyrics/lrc.py b/ncmlyrics/lrc.py similarity index 100% rename from src/ncmlyrics/lrc.py rename to ncmlyrics/lrc.py diff --git a/src/ncmlyrics/object.py b/ncmlyrics/object.py similarity index 100% rename from src/ncmlyrics/object.py rename to ncmlyrics/object.py diff --git a/src/ncmlyrics/util.py b/ncmlyrics/util.py similarity index 100% rename from src/ncmlyrics/util.py rename to ncmlyrics/util.py diff --git a/pyproject.toml b/pyproject.toml index 68c2aa7..604de49 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,40 +1,45 @@ +[build-system] +requires = ["hatchling"] +build-backend = "hatchling.build" + [project] name = "ncmlyrics" -authors = [{ name = "Puqns67", email = "me@puqns67.icu" }] -dependencies = [ - "httpx>=0.27.2", - "h2>=4.1.0", - "rich>=13.9.2", - "brotli>=1.1.0", - "zstandard>=0.23.0", - "click>=8.1.7", - "platformdirs>=4.3.6", -] +description = "No description at now." requires-python = ">=3.12" -readme = "README.md" license = { text = "GPL-3.0-or-later" } -dynamic = ["version"] +authors = [{ name = "Puqns67", email = "me@puqns67.icu" }] classifiers = [ - "Programming Language :: Python :: 3", - "Programming Language :: Python :: 3.12", - "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", - "Operating System :: OS Independent", "Development Status :: 1 - Planning", "Environment :: Console", + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3 :: Only", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: Implementation :: CPython", + "License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)", + "Operating System :: OS Independent", "Natural Language :: Chinese (Simplified)", ] +dependencies = ["httpx", "rich>=13", "click>=8", "platformdirs>=4"] +dynamic = ["readme", "version"] + +[project.optional-dependencies] +brotli = [ + "brotli; platform_python_implementation == 'CPython'", + "brotlicffi; platform_python_implementation != 'CPython'", +] +http2 = ["h2>=3,<5"] +zstd = ["zstandard>=0.18.0"] + +[project.scripts] +ncmlyrics = "ncmlyrics:main" [project.urls] Homepage = "https://github.com/Puqns67/ncmlyrics" Issues = "https://github.com/Puqns67/ncmlyrics/issues" -[build-system] -requires = ["hatchling"] -build-backend = "hatchling.build" - [tool.hatch.version] -path = "src/ncmlyrics/constant.py" -pattern = "^APP_VERSION = \"(?P[^\"]+)\"$" +path = "ncmlyrics/__version__.py" [tool.ruff] target-version = "py312" diff --git a/src/ncmlyrics/__init__.py b/src/ncmlyrics/__init__.py deleted file mode 100644 index 97bb3a0..0000000 --- a/src/ncmlyrics/__init__.py +++ /dev/null @@ -1,3 +0,0 @@ -from .constant import APP_VERSION as __version__ - -__all__ = ["__version__"] diff --git a/uv.lock b/uv.lock index 32412fe..a7646d2 100644 --- a/uv.lock +++ b/uv.lock @@ -34,6 +34,23 @@ wheels = [ { url = "https://files.pythonhosted.org/packages/3d/d5/942051b45a9e883b5b6e98c041698b1eb2012d25e5948c58d6bf85b1bb43/Brotli-1.1.0-cp312-cp312-win_amd64.whl", hash = "sha256:906bc3a79de8c4ae5b86d3d75a8b77e44404b0f4261714306e3ad248d8ab0951", size = 357255 }, ] +[[package]] +name = "brotlicffi" +version = "1.1.0.0" +source = { registry = "https://pypi.org/simple" } +dependencies = [ + { name = "cffi" }, +] +sdist = { url = "https://files.pythonhosted.org/packages/95/9d/70caa61192f570fcf0352766331b735afa931b4c6bc9a348a0925cc13288/brotlicffi-1.1.0.0.tar.gz", hash = "sha256:b77827a689905143f87915310b93b273ab17888fd43ef350d4832c4a71083c13", size = 465192 } +wheels = [ + { url = "https://files.pythonhosted.org/packages/a2/11/7b96009d3dcc2c931e828ce1e157f03824a69fb728d06bfd7b2fc6f93718/brotlicffi-1.1.0.0-cp37-abi3-macosx_10_9_x86_64.whl", hash = "sha256:9b7ae6bd1a3f0df532b6d67ff674099a96d22bc0948955cb338488c31bfb8851", size = 453786 }, + { url = "https://files.pythonhosted.org/packages/d6/e6/a8f46f4a4ee7856fbd6ac0c6fb0dc65ed181ba46cd77875b8d9bbe494d9e/brotlicffi-1.1.0.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:19ffc919fa4fc6ace69286e0a23b3789b4219058313cf9b45625016bf7ff996b", size = 2911165 }, + { url = "https://files.pythonhosted.org/packages/be/20/201559dff14e83ba345a5ec03335607e47467b6633c210607e693aefac40/brotlicffi-1.1.0.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:9feb210d932ffe7798ee62e6145d3a757eb6233aa9a4e7db78dd3690d7755814", size = 2927895 }, + { url = "https://files.pythonhosted.org/packages/cd/15/695b1409264143be3c933f708a3f81d53c4a1e1ebbc06f46331decbf6563/brotlicffi-1.1.0.0-cp37-abi3-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:84763dbdef5dd5c24b75597a77e1b30c66604725707565188ba54bab4f114820", size = 2851834 }, + { url = "https://files.pythonhosted.org/packages/b4/40/b961a702463b6005baf952794c2e9e0099bde657d0d7e007f923883b907f/brotlicffi-1.1.0.0-cp37-abi3-win32.whl", hash = "sha256:1b12b50e07c3911e1efa3a8971543e7648100713d4e0971b13631cce22c587eb", size = 341731 }, + { url = "https://files.pythonhosted.org/packages/1c/fa/5408a03c041114ceab628ce21766a4ea882aa6f6f0a800e04ee3a30ec6b9/brotlicffi-1.1.0.0-cp37-abi3-win_amd64.whl", hash = "sha256:994a4f0681bb6c6c3b0925530a1926b7a189d878e6e5e38fae8efa47c5d9c613", size = 366783 }, +] + [[package]] name = "certifi" version = "2024.8.30" @@ -198,27 +215,37 @@ wheels = [ [[package]] name = "ncmlyrics" -version = "0.1.0a2" +version = "0.1.0a3" source = { editable = "." } dependencies = [ - { name = "brotli" }, { name = "click" }, - { name = "h2" }, { name = "httpx" }, { name = "platformdirs" }, { name = "rich" }, +] + +[package.optional-dependencies] +brotli = [ + { name = "brotli", marker = "platform_python_implementation == 'CPython'" }, + { name = "brotlicffi", marker = "platform_python_implementation != 'CPython'" }, +] +http2 = [ + { name = "h2" }, +] +zstd = [ { name = "zstandard" }, ] [package.metadata] requires-dist = [ - { name = "brotli", specifier = ">=1.1.0" }, - { name = "click", specifier = ">=8.1.7" }, - { name = "h2", specifier = ">=4.1.0" }, - { name = "httpx", specifier = ">=0.27.2" }, - { name = "platformdirs", specifier = ">=4.3.6" }, - { name = "rich", specifier = ">=13.9.2" }, - { name = "zstandard", specifier = ">=0.23.0" }, + { name = "brotli", marker = "platform_python_implementation == 'CPython' and extra == 'brotli'" }, + { name = "brotlicffi", marker = "platform_python_implementation != 'CPython' and extra == 'brotli'" }, + { name = "click", specifier = ">=8" }, + { name = "h2", marker = "extra == 'http2'", specifier = ">=3,<5" }, + { name = "httpx" }, + { name = "platformdirs", specifier = ">=4" }, + { name = "rich", specifier = ">=13" }, + { name = "zstandard", marker = "extra == 'zstd'", specifier = ">=0.18.0" }, ] [[package]]