From ebc90c08c21960615989d2315c777f8448be4782 Mon Sep 17 00:00:00 2001 From: jingfelix Date: Tue, 13 Feb 2024 23:10:31 +0800 Subject: [PATCH] fix: use another way to fix file too long Signed-off-by: jingfelix --- pdm.lock | 44 ++++++++++++++++++++++++++++++++++++-------- pyproject.toml | 6 ++---- requirements.txt | 7 ++++--- setup.py | 35 ----------------------------------- src/bilifm/audio.py | 24 +++++++++++------------- 5 files changed, 53 insertions(+), 63 deletions(-) delete mode 100644 setup.py diff --git a/pdm.lock b/pdm.lock index 58e33b9..fdd3254 100644 --- a/pdm.lock +++ b/pdm.lock @@ -5,17 +5,17 @@ groups = ["default"] strategy = ["cross_platform", "inherit_metadata"] lock_version = "4.4.1" -content_hash = "sha256:a4427c20d04f535aacee58234fec7cc31c66fa6c93003f280f8c6968dabf884d" +content_hash = "sha256:f47748bad88d2caaad828ced37137aab4f43ebc816b5b32101b2e7ed8352f0e0" [[package]] name = "certifi" -version = "2023.11.17" +version = "2024.2.2" requires_python = ">=3.6" summary = "Python package for providing Mozilla's CA Bundle." groups = ["default"] files = [ - {file = "certifi-2023.11.17-py3-none-any.whl", hash = "sha256:e036ab49d5b79556f99cfc2d9320b34cfbe5be05c5871b51de9329f0603b0474"}, - {file = "certifi-2023.11.17.tar.gz", hash = "sha256:9b469f3a900bf28dc19b8cfbf8019bf47f7fdd1a65a1d4ffb98fc14166beb4d1"}, + {file = "certifi-2024.2.2-py3-none-any.whl", hash = "sha256:dc383c07b76109f368f6106eee2b593b04a011ea4d55f652c6ca24a754d1cdd1"}, + {file = "certifi-2024.2.2.tar.gz", hash = "sha256:0569859f95fc761b18b45ef421b1290a0f65f147e92a1e5eb3e635f9a5e4e66f"}, ] [[package]] @@ -124,7 +124,6 @@ version = "0.4.6" requires_python = "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,!=3.4.*,!=3.5.*,!=3.6.*,>=2.7" summary = "Cross-platform colored terminal text." groups = ["default"] -marker = "platform_system == \"Windows\"" files = [ {file = "colorama-0.4.6-py2.py3-none-any.whl", hash = "sha256:4f1d9991f5acc0ca119f9d443620b77f9d6b33703e51011c16baf57afb285fc6"}, {file = "colorama-0.4.6.tar.gz", hash = "sha256:08695f5cb7ed6e0531a20572697297273c47b8cae5a63ffc6d6ed5c201be6e44"}, @@ -210,6 +209,17 @@ files = [ {file = "rich-13.7.0.tar.gz", hash = "sha256:5cb5123b5cf9ee70584244246816e9114227e0b98ad9176eede6ad54bf5403fa"}, ] +[[package]] +name = "shellingham" +version = "1.5.4" +requires_python = ">=3.7" +summary = "Tool to Detect Surrounding Shell" +groups = ["default"] +files = [ + {file = "shellingham-1.5.4-py2.py3-none-any.whl", hash = "sha256:7ecfff8f2fd72616f7481040475a65b2bf8af90a56c89140852d1120324e8686"}, + {file = "shellingham-1.5.4.tar.gz", hash = "sha256:8dbca0739d487e5bd35ab3ca4b36e11c4078f3a234bfce294b0a0291363404de"}, +] + [[package]] name = "typer" version = "0.9.0" @@ -225,6 +235,24 @@ files = [ {file = "typer-0.9.0.tar.gz", hash = "sha256:50922fd79aea2f4751a8e0408ff10d2662bd0c8bbfa84755a699f3bada2978b2"}, ] +[[package]] +name = "typer" +version = "0.9.0" +extras = ["all"] +requires_python = ">=3.6" +summary = "Typer, build great CLIs. Easy to code. Based on Python type hints." +groups = ["default"] +dependencies = [ + "colorama<0.5.0,>=0.4.3", + "rich<14.0.0,>=10.11.0", + "shellingham<2.0.0,>=1.3.0", + "typer==0.9.0", +] +files = [ + {file = "typer-0.9.0-py3-none-any.whl", hash = "sha256:5d96d986a21493606a358cae4461bd8cdf83cbf33a5aa950ae629ca3b51467ee"}, + {file = "typer-0.9.0.tar.gz", hash = "sha256:50922fd79aea2f4751a8e0408ff10d2662bd0c8bbfa84755a699f3bada2978b2"}, +] + [[package]] name = "typing-extensions" version = "4.9.0" @@ -238,11 +266,11 @@ files = [ [[package]] name = "urllib3" -version = "2.1.0" +version = "2.2.0" requires_python = ">=3.8" summary = "HTTP library with thread-safe connection pooling, file post, and more." groups = ["default"] files = [ - {file = "urllib3-2.1.0-py3-none-any.whl", hash = "sha256:55901e917a5896a349ff771be919f8bd99aff50b79fe58fec595eb37bbc56bb3"}, - {file = "urllib3-2.1.0.tar.gz", hash = "sha256:df7aa8afb0148fa78488e7899b2c59b5f4ffcfa82e6c54ccb9dd37c1d7b52d54"}, + {file = "urllib3-2.2.0-py3-none-any.whl", hash = "sha256:ce3711610ddce217e6d113a2732fafad960a03fd0318c91faa79481e35c11224"}, + {file = "urllib3-2.2.0.tar.gz", hash = "sha256:051d961ad0c62a94e50ecf1af379c3aba230c66c710493493560c0c223c49f20"}, ] diff --git a/pyproject.toml b/pyproject.toml index 8d4062f..da63281 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,16 +1,14 @@ [project] name = "bilifm" -version = "0.1.8" +version = "0.2.0" description = "Download Bilibili videos as audios." authors = [ {name = "jingfelix", email = "jingfelix@outlook.com"}, {name = "Felix Jing", email = "jingfelix@outlook.com"}, ] dependencies = [ - "click", "requests", - "rich", - "typer", + "typer[all]>=0.9.0", ] requires-python = ">=3.8" readme = "README.md" diff --git a/requirements.txt b/requirements.txt index e769d14..a84a276 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,16 +1,17 @@ # This file is @generated by PDM. # Please do not edit it manually. -certifi==2023.11.17 +certifi==2024.2.2 charset-normalizer==3.3.2 click==8.1.7 -colorama==0.4.6; platform_system == "Windows" +colorama==0.4.6 idna==3.6 markdown-it-py==3.0.0 mdurl==0.1.2 pygments==2.17.2 requests==2.31.0 rich==13.7.0 +shellingham==1.5.4 typer==0.9.0 typing-extensions==4.9.0 -urllib3==2.1.0 +urllib3==2.2.0 diff --git a/setup.py b/setup.py deleted file mode 100644 index 2845d7e..0000000 --- a/setup.py +++ /dev/null @@ -1,35 +0,0 @@ -import setuptools - -with open("README.md", "r", encoding="utf-8") as fh: - long_description = fh.read() - -setuptools.setup( - name="bilifm", - version="0.1.7", - author="Felix Jing", - author_email="jingfelix@outlook.com", - description="Download Bilibili videos as audios.", - long_description=long_description, - long_description_content_type="text/markdown", - url="https://github.com/jingfelix/bilifm", - project_urls={ - "Bug Tracker": "https://github.com/jingfelix/bilifm/issues", - }, - classifiers=[ - "Programming Language :: Python :: 3", - "License :: OSI Approved :: GNU General Public License v3 (GPLv3)", - "Operating System :: OS Independent", - ], - entry_points={ - "console_scripts": ["bilifm=bilifm.__init__:app"], - }, - install_requires=[ - "requests", - "click", - "typer", - "rich", - ], - package_dir={"": "src"}, - packages=setuptools.find_packages(where="src"), - python_requires=">=3.5", -) diff --git a/src/bilifm/audio.py b/src/bilifm/audio.py index 9bcd20b..f9b12f8 100644 --- a/src/bilifm/audio.py +++ b/src/bilifm/audio.py @@ -52,20 +52,18 @@ def download(self): start_time = time.time() try: for cid, part in zip(self.cid_list, self.part_list): + if len(self.part_list) > 1: + file_path = f"{self.title}-{part}.mp3" + else: + file_path = f"{self.title}.mp3" + + if len(file_path) > 255: + file_path = file_path[:255] + # 如果文件已存在,则跳过下载 - file_path = f"{self.title}-{part}.mp3" - try: - if os.path.exists(file_path): - typer.echo(f"{self.title} already exists, skip for now") - return - except OSError as e: - if e.errno == 36: - file_path = f"{part}.mp3" - if os.path.exists(file_path): - typer.echo(f"{part} already exists, skip for now") - return - else: - raise e + if os.path.exists(file_path): + typer.echo(f"{self.title} already exists, skip for now") + return params = get_signed_params( {