bcmd 0.5.7__py3-none-any.whl → 0.5.9__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of bcmd might be problematic. Click here for more details.

bcmd/main.py CHANGED
@@ -6,5 +6,5 @@ from .tasks import *
6
6
 
7
7
 
8
8
  def run():
9
- btask.options.lock = 0
9
+ btask.options.lock = 0 # 允许多开
10
10
  asyncio.run(btask.main())
bcmd/tasks/__init__.py CHANGED
@@ -9,6 +9,7 @@ from . import json
9
9
  from . import lib
10
10
  from . import math
11
11
  from . import mirror
12
+ from . import pdf
12
13
  from . import project
13
14
  from . import proxy
14
15
  from . import time
bcmd/tasks/image.py CHANGED
@@ -65,7 +65,7 @@ async def convert(
65
65
  @syncCall
66
66
  async def tiny(
67
67
  path: Path = typer.Option(None, '--path', help='指定目录或具体图片文件,默认当前目录'),
68
- compression: int = typer.Option(75, '--compression', help='如果压缩小于指定数值则使用原来的图片,单位:%,默认75'),
68
+ optimization: int = typer.Option(25, '--optimization', help='指定优化大小,如果没有达到优化效果就不处理,单位:%,默认25'),
69
69
  isKeepOriginal: bool = typer.Option(False, '--keep-original', help='保留原始图片'),
70
70
  ):
71
71
 
@@ -75,6 +75,9 @@ async def tiny(
75
75
  'q8YLcvrXVW2NYcr5mMyzQhsSHF4j7gny',
76
76
  ]
77
77
  random.shuffle(keyList)
78
+
79
+ btask.assertTrue(0 < optimization < 100, '优化大小必须在0-100之间')
80
+ compression = 100 - optimization
78
81
  await block.setLimit(_TinyFile.runTiny, len(keyList))
79
82
 
80
83
  # 整理文件列表
@@ -103,7 +106,11 @@ async def tiny(
103
106
  pass
104
107
  else:
105
108
  # 要忽略掉的文件
106
- bcolor.printYellow(f'{file.file}({file.compression - 100:.2f}% / 已压缩 / {file.getSizeDisplay()})')
109
+ if file.isTiny:
110
+ bcolor.printYellow(f'{file.file}({file.compression - 100:.2f}% / 已压缩 / {file.getSizeDisplay()})')
111
+ else:
112
+ bcolor.printMagenta(f'{file.file}({file.compression - 100:.2f}% / 不处理 / {file.getSizeDisplay()})')
113
+
107
114
  fileList[i] = Null
108
115
  fileList = [x for x in fileList if x]
109
116
 
bcmd/tasks/pdf.py ADDED
@@ -0,0 +1,43 @@
1
+ from pathlib import Path
2
+ from typing import Final
3
+
4
+ import fitz
5
+ import typer
6
+ from beni import bcolor, bfile, btask
7
+ from beni.bfunc import syncCall
8
+
9
+ app: Final = btask.newSubApp('PDF相关')
10
+
11
+
12
+ @app.command()
13
+ @syncCall
14
+ async def output_images(
15
+ target: Path = typer.Option(Path.cwd(), '--target', help='PDF文件路径或多个PDF文件所在的目录'),
16
+ ):
17
+ '保存 PDF 文件里面的图片'
18
+
19
+ # 列出需要检查的PDF文件
20
+ pdfFileList: list[Path] = []
21
+ if target.is_dir():
22
+ pdfFileList = list(target.glob('*.pdf'))
23
+ elif target.is_file():
24
+ pdfFileList = [target]
25
+ else:
26
+ raise ValueError("目标路径不存在")
27
+
28
+ for pdf_file in pdfFileList:
29
+ pdf_document = fitz.open(pdf_file)
30
+ output_dir = pdf_file.with_name(pdf_file.stem + '-PDF图片文件')
31
+ for page_num in range(len(pdf_document)):
32
+ page = pdf_document.load_page(page_num)
33
+ images = page.get_images(full=True)
34
+ for img_index, img in enumerate(images):
35
+ xref = img[0]
36
+ base_image = pdf_document.extract_image(xref)
37
+ image_bytes = base_image["image"]
38
+ image_ext = base_image["ext"]
39
+ image_filename = f"page{page_num + 1}_img{img_index + 1}.{image_ext}"
40
+ image_path = output_dir / image_filename
41
+ output_dir.mkdir(exist_ok=True)
42
+ bcolor.printGreen(image_path)
43
+ await bfile.writeBytes(image_path, image_bytes)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: bcmd
3
- Version: 0.5.7
3
+ Version: 0.5.9
4
4
  Summary: Commands for Beni
5
5
  Author-email: Beni Mang <benimang@126.com>
6
6
  Maintainer-email: Beni Mang <benimang@126.com>
@@ -13,6 +13,7 @@ Requires-Dist: pathspec
13
13
  Requires-Dist: pillow
14
14
  Requires-Dist: prettytable
15
15
  Requires-Dist: psutil
16
+ Requires-Dist: pymupdf
16
17
  Requires-Dist: qiniu
17
18
  Requires-Dist: twine
18
19
  Requires-Dist: typer
@@ -1,5 +1,5 @@
1
1
  bcmd/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- bcmd/main.py,sha256=1HRCHLt_jeF6ImgjG_MX9N2x9H1f6FyqTX7UADzedfA,131
2
+ bcmd/main.py,sha256=GP_60-6vImXqdMfC5vc4xlscWajx4OYmnlNXASWn19w,147
3
3
  bcmd/common/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
4
  bcmd/common/func.py,sha256=MehbfuWFHTOsihhYxVFj0_U6-hjMTfLh3n-oMrpyyKo,508
5
5
  bcmd/common/password.py,sha256=25fA1h9ttZuUobnZ_nA0Ouhmk43etBfGeM40dgxJnFY,1347
@@ -8,24 +8,25 @@ bcmd/resources/project/main.py,sha256=xdskz_sf05fYA1SRMFCIxDjx8SnegxTbCmHpW86ItL
8
8
  bcmd/resources/project/.vscode/launch.json,sha256=Wpghb9lW9Y1wtrjqlTbyjeejDuU8BQJmBjwsLyPRh1g,478
9
9
  bcmd/resources/project/.vscode/settings.json,sha256=G4rCroWxEHcQfsqIJ6CXRHI6VGr3WYQI3KPPjH_JANs,280
10
10
  bcmd/resources/project/.vscode/tasks.json,sha256=gouhpkrqiPz7v65Jw1Rz-BCYU3sSdmphzXIYCzVnoe0,1783
11
- bcmd/tasks/__init__.py,sha256=siqJwKgsjiIQzarBsQaucjm6VEvDr1pJDuEd7UnDXSQ,316
11
+ bcmd/tasks/__init__.py,sha256=cHy7P9387I3ouanSV12pMrKBVNZ7SoUZHsJRuf8pjMo,334
12
12
  bcmd/tasks/bin.py,sha256=B_e-HYOc2Cohk-1PbKHyKn3RhI8TAUfI2EBRoFEHiTM,2961
13
13
  bcmd/tasks/code.py,sha256=IUs_ClZuSsBk2gavlitC8mkRrQQX9rvNDgR8cFxduBA,3992
14
14
  bcmd/tasks/crypto.py,sha256=C2welnYfdI4Tc-W1cwkboGb6bk6NGWO0MRKm4Bzo_9Q,3216
15
15
  bcmd/tasks/debian.py,sha256=B9aMIIct3vNqMJr5hTr1GegXVf20H49C27FMvRRGIzI,3004
16
16
  bcmd/tasks/download.py,sha256=XdZYKi8zQTNYWEgUxeTNDqPgP7IGYJkMmlDDC9u93Vk,2315
17
- bcmd/tasks/image.py,sha256=Po8jpEf4e1X68oJc2MYT446o-45RgIrl1TsODvUetBo,7782
17
+ bcmd/tasks/image.py,sha256=fxCiP9Xs4mxj6PhnZY2nRc0pvYg0DAbEIOFHhj-BkXA,8088
18
18
  bcmd/tasks/json.py,sha256=WWOyvcZPYaqQgp-Tkm-uIJschNMBKPKtZN3yXz_SC5s,635
19
19
  bcmd/tasks/lib.py,sha256=lq-PdHxhK-5Akf7k4QaIT8mBB-sCK5or5OqEFTdphIA,4567
20
20
  bcmd/tasks/math.py,sha256=xbl5UdaDMyAjiLodDPleP4Cutrk2S3NOAgurzAgOEAE,2862
21
21
  bcmd/tasks/mirror.py,sha256=nAe8NYftMKzht16MFBj7RqXwvVhR6Jh2uuAyJLh87og,1098
22
+ bcmd/tasks/pdf.py,sha256=fkHRgxqzrRxdb4_-9pL9wp2roqAHJPS_dVqAGJvRUsM,1504
22
23
  bcmd/tasks/project.py,sha256=yLYL6WNmq0mlY-hQ-SGKZ6uRjwceJxpgbP-QAo0Wk-Y,1948
23
24
  bcmd/tasks/proxy.py,sha256=xvxN5PClUnc5LQpmq2Wug7_LUVpJboMWLXBvL9lX7EM,1552
24
25
  bcmd/tasks/time.py,sha256=ZiqA1jdgl-TBtFSOxxP51nwv4g9iZItmkFKpf9MKelk,2453
25
26
  bcmd/tasks/upgrade.py,sha256=ZiyecgVbnnoTU_LAsd78CIKA4ioc9so9pXpAM76b_0M,447
26
27
  bcmd/tasks/venv.py,sha256=a7ZDyagUPQvCAXx3cZJIqJt0p1Iy5u5qmmj8iRbDQZE,7673
27
- bcmd-0.5.7.dist-info/METADATA,sha256=VYojYhON5P2o-Vmd9J-I3tOCdWTVYqR4R6uqplVK8JI,475
28
- bcmd-0.5.7.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
29
- bcmd-0.5.7.dist-info/entry_points.txt,sha256=rHJrP6KEQpB-YaQqDFzEL2v88r03rxSfnzAayRvAqHU,39
30
- bcmd-0.5.7.dist-info/top_level.txt,sha256=-KrvhhtBcYsm4XhcjQvEcFbBB3VXeep7d3NIfDTrXKQ,5
31
- bcmd-0.5.7.dist-info/RECORD,,
28
+ bcmd-0.5.9.dist-info/METADATA,sha256=cvbOTNQeImLrBxhbBDSwN27j4HjCz1wWTNOBNCBE420,499
29
+ bcmd-0.5.9.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
30
+ bcmd-0.5.9.dist-info/entry_points.txt,sha256=rHJrP6KEQpB-YaQqDFzEL2v88r03rxSfnzAayRvAqHU,39
31
+ bcmd-0.5.9.dist-info/top_level.txt,sha256=-KrvhhtBcYsm4XhcjQvEcFbBB3VXeep7d3NIfDTrXKQ,5
32
+ bcmd-0.5.9.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5