init
This commit is contained in:
1
utils/__init__.py
Normal file
1
utils/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# Utils package initialization
|
||||
52
utils/format.py
Normal file
52
utils/format.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import os
|
||||
|
||||
def format_file_size(size_bytes):
|
||||
"""将字节大小转换为可读性更好的格式"""
|
||||
if size_bytes == 0:
|
||||
return "0 B"
|
||||
|
||||
size_names = ["B", "KB", "MB", "GB", "TB"]
|
||||
i = 0
|
||||
while size_bytes >= 1024 and i < len(size_names) - 1:
|
||||
size_bytes /= 1024.0
|
||||
i += 1
|
||||
|
||||
return f"{size_bytes:.1f} {size_names[i]}"
|
||||
|
||||
def format_status(status):
|
||||
"""将状态代码转换为中文描述"""
|
||||
status_map = {
|
||||
'uploading': '做种中',
|
||||
'downloading': '下载中',
|
||||
'paused': '已暂停',
|
||||
'checking': '检查中',
|
||||
'error': '错误',
|
||||
'completed': '已完成',
|
||||
'stalledUP': '做种中(空闲)',
|
||||
'stalledDL': '下载中(空闲)',
|
||||
'queuedUP': '队列做种',
|
||||
'queuedDL': '队列下载',
|
||||
'forcedUP': '强制做种',
|
||||
'forcedDL': '强制下载',
|
||||
'missingFiles': '文件缺失',
|
||||
'allocating': '分配中',
|
||||
'metaDL': '获取元数据',
|
||||
'moving': '移动中',
|
||||
'unknown': '未知'
|
||||
}
|
||||
|
||||
# Transmission状态码映射
|
||||
transmission_status_map = {
|
||||
0: '已暂停',
|
||||
1: '等待校验',
|
||||
2: '正在校验',
|
||||
3: '等待下载',
|
||||
4: '下载中',
|
||||
5: '等待做种',
|
||||
6: '做种中'
|
||||
}
|
||||
|
||||
if isinstance(status, int):
|
||||
return transmission_status_map.get(status, '未知')
|
||||
else:
|
||||
return status_map.get(status, status)
|
||||
Reference in New Issue
Block a user