Skip to content

Commit 2a04fe4

Browse files
author
farfarfun
committed
bump ver to 1.1.80, limit data to 5 items, add file size fmt and source count extraction
1 parent 127da2e commit 2a04fe4

3 files changed

Lines changed: 37 additions & 2 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "funread"
3-
version = "1.1.79"
3+
version = "1.1.80"
44
description = "一个用于管理和处理阅读源(Legado 阅读 APP 的书源和 RSS 源)的 Python 工具库"
55
readme = "README.md"
66
requires-python = ">=3.8"

src/funread/legado/manage/download/base.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,8 @@ def export_sources(self, size: int = 1000) -> Iterator[List[Dict[str, Any]]]:
482482
continue
483483
if key == "candidate":
484484
_data = _data[:3]
485+
else:
486+
_data = _data[:5]
485487
for item in data[key]: # 每个文件最多取前3个
486488
if "source" not in item or "md5_list" not in item:
487489
continue

src/funread/legado/manage/download/generate.py

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,10 +165,42 @@ def get_downloader(self, path: str):
165165
return BookSourceDownload(path=path, cate1="book")
166166
return RSSSourceDownload(path=path, cate1="rss")
167167

168+
169+
@staticmethod
170+
def format_file_size(size: Any) -> str:
171+
"""将字节大小格式化为易读文本"""
172+
try:
173+
value = float(size)
174+
except (TypeError, ValueError):
175+
return str(size)
176+
177+
units = ["B", "KB", "MB", "GB", "TB"]
178+
unit_index = 0
179+
while value >= 1024 and unit_index < len(units) - 1:
180+
value /= 1024
181+
unit_index += 1
182+
if unit_index == 0:
183+
return f"{int(value)} {units[unit_index]}"
184+
return f"{value:.1f} {units[unit_index]}"
185+
186+
@staticmethod
187+
def extract_source_count(file: Dict[str, Any]) -> str:
188+
"""根据文件内容估算该批次包含的源数量"""
189+
name = str(file.get("name", ""))
190+
if name == "index.html":
191+
return "-"
192+
193+
size = file.get("size")
194+
try:
195+
return str(int(size)) if name.endswith(".json") and int(size) < 1024 else "-"
196+
except (TypeError, ValueError):
197+
return "-"
198+
168199
def set_table_head(self) -> None:
169200
"""设置表格头"""
170201
with tr():
171202
th("文件")
203+
th("源个数")
172204
th("大小")
173205
th("github")
174206
th("gitee")
@@ -177,7 +209,8 @@ def fill_table_data(self, file: Dict[str, Any]) -> None:
177209
"""填充表格数据行"""
178210
data_tr = tr()
179211
data_tr += td(file["name"])
180-
data_tr += td(file["size"])
212+
data_tr += td(self.extract_source_count(file))
213+
data_tr += td(self.format_file_size(file.get("size", 0)))
181214

182215
# GitHub 链接
183216
github_link = td()

0 commit comments

Comments
 (0)