Compare commits
2 Commits
70e46124a0
...
b4c04343e8
Author | SHA1 | Date | |
---|---|---|---|
b4c04343e8 | |||
f539792fd1 |
4
.gitignore
vendored
4
.gitignore
vendored
@ -8,4 +8,6 @@ __pycache__
|
||||
*.log
|
||||
test
|
||||
.venv
|
||||
uv.lock
|
||||
uv.lock
|
||||
.claude
|
||||
CLAUDE.md
|
27
English_Listening_cut/README.md
Normal file
27
English_Listening_cut/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# English_Listening_cut
|
||||
|
||||
英语听力音频文件自动分割工具。
|
||||
|
||||
## 功能
|
||||
|
||||
自动分割英语听力考试音频文件,通过检测静音段落将长音频分割为多个小段,并按照规定格式组织输出文件。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 准备MP3格式的听力音频文件
|
||||
2. 运行 `python main.py 音频文件.mp3`
|
||||
3. 程序将在OUTPUT目录中创建结构化的分割文件
|
||||
|
||||
## 输出结构
|
||||
|
||||
分割后的文件将按以下结构组织:
|
||||
- BASIC文件夹:基础题目
|
||||
- 1-5文件夹:按题号分类
|
||||
- Others文件夹:其他片段
|
||||
|
||||
## 特性
|
||||
|
||||
- 自动静音检测
|
||||
- 智能分割算法
|
||||
- 规范化文件命名
|
||||
- 结构化输出目录
|
32
ImageCompress/README.md
Normal file
32
ImageCompress/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
# ImageCompress
|
||||
|
||||
批量图片压缩工具。
|
||||
|
||||
## 功能
|
||||
|
||||
使用FFmpeg对图片进行批量压缩,支持精确控制目标文件大小,通过迭代优化实现精准的大小控制。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `python b.py [目录/文件路径]`
|
||||
2. 根据提示输入目标文件大小(KB)
|
||||
3. 程序将自动压缩图片至指定大小
|
||||
|
||||
## 支持格式
|
||||
|
||||
- JPG
|
||||
- PNG
|
||||
- WebP
|
||||
- GIF
|
||||
|
||||
## 特性
|
||||
|
||||
- 精确大小控制
|
||||
- 迭代优化算法
|
||||
- 批量处理支持
|
||||
- 多进程并行处理
|
||||
- 质量自动调整
|
||||
|
||||
## 依赖要求
|
||||
|
||||
需要安装FFmpeg.exe并确保在系统路径中可访问。
|
142
README.md
142
README.md
@ -1,94 +1,98 @@
|
||||
# 个人使用小工具集
|
||||
|
||||
## [修改连接数](changeConnectionLimit)
|
||||
## 系统工具
|
||||
|
||||
win10修改wifi热点最大连接终端数
|
||||
### [修改连接数](changeConnectionLimit)
|
||||
修改Windows 10 WiFi热点最大连接终端数
|
||||
|
||||
Usage:`main.bat`
|
||||
### [字体替换](change_font)
|
||||
OCR文字检测与自定义字体替换工具
|
||||
|
||||
## [学*网预览下载](zxxk_dl)
|
||||
## 文件处理
|
||||
|
||||
下载学*网资源,通过预览的形式,下载的文件以html形式保存。可以使用adobe Acrobat的打印转为pdf,文字版文件以svg下载,图片版原图。
|
||||
### [图片压缩](ImageCompress)
|
||||
批量图片压缩工具,支持精确大小控制
|
||||
|
||||
1. 研究过程:[process.md](zxxk_dl/process.md)
|
||||
### [图片整理](tidy_img)
|
||||
按照手机照片视频命名规范自动分类整理文件
|
||||
|
||||
2. usage: `python main.py`
|
||||
3. requirements: python, requests
|
||||
### [文件加密](encryptFiles)
|
||||
基于RSA的文件夹加密解密工具
|
||||
|
||||
## adb快速传手机文件
|
||||
### [PDF解锁](pdf_unlock)
|
||||
移除PDF文件权限限制
|
||||
|
||||
源文件丢了,TODO
|
||||
### [编码转换](recode)
|
||||
文本文件字符编码格式转换工具
|
||||
|
||||
2024.7.14:放弃,已有项目[双轨快传](https://github.com/weixiansen574/HybridFileXfer)实现
|
||||
## 音视频处理
|
||||
|
||||
## [并行auto-editor](mult)
|
||||
### [听力文件拆分](English_Listening_cut)
|
||||
英语听力考试音频自动分割工具
|
||||
|
||||
并行运行auto-editor, 递归转码所有视频。(PS:网课时用的)
|
||||
### [批量视频处理](mult)
|
||||
使用auto-editor批量处理视频,去除静音片段
|
||||
|
||||
### files
|
||||
### [视频剪切](video)
|
||||
简单的视频时间段剪切工具
|
||||
|
||||
#### main.py
|
||||
### [视频时长调整](process_video)
|
||||
调整视频播放速度以达到目标时长
|
||||
|
||||
主程序
|
||||
## 学习教育
|
||||
|
||||
### main_up.py
|
||||
### [化学反应坐标图](cord)
|
||||
生成化学反应坐标图的Web工具
|
||||
|
||||
使用hevc(CUDA)硬解码
|
||||
### [化学计算工具](mw_tool)
|
||||
化合物查询与分子量计算平台
|
||||
|
||||
### usage
|
||||
### [座位表生成](seat_map)
|
||||
课堂座位安排自动生成工具
|
||||
|
||||
`python main.py`
|
||||
### [任务分配系统](task_assignment)
|
||||
基于Web的任务分配管理系统
|
||||
|
||||
## 菁*网题目下载
|
||||
### [学科网下载](zxxk_dl)
|
||||
学科网教育资源下载工具
|
||||
|
||||
### [问卷星抓取](wjx)
|
||||
问卷星调查数据获取工具
|
||||
|
||||
### [教务系统登录](jw)
|
||||
教务系统自动登录工具(URP新版,登录逆向,API在更改没有持续更新。但是核心算法没变)
|
||||
|
||||
## 网络下载
|
||||
|
||||
### [123pan下载](down)
|
||||
123pan云盘文件批量下载工具
|
||||
|
||||
## 实用工具
|
||||
|
||||
### [运动监控](move_warn)
|
||||
IP摄像头运动检测报警工具
|
||||
|
||||
### [随机数生成](rand)
|
||||
交互式随机数生成器
|
||||
|
||||
### [拼音转换](pinyin)
|
||||
中文姓名转拼音首字母工具
|
||||
|
||||
### [对话转换](conversation_trans)
|
||||
对话数据转Markdown格式工具
|
||||
|
||||
---
|
||||
|
||||
## 已停止维护
|
||||
|
||||
### adb快速传手机文件
|
||||
源文件丢了,已有项目[双轨快传](https://github.com/weixiansen574/HybridFileXfer)实现
|
||||
|
||||
### 菁优网题目下载
|
||||
**ATTENTION:目前制作时的账号疑似被封禁,请谨慎使用**
|
||||
|
||||
如需打印,请使用浏览器打印或转pdf
|
||||
### 检测视频是否破损(video_test)
|
||||
功能已整合到其他工具中
|
||||
|
||||
### Usage
|
||||
|
||||
菁优网任意界面,F12抓Cookie
|
||||
运行main.py,输入复制的内容,根据提示输入网址即可。
|
||||
|
||||
### requements
|
||||
|
||||
python, requests,bs4
|
||||
|
||||
## [听力文件拆分](English_Listening_cut)
|
||||
|
||||
基于学英语报的听力做听力文件拆解,拆分到每段对话
|
||||
|
||||
### Usage
|
||||
|
||||
`python main.py`
|
||||
|
||||
## seat_map
|
||||
|
||||
文档TODO
|
||||
|
||||
## 简单运动报警(move_warn)
|
||||
|
||||
对ip摄像头画面进行简单运动捕捉,核心代码来自网络。效果:运动达到一定范围,发出声音警告后自动关闭程序。
|
||||
|
||||
### usage
|
||||
|
||||
`python main.py`
|
||||
|
||||
### requirements
|
||||
|
||||
python, opencv
|
||||
|
||||
## 检测视频是否破损(video_test)
|
||||
|
||||
|
||||
|
||||
## 转移libcef.dll(move_CEF)
|
||||
|
||||
通过Everything API遍历所有libcef.dll,核验md5后转移至指定文件夹并创建软连接。
|
||||
|
||||
## [图片整理(tidy_img)](tidy_img)
|
||||
|
||||
按照手机(华为)照片视频命名规范(例如`IMG_20170218_164951.jpg`,`VID_20220116_154728.mp4`)将其按年份分类,递归遍历所有文件。如果重复,文件相同<sup>[1]</sup>由用户判断是否删除相同文件。如果文件冲突<sup>[2]</sup>,放入conflict文件夹,并在文件名后加sha256前5位。
|
||||
|
||||
[1]: 先判断文件大小,相同比较sha256值,如果均相同认为是同文件
|
||||
[2]: 上述标准任一不满足
|
||||
### 转移libcef.dll(move_CEF)
|
||||
通过Everything API遍历所有libcef.dll,核验md5后转移至指定文件夹并创建软连接
|
||||
|
174
VideoCompress/README.md
Normal file
174
VideoCompress/README.md
Normal file
@ -0,0 +1,174 @@
|
||||
# VideoCompress 🎬
|
||||
|
||||
一个功能强大的视频批量压缩工具,基于 FFmpeg 构建,支持硬件加速和多种压缩配置选项。
|
||||
|
||||
## ✨ 主要特性
|
||||
|
||||
- **批量处理**: 递归扫描目录,批量压缩多个视频文件
|
||||
- **硬件加速**: 支持 NVIDIA、AMD、Intel 显卡硬件加速
|
||||
- **灵活配置**: 支持 CRF 和固定码率两种压缩模式
|
||||
- **进度显示**: 实时显示压缩进度和预估时间
|
||||
- **多种界面**: 提供 Tkinter 和 PySide6 两种 GUI 配置界面
|
||||
- **智能跳过**: 自动跳过已存在的压缩文件
|
||||
- **格式支持**: 支持 MP4、MKV 等多种视频格式
|
||||
|
||||
## 🚀 快速开始
|
||||
|
||||
### 环境要求
|
||||
|
||||
- Python 3.7+
|
||||
- FFmpeg(已内置 ffmpeg.exe)
|
||||
|
||||
### 安装依赖
|
||||
|
||||
```bash
|
||||
pip install rich PySide6
|
||||
```
|
||||
|
||||
### 基本使用
|
||||
|
||||
1. **启动配置界面**:
|
||||
```bash
|
||||
python config_ui.py
|
||||
```
|
||||
|
||||
2. **直接压缩视频**:
|
||||
```bash
|
||||
python main.py <目标目录>
|
||||
```
|
||||
|
||||
3. **配置后压缩**:
|
||||
```bash
|
||||
python config.py <目标目录>
|
||||
```
|
||||
|
||||
## ⚙️ 配置选项
|
||||
|
||||
### 基础设置
|
||||
|
||||
- **输出方式**:
|
||||
- `single`: 所有压缩文件保存到统一的 Compress 文件夹
|
||||
- `multi`: 在每个视频文件旁创建独立的 compress 文件夹
|
||||
|
||||
- **编码器**:
|
||||
- `h264`: H.264 编码(兼容性好)
|
||||
- `hevc`: H.265 编码(文件更小)
|
||||
|
||||
### 质量设置
|
||||
|
||||
- **CRF 模式**(推荐):
|
||||
- 数值范围:0-51
|
||||
- 数值越小质量越高,文件越大
|
||||
- 推荐值:18-23
|
||||
|
||||
- **固定码率模式**:
|
||||
- 格式:数字+单位(如 2M、500k)
|
||||
- 可以精确控制文件大小
|
||||
|
||||
### 硬件加速
|
||||
|
||||
- **NVIDIA 显卡**:使用 `h264_nvenc` 或 `hevc_nvenc`
|
||||
- **AMD 显卡**:使用 `h264_amf` 或 `hevc_amf`
|
||||
- **Intel 核显**:使用 `h264_qsv` 或 `hevc_qsv`
|
||||
|
||||
## 📁 项目结构
|
||||
|
||||
```
|
||||
VideoCompress/
|
||||
├── main.py # 核心压缩引擎
|
||||
├── config.py # Tkinter 配置界面
|
||||
├── config_ui.py # PySide6 现代化配置界面
|
||||
├── config.json # 配置文件
|
||||
├── ffmpeg.exe # FFmpeg 可执行文件
|
||||
├── ffprobe.exe # FFprobe 可执行文件
|
||||
├── test.py # 测试文件
|
||||
├── pack.bat # 打包脚本
|
||||
└── logs/ # 日志文件夹
|
||||
```
|
||||
|
||||
## 🔧 高级用法
|
||||
|
||||
### 自定义 FFmpeg 参数
|
||||
|
||||
在配置界面的"高级设置"中,可以添加自定义 FFmpeg 参数:
|
||||
|
||||
```bash
|
||||
# 示例:设置线程数
|
||||
-threads 4
|
||||
|
||||
# 示例:自定义预设
|
||||
-preset slow
|
||||
|
||||
# 示例:音频编码设置
|
||||
-c:a aac -b:a 128k
|
||||
```
|
||||
|
||||
### 手动参数模式
|
||||
|
||||
如果需要完全自定义压缩命令,可以在配置文件中设置 `manual` 参数:
|
||||
|
||||
```json
|
||||
{
|
||||
"manual": ["-vf", "scale=1280:720", "-c:v", "libx264", "-crf", "20"]
|
||||
}
|
||||
```
|
||||
|
||||
### 训练模式(实验性)
|
||||
|
||||
启用训练模式可以让程序学习压缩时间,提供更准确的时间预估:
|
||||
|
||||
```json
|
||||
{
|
||||
"train": true
|
||||
}
|
||||
```
|
||||
|
||||
## 📊 输出示例
|
||||
|
||||
```
|
||||
2025-08-26 19:20:15 - INFO - Video Compress started at 2025/08/26 19:20
|
||||
2025-08-26 19:20:15 - INFO - 开始验证环境
|
||||
2025-08-26 19:20:16 - INFO - 正在获取视频信息 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 100%
|
||||
2025-08-26 19:20:17 - INFO - 总进度 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 45%
|
||||
2025-08-26 19:20:17 - INFO - test.mp4 ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 67%
|
||||
```
|
||||
|
||||
## 🎯 使用场景
|
||||
|
||||
- **批量压缩**: 处理大量视频文件,减小存储空间
|
||||
- **格式转换**: 将各种格式的视频统一转换为 MP4
|
||||
- **质量优化**: 在保持视觉质量的前提下减小文件体积
|
||||
- **硬件加速**: 利用显卡加速,提高压缩效率
|
||||
|
||||
## ⚠️ 注意事项
|
||||
|
||||
1. 确保有足够的磁盘空间存储压缩后的文件
|
||||
2. 硬件加速需要相应的显卡驱动支持
|
||||
3. 压缩过程中避免强制退出,可能导致文件损坏
|
||||
4. 建议先用小批量文件测试配置效果
|
||||
|
||||
## 🐛 常见问题
|
||||
|
||||
**Q: 压缩后文件变大了?**
|
||||
A: 降低 CRF 值或检查原文件是否已经是高压缩格式
|
||||
|
||||
**Q: 硬件加速不生效?**
|
||||
A: 检查显卡驱动是否支持对应的编码器
|
||||
|
||||
**Q: 程序卡在某个文件?**
|
||||
A: 检查该文件是否损坏或格式不被支持
|
||||
|
||||
## 📝 更新日志
|
||||
|
||||
- **v1.2.1**: 优化进度显示,修复时间预估
|
||||
- **v1.2**: 添加 PySide6 现代化界面
|
||||
- **v1.1**: 支持硬件加速和多种编码器
|
||||
- **v1.0**: 基础批量压缩功能
|
||||
|
||||
## 📄 许可证
|
||||
|
||||
本项目仅供学习和个人使用。
|
||||
|
||||
---
|
||||
|
||||
💡 **提示**: 如有问题或建议,欢迎提出 Issue 或 Pull Request。
|
@ -11,6 +11,10 @@ from pickle import dumps, loads
|
||||
from typing import Optional
|
||||
import atexit
|
||||
import re
|
||||
import threading
|
||||
import queue
|
||||
import psutil
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
root = None
|
||||
TRAIN = False
|
||||
@ -25,11 +29,29 @@ CFG = {
|
||||
"ffmpeg": "ffmpeg",
|
||||
"manual": None,
|
||||
"video_ext": [".mp4", ".mkv"],
|
||||
"train": False
|
||||
|
||||
"train": False,
|
||||
"compress_dir_name": "compress",
|
||||
"resolution": "-1:1080",
|
||||
"fps": "30",
|
||||
"esti_data_file": "estiminate_data.dat",
|
||||
"test_video_resolution": "1920x1080",
|
||||
"test_video_fps": "30",
|
||||
"test_video_input": "compress_video_test.mp4",
|
||||
"test_video_output": "compressed_video_test.mp4",
|
||||
"max_concurrent_instances": 2,
|
||||
"cpu_monitor_interval": 3, # CPU监控间隔(秒)
|
||||
"cpu_monitor_duration": 30, # 统计持续时间(秒,5分钟)
|
||||
}
|
||||
esti=None # :tuple[list[int],list[float]]
|
||||
|
||||
# CPU监控相关全局变量
|
||||
ffmpeg_processes = {} # 存储活动的ffmpeg进程
|
||||
cpu_stats = {"system": [], "ffmpeg": []} # CPU使用率统计
|
||||
cpu_monitor_thread = None
|
||||
cpu_monitor_lock = threading.Lock()
|
||||
current_instances = 0
|
||||
instance_lock = threading.Lock()
|
||||
|
||||
def get_cmd(video_path,output_file):
|
||||
if CFG["manual"] is not None:
|
||||
command=[
|
||||
@ -46,23 +68,31 @@ def get_cmd(video_path,output_file):
|
||||
CFG["ffmpeg"],
|
||||
"-hide_banner",
|
||||
"-i", video_path,
|
||||
"-vf", "scale=-1:1080",
|
||||
]
|
||||
if CFG['resolution'] is not None:
|
||||
command.extend([
|
||||
"-vf", f"scale={CFG['resolution']}",])
|
||||
command.extend([
|
||||
"-c:v", CFG["codec"],
|
||||
"-b:v", CFG["bitrate"],
|
||||
"-r","30",
|
||||
"-r",CFG["fps"],
|
||||
"-y",
|
||||
]
|
||||
])
|
||||
else:
|
||||
command = [
|
||||
CFG["ffmpeg"],
|
||||
"-hide_banner",
|
||||
"-i", video_path,
|
||||
"-vf", "scale=-1:1080",
|
||||
]
|
||||
if CFG['resolution'] is not None:
|
||||
command.extend([
|
||||
"-vf", f"scale={CFG['resolution']}",])
|
||||
command.extend([
|
||||
"-c:v", CFG["codec"],
|
||||
"-global_quality", str(CFG["crf"]),
|
||||
"-r","30",
|
||||
"-r",CFG["fps"],
|
||||
"-y",
|
||||
]
|
||||
])
|
||||
|
||||
command.extend(CFG["extra"])
|
||||
command.append(output_file)
|
||||
@ -70,7 +100,7 @@ def get_cmd(video_path,output_file):
|
||||
|
||||
def train_init():
|
||||
global esti_data,TRAIN,data_file
|
||||
data_file = Path("estiminate_data.dat")
|
||||
data_file = Path(CFG["esti_data_file"])
|
||||
if data_file.exists():
|
||||
esti_data=loads(data_file.read_bytes())
|
||||
if not isinstance(esti_data,tuple):
|
||||
@ -187,6 +217,99 @@ def fmt_time(t:float|int) -> str:
|
||||
else:
|
||||
return f"{round(t)}s"
|
||||
|
||||
def cpu_monitor():
|
||||
"""CPU监控线程函数"""
|
||||
global cpu_stats
|
||||
|
||||
while True:
|
||||
try:
|
||||
# 获取系统CPU使用率
|
||||
system_cpu = psutil.cpu_percent(interval=1)
|
||||
|
||||
# 获取所有ffmpeg进程的CPU使用率
|
||||
ffmpeg_cpu_total = 0
|
||||
active_processes = []
|
||||
|
||||
with cpu_monitor_lock:
|
||||
for proc_info in ffmpeg_processes.values():
|
||||
try:
|
||||
proc = proc_info['process']
|
||||
if proc.is_running():
|
||||
# print(proc,proc.cpu_percent() / psutil.cpu_count())
|
||||
ffmpeg_cpu_total += proc.cpu_percent() / psutil.cpu_count()
|
||||
active_processes.append(proc_info)
|
||||
except (psutil.NoSuchProcess, psutil.AccessDenied):
|
||||
continue
|
||||
|
||||
# 更新统计数据
|
||||
with cpu_monitor_lock:
|
||||
cpu_stats["system"].append(system_cpu)
|
||||
cpu_stats["ffmpeg"].append(ffmpeg_cpu_total)
|
||||
|
||||
# 保持最近5分钟的数据
|
||||
max_samples = CFG["cpu_monitor_duration"] // CFG["cpu_monitor_interval"]
|
||||
if len(cpu_stats["system"]) > max_samples:
|
||||
cpu_stats["system"] = cpu_stats["system"][-max_samples:]
|
||||
if len(cpu_stats["ffmpeg"]) > max_samples:
|
||||
cpu_stats["ffmpeg"] = cpu_stats["ffmpeg"][-max_samples:]
|
||||
|
||||
logging.debug(f"CPU监控: 系统={system_cpu:.1f}%, FFmpeg总计={ffmpeg_cpu_total:.1f}%, 活动进程={len(active_processes)}")
|
||||
except KeyboardInterrupt as e:
|
||||
raise e
|
||||
except Exception as e:
|
||||
logging.debug(f"CPU监控异常: {e}")
|
||||
|
||||
# 等待下一次监控
|
||||
threading.Event().wait(CFG["cpu_monitor_interval"])
|
||||
|
||||
def start_cpu_monitor():
|
||||
"""启动CPU监控线程"""
|
||||
global cpu_monitor_thread
|
||||
if cpu_monitor_thread is None or not cpu_monitor_thread.is_alive():
|
||||
cpu_monitor_thread = threading.Thread(target=cpu_monitor, daemon=True)
|
||||
cpu_monitor_thread.start()
|
||||
logging.info("CPU监控线程已启动")
|
||||
|
||||
def get_cpu_usage_stats():
|
||||
"""获取CPU使用率统计"""
|
||||
with cpu_monitor_lock:
|
||||
if not cpu_stats["system"] or not cpu_stats["ffmpeg"]:
|
||||
return None, None
|
||||
|
||||
system_avg = sum(cpu_stats["system"]) / len(cpu_stats["system"])
|
||||
ffmpeg_avg = sum(cpu_stats["ffmpeg"]) / len(cpu_stats["ffmpeg"])
|
||||
|
||||
return system_avg, ffmpeg_avg
|
||||
|
||||
def should_increase_instances():
|
||||
"""判断是否应该增加实例数"""
|
||||
system_avg, ffmpeg_avg = get_cpu_usage_stats()
|
||||
|
||||
if system_avg is None or ffmpeg_avg is None:
|
||||
return False
|
||||
|
||||
# 条件: 系统CPU - FFmpeg CPU > FFmpeg CPU * 2 + 0.1
|
||||
available_cpu = 100 - system_avg
|
||||
threshold = ffmpeg_avg # 10% = 0.1 * 100
|
||||
|
||||
logging.debug(f"CPU统计: 系统平均={system_avg:.1f}%, FFmpeg平均={ffmpeg_avg:.1f}%, 可用={available_cpu:.1f}%, 阈值={threshold:.1f}%")
|
||||
|
||||
return available_cpu > threshold
|
||||
|
||||
def register_ffmpeg_process(proc_id, process):
|
||||
"""注册ffmpeg进程用于监控"""
|
||||
with cpu_monitor_lock:
|
||||
ffmpeg_processes[proc_id] = {
|
||||
'process': psutil.Process(process.pid),
|
||||
'start_time': time()
|
||||
}
|
||||
|
||||
def unregister_ffmpeg_process(proc_id):
|
||||
"""注销ffmpeg进程"""
|
||||
with cpu_monitor_lock:
|
||||
if proc_id in ffmpeg_processes:
|
||||
del ffmpeg_processes[proc_id]
|
||||
|
||||
def func(sz:int,src=False):
|
||||
if TRAIN:
|
||||
try:
|
||||
@ -216,21 +339,15 @@ def func(sz:int,src=False):
|
||||
logging.debug("esti time exception", exc_info=e)
|
||||
return -1 if src else "NaN"
|
||||
|
||||
def process_video(video_path: Path, compress_dir:Optional[Path]=None ,update_func=None):
|
||||
global esti_data
|
||||
def process_video(video_path: Path, compress_dir:Optional[Path]=None, update_func=None, proc_id=None):
|
||||
global esti_data, current_instances
|
||||
use=None
|
||||
sz=video_path.stat().st_size//(1024*1024)
|
||||
# if esti is not None or TRAIN:
|
||||
# use = func(sz,True)
|
||||
# logging.info(f"开始处理文件: {video_path.relative_to(root)},大小{sz}M,预计{fmt_time(use)}")
|
||||
# else:
|
||||
# logging.info(f"开始处理文件: {video_path.relative_to(root)},大小{sz}M")
|
||||
|
||||
|
||||
bgn=time()
|
||||
if compress_dir is None:
|
||||
# 在视频文件所在目录下创建 compress 子目录(如果不存在)
|
||||
compress_dir = video_path.parent / "compress"
|
||||
compress_dir = video_path.parent / CFG["compress_dir_name"]
|
||||
else:
|
||||
compress_dir /= video_path.parent.relative_to(root)
|
||||
|
||||
@ -246,6 +363,11 @@ def process_video(video_path: Path, compress_dir:Optional[Path]=None ,update_fun
|
||||
command = get_cmd(video_path_str,output_file)
|
||||
|
||||
try:
|
||||
with instance_lock:
|
||||
current_instances += 1
|
||||
|
||||
logging.debug(f"启动FFmpeg进程 {proc_id}: {video_path.name}")
|
||||
|
||||
result = subprocess.Popen(
|
||||
command,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -254,17 +376,19 @@ def process_video(video_path: Path, compress_dir:Optional[Path]=None ,update_fun
|
||||
text=True
|
||||
)
|
||||
|
||||
# 注册进程用于CPU监控
|
||||
if proc_id:
|
||||
register_ffmpeg_process(proc_id, result)
|
||||
|
||||
while result.poll() is None:
|
||||
line = " "
|
||||
while result.poll() is None and line[-1:] not in "\r\n":
|
||||
line+=result.stderr.read(1)
|
||||
# print(line[-1])
|
||||
if 'warning' in line.lower():
|
||||
logging.warning(f"[FFmpeg]({video_path_str}): {line}")
|
||||
logging.warning(f"[FFmpeg {proc_id}]({video_path_str}): {line}")
|
||||
elif 'error' in line.lower():
|
||||
logging.error(f"[FFmpeg]({video_path_str}): {line}")
|
||||
logging.error(f"[FFmpeg {proc_id}]({video_path_str}): {line}")
|
||||
elif "frame=" in line:
|
||||
# print(line,end="")
|
||||
match = re.search(r"frame=\s*(\d+)",line)
|
||||
if match:
|
||||
frame_number = int(match.group(1))
|
||||
@ -272,9 +396,9 @@ def process_video(video_path: Path, compress_dir:Optional[Path]=None ,update_fun
|
||||
update_func(frame_number)
|
||||
|
||||
if result.returncode != 0:
|
||||
logging.error(f"处理文件 {video_path_str} 失败,返回码: {result.returncode},cmd={' '.join(command)}")
|
||||
logging.error(result.stdout)
|
||||
logging.error(result.stderr)
|
||||
logging.error(f"处理文件 {video_path_str} 失败,返回码: {result.returncode},cmd={' '.join(map(str,command))}")
|
||||
logging.error(result.stdout.read())
|
||||
logging.error(result.stderr.read())
|
||||
else:
|
||||
logging.debug(f"文件处理成功: {video_path_str} -> {output_file}")
|
||||
|
||||
@ -282,13 +406,23 @@ def process_video(video_path: Path, compress_dir:Optional[Path]=None ,update_fun
|
||||
if TRAIN:
|
||||
esti_data[0].append(sz)
|
||||
esti_data[1].append(end-bgn)
|
||||
|
||||
|
||||
except KeyboardInterrupt as e:raise e
|
||||
except Exception as e:
|
||||
logging.error(f"执行 ffmpeg 命令时发生异常, 文件:{str(video_path_str)},cmd={' '.join(map(str,command))}",exc_info=e)
|
||||
finally:
|
||||
# 注销进程监控
|
||||
if proc_id:
|
||||
unregister_ffmpeg_process(proc_id)
|
||||
|
||||
with instance_lock:
|
||||
current_instances -= 1
|
||||
|
||||
logging.debug(f"FFmpeg进程 {proc_id} 已结束")
|
||||
|
||||
return use
|
||||
|
||||
def traverse_directory(root_dir: Path):
|
||||
global current_instances
|
||||
video_extensions = set(CFG["video_ext"])
|
||||
sm=None
|
||||
if esti is not None:
|
||||
@ -296,7 +430,7 @@ def traverse_directory(root_dir: Path):
|
||||
logging.info(f"正在估算时间(当存在大量小文件时,估算值将会很离谱)")
|
||||
sm = 0
|
||||
for file in root_dir.rglob("*"):
|
||||
if file.parent.name == "compress":continue
|
||||
if file.parent.name.lower() == CFG["compress_dir_name"].lower():continue
|
||||
if file.is_file() and file.suffix.lower() in video_extensions:
|
||||
sz=file.stat().st_size//(1024*1024)
|
||||
tmp = func(sz,True)
|
||||
@ -307,84 +441,196 @@ def traverse_directory(root_dir: Path):
|
||||
sm += tmp
|
||||
logging.info(f"预估用时:{fmt_time(sm)}")
|
||||
else:
|
||||
# logging.info("正在估算视频帧数,用于显示进度。")
|
||||
with Progress() as prog:
|
||||
task = prog.add_task("正在获取视频信息",total=len(list(root_dir.rglob("*"))))
|
||||
frames:dict[Path,float] = {}
|
||||
for file in root_dir.rglob("*"):
|
||||
prog.advance(task)
|
||||
if file.parent.name == "Compress":continue
|
||||
# 获取视频文件列表和帧数信息
|
||||
video_files = []
|
||||
que = list(root_dir.glob("*"))
|
||||
while que:
|
||||
d = que.pop()
|
||||
for file in d.glob("*"):
|
||||
if file.parent.name == CFG["compress_dir_name"] or file.name == CFG["compress_dir_name"]:
|
||||
continue
|
||||
if file.is_file() and file.suffix.lower() in video_extensions:
|
||||
cmd = f'ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate,duration -of default=nokey=1:noprint_wrappers=1'.split()
|
||||
cmd.append(str(file))
|
||||
proc = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
if proc.returncode != 0:
|
||||
logging.debug(f"无法获取视频信息: {file}, 返回码: {proc.returncode}")
|
||||
logging.debug(proc.stdout)
|
||||
logging.debug(proc.stderr)
|
||||
frames[file] = 0
|
||||
continue
|
||||
if proc.stdout.strip():
|
||||
video_files.append(file)
|
||||
elif file.is_dir():
|
||||
que.append(file)
|
||||
|
||||
|
||||
# exit()
|
||||
|
||||
if not video_files:
|
||||
logging.warning("未找到需要处理的视频文件")
|
||||
return
|
||||
|
||||
# 获取视频信息
|
||||
with Progress() as prog:
|
||||
task = prog.add_task("正在获取视频信息", total=len(video_files))
|
||||
frames: dict[Path, float] = {}
|
||||
for file in video_files:
|
||||
prog.advance(task)
|
||||
cmd = f'ffprobe -v error -select_streams v:0 -show_entries stream=avg_frame_rate,duration -of default=nokey=1:noprint_wrappers=1'.split()
|
||||
cmd.append(str(file))
|
||||
proc = subprocess.run(cmd, shell=True, capture_output=True, text=True)
|
||||
if proc.returncode != 0:
|
||||
logging.debug(f"无法获取视频信息: {file}, 返回码: {proc.returncode}")
|
||||
frames[file] = 0
|
||||
continue
|
||||
if proc.stdout.strip():
|
||||
try:
|
||||
avg_frame_rate, duration = proc.stdout.strip().split('\n')
|
||||
tmp = avg_frame_rate.split('/')
|
||||
avg_frame_rate = float(tmp[0]) / float(tmp[1])
|
||||
if duration == "N/A":
|
||||
duration = 0
|
||||
logging.debug(f"无法获取视频信息: {file}, 时长为N/A,默认使用0s。运行时进度条将出现异常。")
|
||||
logging.debug(f"无法获取视频信息: {file}, 时长为N/A,默认使用0s")
|
||||
duration = float(duration)
|
||||
frames[file] = duration * avg_frame_rate
|
||||
|
||||
|
||||
logging.debug(f"开始遍历目录: {root_dir}")
|
||||
# 定义需要处理的视频后缀(忽略大小写)
|
||||
except (ValueError, IndexError) as e:
|
||||
logging.debug(f"解析视频信息失败: {file}, 错误: {e}")
|
||||
frames[file] = 0
|
||||
|
||||
logging.debug(f"开始遍历目录: {root_dir}, 共{len(frames)}个视频文件")
|
||||
|
||||
# 启动CPU监控
|
||||
start_cpu_monitor()
|
||||
|
||||
# 创建进度条
|
||||
with Progress() as prog:
|
||||
task = prog.add_task("总进度",total=sm if sm is not None else sum(frames.values()))
|
||||
total_frames = sum(frames.values())
|
||||
main_task = prog.add_task("总进度", total=total_frames if total_frames > 0 else len(frames))
|
||||
|
||||
# 创建文件队列
|
||||
file_queue = queue.Queue()
|
||||
for file in frames.keys():
|
||||
# if "Compress" in file.relative_to(root_dir).parents:continue
|
||||
if file.is_file() and file.suffix.lower() in video_extensions:
|
||||
filename = file.relative_to(root_dir)
|
||||
if frames[file] == 0:
|
||||
logging.warning("当前文件时长获取失败,进度条持续为0为正常现象。")
|
||||
cur = prog.add_task(f"{filename}")
|
||||
file_queue.put(file)
|
||||
|
||||
# 进度跟踪
|
||||
progress_trackers = {}
|
||||
completed_files = 0
|
||||
total_completed_frames = 0
|
||||
|
||||
def create_progress_updater(file_path, task_id):
|
||||
def update_progress(frame_count):
|
||||
nonlocal total_completed_frames
|
||||
if file_path in progress_trackers:
|
||||
old_frames = progress_trackers[file_path]
|
||||
diff = frame_count - old_frames
|
||||
total_completed_frames += diff
|
||||
else:
|
||||
cur = prog.add_task(f"{filename}",total=frames[file])
|
||||
with prog._lock:
|
||||
tmp = prog._tasks[task]
|
||||
completed_start = tmp.completed
|
||||
|
||||
def update_progress(x):
|
||||
if frames[file] == 0:
|
||||
prog.update(cur,description=f"{filename} 已处理{x}帧")
|
||||
else:
|
||||
prog.update(cur,completed=x)
|
||||
prog.update(task, completed=completed_start+x)
|
||||
total_completed_frames += frame_count
|
||||
progress_trackers[file_path] = frame_count
|
||||
|
||||
if frames[file_path] > 0:
|
||||
prog.update(task_id, completed=frame_count)
|
||||
else:
|
||||
prog.update(task_id, description=f"{file_path.relative_to(root_dir)} 已处理{frame_count}帧")
|
||||
|
||||
# 更新总进度
|
||||
if total_frames > 0:
|
||||
prog.update(main_task, completed=total_completed_frames)
|
||||
return update_progress
|
||||
|
||||
def process_file_worker():
|
||||
nonlocal completed_files
|
||||
while True:
|
||||
try:
|
||||
file = file_queue.get(timeout=1)
|
||||
except queue.Empty:
|
||||
break
|
||||
|
||||
filename = file.relative_to(root_dir)
|
||||
|
||||
# 创建文件级进度条
|
||||
if frames[file] == 0:
|
||||
file_task = prog.add_task(f"{filename}")
|
||||
else:
|
||||
file_task = prog.add_task(f"{filename}", total=frames[file])
|
||||
|
||||
progress_updater = create_progress_updater(file, file_task)
|
||||
|
||||
# 处理视频
|
||||
proc_id = f"worker_{threading.current_thread().ident}_{completed_files}"
|
||||
|
||||
if CFG["save_to"] == "single":
|
||||
t = process_video(file, root_dir/"Compress", update_progress)
|
||||
process_video(file, root_dir/"Compress", progress_updater, proc_id)
|
||||
else:
|
||||
t = process_video(file, update_progress)
|
||||
|
||||
process_video(file, None, progress_updater, proc_id)
|
||||
|
||||
prog.stop_task(cur)
|
||||
prog.remove_task(cur)
|
||||
if t is None:
|
||||
prog.update(task,completed=completed_start+frames[file])
|
||||
else:
|
||||
prog.advance(task,t)
|
||||
# 更新完成计数
|
||||
with instance_lock:
|
||||
completed_files += 1
|
||||
if total_frames == 0: # 如果没有总帧数,按文件数计算
|
||||
prog.update(main_task, completed=completed_files)
|
||||
|
||||
# 移除文件级进度条
|
||||
prog.remove_task(file_task)
|
||||
file_queue.task_done()
|
||||
|
||||
# 动态管理线程数
|
||||
active_threads = []
|
||||
max_workers = CFG["max_concurrent_instances"]
|
||||
|
||||
def manage_workers():
|
||||
nonlocal active_threads
|
||||
|
||||
while completed_files < len(frames) or any(t.is_alive() for t in active_threads):
|
||||
# 清理已完成的线程
|
||||
active_threads = [t for t in active_threads if t.is_alive()]
|
||||
|
||||
# 检查是否需要增加实例
|
||||
current_worker_count = len(active_threads)
|
||||
|
||||
if current_worker_count < max_workers and not file_queue.empty():
|
||||
# 检查CPU使用率(运行5分钟后开始检查)
|
||||
should_add_worker = False
|
||||
if len(cpu_stats["system"]) >= 10: # 至少有5分钟的数据
|
||||
if current_worker_count >= 1: # 已有实例运行
|
||||
should_add_worker = should_increase_instances()
|
||||
if should_add_worker:
|
||||
logging.info("CPU资源充足,启动第二个压缩实例")
|
||||
else:
|
||||
should_add_worker = False
|
||||
|
||||
if should_add_worker:
|
||||
worker_thread = threading.Thread(target=process_file_worker, daemon=True)
|
||||
worker_thread.start()
|
||||
active_threads.append(worker_thread)
|
||||
logging.debug(f"启动新的工作线程,当前活动线程数: {len(active_threads)}")
|
||||
|
||||
threading.Event().wait(5) # 每5秒检查一次
|
||||
|
||||
# 等待所有线程完成
|
||||
for thread in active_threads:
|
||||
thread.join()
|
||||
|
||||
# 启动第一个工作线程
|
||||
if not file_queue.empty():
|
||||
first_worker = threading.Thread(target=process_file_worker, daemon=True)
|
||||
first_worker.start()
|
||||
active_threads.append(first_worker)
|
||||
logging.info("启动第一个压缩实例")
|
||||
|
||||
# 启动线程管理器
|
||||
manager_thread = threading.Thread(target=manage_workers, daemon=True)
|
||||
manager_thread.start()
|
||||
|
||||
# 等待管理线程完成
|
||||
manager_thread.join()
|
||||
|
||||
logging.info(f"所有视频处理完成,共处理了 {completed_files} 个文件")
|
||||
|
||||
def test():
|
||||
os.environ["PATH"] = Path(__file__).parent.as_posix() + os.pathsep + os.environ["PATH"]
|
||||
|
||||
try:
|
||||
subprocess.run([CFG["ffmpeg"],"-version"],stdout=-3,stderr=-3).check_returncode()
|
||||
except KeyboardInterrupt as e:raise e
|
||||
except Exception as e:
|
||||
print(__file__)
|
||||
logging.critical("无法运行ffmpeg")
|
||||
exit(-1)
|
||||
try:
|
||||
ret = subprocess.run(
|
||||
"ffmpeg -hide_banner -f lavfi -i testsrc=duration=1:size=1920x1080:rate=30 -c:v libx264 -y -pix_fmt yuv420p compress_video_test.mp4".split(),
|
||||
f"ffmpeg -hide_banner -f lavfi -i testsrc=duration=1:size={CFG['test_video_resolution']}:rate={CFG['test_video_fps']} -c:v libx264 -y -pix_fmt yuv420p {CFG['test_video_input']}".split(),
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=subprocess.PIPE,
|
||||
text=True
|
||||
@ -394,7 +640,7 @@ def test():
|
||||
logging.debug(ret.stdout)
|
||||
logging.debug(ret.stderr)
|
||||
ret.check_returncode()
|
||||
cmd = get_cmd("compress_video_test.mp4","compressed_video_test.mp4",)
|
||||
cmd = get_cmd(CFG["test_video_input"],CFG["test_video_output"],)
|
||||
ret = subprocess.run(
|
||||
cmd,
|
||||
stdout=subprocess.PIPE,
|
||||
@ -409,6 +655,7 @@ def test():
|
||||
exit(-1)
|
||||
os.remove("compress_video_test.mp4")
|
||||
os.remove("compressed_video_test.mp4")
|
||||
except KeyboardInterrupt as e:raise e
|
||||
except Exception as e:
|
||||
if os.path.exists("compress_video_test.mp4"):
|
||||
os.remove("compress_video_test.mp4")
|
||||
@ -425,6 +672,7 @@ def init_train():
|
||||
# 从文件读取系数
|
||||
coeffs_str = ESTI_FILE.read_text().strip().split(',')
|
||||
esti = [float(coeff) for coeff in coeffs_str]
|
||||
except KeyboardInterrupt as e:raise e
|
||||
except Exception as e:
|
||||
logging.warning(f"预测输出文件{str(ESTI_FILE)}存在但无法读取", exc_info=e)
|
||||
|
||||
@ -449,6 +697,7 @@ def main(_root = None):
|
||||
import json
|
||||
cfg:dict = json.loads(CFG_FILE.read_text())
|
||||
CFG.update(cfg)
|
||||
except KeyboardInterrupt as e:raise e
|
||||
except Exception as e:
|
||||
logging.warning("Invalid config file, ignored.")
|
||||
logging.debug(e)
|
||||
@ -463,7 +712,7 @@ def main(_root = None):
|
||||
sys.exit(1)
|
||||
root = Path(sys.argv[1])
|
||||
|
||||
if root.name == "compress":
|
||||
if root.name.lower() == CFG["compress_dir_name"].lower():
|
||||
logging.critical("请修改目标目录名为非compress。")
|
||||
logging.error("Error termination via invalid input.")
|
||||
sys.exit(1)
|
||||
|
19
changeConnectionLimit/README.md
Normal file
19
changeConnectionLimit/README.md
Normal file
@ -0,0 +1,19 @@
|
||||
# changeConnectionLimit
|
||||
|
||||
修改Windows 10 WiFi热点最大连接终端数的工具。
|
||||
|
||||
## 功能
|
||||
|
||||
通过修改注册表设置和重启相关服务来调整WiFi热点允许连接的设备数量上限。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 以管理员身份运行 `main.bat`
|
||||
2. 根据提示输入期望的最大连接数
|
||||
3. 等待脚本完成注册表修改和服务重启
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 需要管理员权限
|
||||
- 仅适用于Windows系统
|
||||
- 修改后需要重启WiFi热点服务才能生效
|
33
change_font/README.md
Normal file
33
change_font/README.md
Normal file
@ -0,0 +1,33 @@
|
||||
# change_font
|
||||
|
||||
An OCR-powered tool that detects text in images and replaces it with custom fonts.
|
||||
|
||||
说明:用于将已有文档所有手写文字转变为自定义字体,尽量保持文字格式位置不变。
|
||||
|
||||
注意:**只将手写替换,保持印刷体不变。**
|
||||
|
||||
使用好未来(https://ai.100tal.com/)的API,可能需要付费。
|
||||
|
||||
## Description
|
||||
|
||||
This tool uses optical character recognition (OCR) to identify text within images and replaces the detected text with your choice of custom fonts, maintaining the original layout and positioning.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Configure your API credentials in the script
|
||||
2. Place your source images in the designated folder
|
||||
3. Run `python main.py`
|
||||
4. The tool will process images and generate new versions with replaced fonts
|
||||
|
||||
## Requirements
|
||||
|
||||
- Python libraries: opencv, numpy, matplotlib, Pillow
|
||||
- Valid API credentials for the OCR service
|
||||
- Source images to process
|
||||
|
||||
## Setup
|
||||
|
||||
Before running, make sure to:
|
||||
- Install required Python packages
|
||||
- Configure your API credentials in the configuration section
|
||||
- Prepare your input images in the correct format
|
20
conversation_trans/README.md
Normal file
20
conversation_trans/README.md
Normal file
@ -0,0 +1,20 @@
|
||||
# conversation_trans
|
||||
|
||||
将对话数据转换为Markdown格式的工具。
|
||||
|
||||
## 功能
|
||||
|
||||
将Claude AI聊天记录或其他对话JSON数据转换为格式化的Markdown文档,提取思考时间、内容和回复等信息。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 将对话JSON数据放入脚本中
|
||||
2. 运行 `python main.py`
|
||||
3. 程序将生成带有对话标题的Markdown文件
|
||||
|
||||
## 特性
|
||||
|
||||
- 解析消息树结构
|
||||
- 提取思考过程和回复内容
|
||||
- 生成格式化的Markdown输出
|
||||
- 自动生成文件名
|
27
cord/README.md
Normal file
27
cord/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# cord
|
||||
|
||||
化学反应坐标图生成工具。
|
||||
|
||||
## 功能
|
||||
|
||||
创建化学反应的反应坐标图,使用贝塞尔曲线展示反应过程中的能量变化,支持交互式图表显示。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `streamlit run main.py`
|
||||
2. 在网页界面中上传包含反应数据的Excel或CSV文件
|
||||
3. 文件需包含"Name"和"Energy"两列
|
||||
4. 程序将自动生成反应坐标图
|
||||
|
||||
## 数据格式
|
||||
|
||||
- 支持Excel (.xlsx) 和CSV (.csv) 格式
|
||||
- 能量单位:Hartree(程序自动转换为kcal/mol)
|
||||
- 列名:Name(反应物/过渡态/产物名称),Energy(能量值)
|
||||
|
||||
## 特性
|
||||
|
||||
- 交互式Web界面
|
||||
- 自动单位转换
|
||||
- 美观的曲线图表
|
||||
- 支持多步反应
|
26
down/README.md
Normal file
26
down/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# down
|
||||
|
||||
123pan云盘文件下载工具。
|
||||
|
||||
## 功能
|
||||
|
||||
从123pan.com云存储服务下载文件,支持通过分享密钥批量下载,使用多线程下载提高速度。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 在脚本中配置分享密钥
|
||||
2. 运行 `python down.py`
|
||||
3. 程序将自动提取下载链接并使用aria2c进行多线程下载
|
||||
|
||||
## 依赖要求
|
||||
|
||||
- 需要安装aria2c.exe
|
||||
- 需要网络连接
|
||||
- Python requests库
|
||||
|
||||
## 特性
|
||||
|
||||
- 自动解析分享链接
|
||||
- 多线程下载
|
||||
- 支持批量处理
|
||||
- 断点续传支持(通过aria2c)
|
27
encryptFiles/README.md
Normal file
27
encryptFiles/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# encryptFiles
|
||||
|
||||
基于RSA的文件夹加密工具。
|
||||
|
||||
## 功能
|
||||
|
||||
使用RSA算法对整个文件夹进行加密和解密,支持密码保护的私钥,提供并行处理以提高性能。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 首次运行:`python main.py [文件夹路径]` - 将生成RSA密钥对并加密文件夹
|
||||
2. 再次运行:`python main.py [文件夹路径]` - 将解密已加密的文件夹
|
||||
3. 程序会自动在加密和解密模式之间切换
|
||||
|
||||
## 特性
|
||||
|
||||
- RSA加密算法确保安全性
|
||||
- 密码保护的私钥
|
||||
- 并行处理提高速度
|
||||
- 进度条显示处理状态
|
||||
- 自动模式切换(加密/解密)
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 首次使用会在当前目录生成密钥文件
|
||||
- 请妥善保管密钥文件和密码
|
||||
- 加密过程不可逆,请确保有备份
|
26
jw/README.md
Normal file
26
jw/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# jw
|
||||
|
||||
教务系统自动登录工具。
|
||||
|
||||
## 功能
|
||||
|
||||
自动登录学生教务系统,支持验证码自动识别和密码哈希验证,简化教务系统访问流程。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 在代码中配置用户名和密码
|
||||
2. 运行 `python main.py`
|
||||
3. 程序将自动处理登录过程
|
||||
|
||||
## 特性
|
||||
|
||||
- 自动验证码识别
|
||||
- 密码安全哈希处理
|
||||
- 会话管理
|
||||
- 错误重试机制
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 需要配置正确的用户凭据
|
||||
- 仅用于合法的教务系统访问
|
||||
- 请遵守学校相关规定
|
71
jw/main.py
Normal file
71
jw/main.py
Normal file
@ -0,0 +1,71 @@
|
||||
import hashlib
|
||||
import requests
|
||||
import re
|
||||
import json
|
||||
import base64
|
||||
import tenacity as retry
|
||||
|
||||
def recapture(username, password, b64, ID):
|
||||
data = {"username": username, "password": password, "ID": ID, "b64": b64, "version": "3.1.1"}
|
||||
data_json = json.dumps(data)
|
||||
result = json.loads(requests.post("http://www.fdyscloud.com.cn/tuling/predict", data=data_json).text)
|
||||
return result
|
||||
|
||||
|
||||
def pwd_md5(string: str) -> str:
|
||||
md5_part1 = hashlib.md5((string + "{Urp602019}").encode()).hexdigest().lower()
|
||||
md5_part2 = hashlib.md5(string.encode()).hexdigest().lower()
|
||||
final_result = md5_part1 + '*' + md5_part2
|
||||
return final_result
|
||||
|
||||
@retry.retry(stop=retry.stop_after_attempt(3), wait=retry.wait_random(3,5),reraise=True)
|
||||
def login(username: str, password: str) -> requests.Session:
|
||||
print("正在登录...")
|
||||
session = requests.Session()
|
||||
|
||||
req = session.get("http://jwstudent.lnu.edu.cn/login")
|
||||
req.raise_for_status()
|
||||
html = req.text
|
||||
match = re.search(r'name="tokenValue" value="(.+?)">', html)
|
||||
if match:
|
||||
token_value = match.group(1)
|
||||
else:
|
||||
raise ValueError("未找到 tokenValue")
|
||||
|
||||
req = session.get("http://jwstudent.lnu.edu.cn/img/captcha.jpg")
|
||||
req.raise_for_status()
|
||||
im = req.content
|
||||
b64 = base64.b64encode(im).decode('utf-8')
|
||||
captcha_code = recapture(username="fbcfbc6", password="b0qDHNSSg5LxBRzO3hfpbTE5", b64=b64, ID="04897896")["data"]["result"]
|
||||
with open("captcha.jpg", "wb") as f:
|
||||
f.write(im)
|
||||
print(captcha_code)
|
||||
|
||||
hashed_password = pwd_md5(password)
|
||||
|
||||
# 模拟请求的 payload
|
||||
payload = {
|
||||
"j_username": username,
|
||||
"j_password": hashed_password,
|
||||
"j_captcha": captcha_code,
|
||||
"tokenValue": token_value
|
||||
}
|
||||
|
||||
# 发送 POST 请求
|
||||
url = "http://jwstudent.lnu.edu.cn/j_spring_security_check" # 替换为实际登录地址
|
||||
headers = {
|
||||
"User-Agent": "Mozilla/5.0",
|
||||
"Content-Type": "application/x-www-form-urlencoded"
|
||||
}
|
||||
response = session.post(url, data=payload, headers=headers)
|
||||
|
||||
if "发生错误" in response.text:
|
||||
err = re.search(r'<strong>发生错误!</strong>(.+)', response.text)
|
||||
if err:
|
||||
error_message = err.group(1).strip()
|
||||
raise ValueError(f"登录失败: {error_message}")
|
||||
raise ValueError("登录失败")
|
||||
return session
|
||||
|
||||
|
||||
print(login("20211299305", "123"))
|
@ -13,8 +13,8 @@ from Crypto.Util.Padding import pad
|
||||
from base64 import b64encode
|
||||
|
||||
URL = "http://[your libseat url]"
|
||||
UID = "[uid]" # 图书馆账号
|
||||
PWD = "[password]" # 图书馆密码
|
||||
# UID = "[uid]" # 图书馆账号
|
||||
PWD = "000000" # 图书馆密码
|
||||
USERNAME = "[username]" # 验证码平台用户名
|
||||
PASSWORD = "[password]" # 验证码平台密码
|
||||
TOKEN = "[token]"
|
||||
@ -171,8 +171,8 @@ def main(dep=0):
|
||||
print("正在尝试登录...")
|
||||
tried =0
|
||||
while token is None and tried <= 5:
|
||||
id = UID
|
||||
# id = str(random.choice(years)) + random.choice(house) + str(random.choice(classes)) + str(random.choice(num)).zfill(2)
|
||||
# id = UID
|
||||
id = str(random.choice(years)) + random.choice(house) + str(random.choice(classes)) + str(random.choice(num)).zfill(2)
|
||||
token = login(id,PWD)
|
||||
if token is None:
|
||||
print("登陆失败:",token)
|
||||
|
27
move_warn/README.md
Normal file
27
move_warn/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# move_warn
|
||||
|
||||
运动检测监控工具。
|
||||
|
||||
## 功能
|
||||
|
||||
监控IP摄像头画面,当检测到显著运动时触发声音警报,适用于简单的安防监控需求。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 确保IP摄像头正常工作并可访问
|
||||
2. 在代码中配置摄像头IP地址
|
||||
3. 运行 `python main.py`
|
||||
4. 程序将开始监控,检测到运动时发出警报并自动关闭
|
||||
|
||||
## 特性
|
||||
|
||||
- 实时运动检测
|
||||
- 声音警报提示
|
||||
- 自动程序终止
|
||||
- 基于OpenCV的计算机视觉处理
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 需要配置正确的摄像头地址
|
||||
- 确保摄像头网络连接稳定
|
||||
- 检测灵敏度可根据需要调整
|
32
mult/README.md
Normal file
32
mult/README.md
Normal file
@ -0,0 +1,32 @@
|
||||
# mult
|
||||
|
||||
批量视频处理工具。
|
||||
|
||||
## 功能
|
||||
|
||||
使用auto-editor和FFmpeg对多个MP4/FLV视频文件进行批量处理,自动去除静音片段并转码视频,支持并行处理提高效率。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 将要处理的视频文件放在程序目录中
|
||||
2. 运行 `python main.py`(CPU处理)或 `python main_up.py`(GPU加速)
|
||||
3. 程序将自动处理所有视频文件
|
||||
|
||||
## 支持格式
|
||||
|
||||
- MP4
|
||||
- FLV
|
||||
|
||||
## 特性
|
||||
|
||||
- 批量视频处理
|
||||
- 自动静音片段移除
|
||||
- 并行处理支持
|
||||
- GPU硬件加速支持(main_up.py)
|
||||
- 进程池管理
|
||||
|
||||
## 依赖要求
|
||||
|
||||
- FFmpeg
|
||||
- auto-editor
|
||||
- 足够的磁盘空间用于输出文件
|
30
mw_tool/README.md
Normal file
30
mw_tool/README.md
Normal file
@ -0,0 +1,30 @@
|
||||
# mw_tool
|
||||
|
||||
化学计算与化合物查询工具。
|
||||
|
||||
## 功能
|
||||
|
||||
基于Web界面的化学工具,提供PubChem数据库集成的化合物搜索、分子量计算和反应化学计量计算功能。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `streamlit run main.py`
|
||||
2. 在浏览器中访问显示的本地网址
|
||||
3. 使用各项功能:
|
||||
- 化合物搜索和信息查询
|
||||
- 分子量计算
|
||||
- 反应化学计量计算
|
||||
|
||||
## 主要功能
|
||||
|
||||
- **化合物查询**:通过PubChem数据库搜索化合物信息
|
||||
- **分子量计算**:计算化学式的分子量
|
||||
- **化学计量学**:反应平衡计算和摩尔比计算
|
||||
- **交互式表格**:数据以表格形式展示,便于查看
|
||||
|
||||
## 特性
|
||||
|
||||
- 友好的Web界面
|
||||
- 实时数据库查询
|
||||
- 多功能集成平台
|
||||
- 数据表格化展示
|
31
pdf_unlock/README.md
Normal file
31
pdf_unlock/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
# pdf_unlock
|
||||
|
||||
PDF限制移除工具。
|
||||
|
||||
## 功能
|
||||
|
||||
移除PDF文件的访问限制,通过重新创建不带加密和访问限制的PDF副本来解除文件保护。
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 命令行使用
|
||||
```bash
|
||||
python main.py <输入文件或目录>
|
||||
```
|
||||
|
||||
### 拖拽使用
|
||||
将PDF文件或包含PDF文件的文件夹直接拖拽到程序上。
|
||||
|
||||
## 特性
|
||||
|
||||
- 支持单个文件和批量处理
|
||||
- 移除密码保护
|
||||
- 移除复制/打印限制
|
||||
- 保持原始文件质量
|
||||
- 自动输出到指定目录
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 仅用于合法拥有的PDF文件
|
||||
- 请遵守版权法规
|
||||
- 原始文件保持不变,生成新的无限制副本
|
26
pinyin/README.md
Normal file
26
pinyin/README.md
Normal file
@ -0,0 +1,26 @@
|
||||
# pinyin
|
||||
|
||||
中文姓名拼音首字母转换器。
|
||||
|
||||
## 功能
|
||||
|
||||
将中文姓名转换为拼音首字母,处理预设的中文姓名列表并输出每个字符拼音的首字母。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `python gen.py`
|
||||
2. 程序将处理内置的中文姓名列表
|
||||
3. 输出每个姓名对应的拼音首字母
|
||||
|
||||
## 特性
|
||||
|
||||
- 中文转拼音处理
|
||||
- 首字母提取
|
||||
- 批量姓名处理
|
||||
- 简洁输出格式
|
||||
|
||||
## 应用场景
|
||||
|
||||
- 姓名索引生成
|
||||
- 拼音首字母排序
|
||||
- 中文姓名处理工具
|
34
process_video/README.md
Normal file
34
process_video/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# process_video
|
||||
|
||||
视频时长调整工具。
|
||||
|
||||
## 功能
|
||||
|
||||
使用FFmpeg调整视频播放速度以达到目标时长,支持加速或减速处理,同时保持视频质量。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 编译C++程序(如果尚未编译)
|
||||
2. 运行可执行文件
|
||||
3. 按提示输入:
|
||||
- 源视频文件路径
|
||||
- 目标时长
|
||||
- 输出文件名
|
||||
|
||||
## 特性
|
||||
|
||||
- 精确时长控制
|
||||
- 自动速度计算
|
||||
- 质量保持优化
|
||||
- 交互式操作界面
|
||||
|
||||
## 依赖要求
|
||||
|
||||
- FFmpeg和FFprobe需要安装并在系统PATH中
|
||||
- C++编译器(用于编译源代码)
|
||||
|
||||
## 应用场景
|
||||
|
||||
- 视频时长标准化
|
||||
- 网课视频调速
|
||||
- 媒体内容适配
|
30
rand/README.md
Normal file
30
rand/README.md
Normal file
@ -0,0 +1,30 @@
|
||||
# rand
|
||||
|
||||
交互式随机数生成器。
|
||||
|
||||
## 功能
|
||||
|
||||
生成指定范围内的随机整数列表,支持设置是否允许重复数字,提供交互式操作界面。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `python main.py`
|
||||
2. 按照提示输入:
|
||||
- 随机数的数量
|
||||
- 数字范围(最小值和最大值)
|
||||
- 是否允许重复数字
|
||||
3. 程序将生成并显示随机数列表
|
||||
|
||||
## 特性
|
||||
|
||||
- 交互式用户界面
|
||||
- 可配置数字范围
|
||||
- 重复数字控制选项
|
||||
- 即时结果显示
|
||||
|
||||
## 应用场景
|
||||
|
||||
- 抽奖号码生成
|
||||
- 随机抽样
|
||||
- 测试数据生成
|
||||
- 游戏数字生成
|
36
recode/README.md
Normal file
36
recode/README.md
Normal file
@ -0,0 +1,36 @@
|
||||
# recode
|
||||
|
||||
文件编码转换器。
|
||||
|
||||
## 功能
|
||||
|
||||
检测并转换文本文件的字符编码格式,支持UTF-8、GBK、GB2312等80多种编码格式之间的相互转换。
|
||||
|
||||
## 使用方法
|
||||
|
||||
```bash
|
||||
python recode.py [选项] 文件名(们)
|
||||
```
|
||||
|
||||
## 参数选项
|
||||
|
||||
- `-i` : 指定输入编码格式
|
||||
- `-o` : 指定输出编码格式(默认:utf-8)
|
||||
- `-c` : 测试特定编码格式
|
||||
- `-r` : 输出目录(默认:"out")
|
||||
- `-s` : 显示所有支持的编码格式
|
||||
|
||||
## 支持的编码
|
||||
|
||||
支持80多种字符编码,包括:
|
||||
- UTF-8, UTF-16, UTF-32
|
||||
- GBK, GB2312, GB18030
|
||||
- Big5, ASCII
|
||||
- 各种ISO标准编码等
|
||||
|
||||
## 特性
|
||||
|
||||
- 自动编码检测
|
||||
- 批量文件处理
|
||||
- 广泛的编码支持
|
||||
- 灵活的输出配置
|
33
seat_map/README.md
Normal file
33
seat_map/README.md
Normal file
@ -0,0 +1,33 @@
|
||||
# seat_map
|
||||
|
||||
课堂座位表生成器。
|
||||
|
||||
## 功能
|
||||
|
||||
从二进制数据文件读取座位信息,生成8x6的教室座位安排表,并导出为CSV格式,支持座位轮换逻辑。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 准备座位数据文件 `seat.dat`
|
||||
2. 运行 `python main.py`
|
||||
3. 程序将生成 `seat.csv` 座位表文件
|
||||
|
||||
## 输出格式
|
||||
|
||||
- 8行6列的座位表
|
||||
- CSV格式便于查看和打印
|
||||
- 包含学生姓名信息
|
||||
- 支持座位轮换算法
|
||||
|
||||
## 特性
|
||||
|
||||
- 自动座位分配
|
||||
- 轮换逻辑支持
|
||||
- CSV格式输出
|
||||
- 预设学生名单(48人)
|
||||
|
||||
## 应用场景
|
||||
|
||||
- 课堂座位安排
|
||||
- 考试座位分配
|
||||
- 活动座位管理
|
31
task_assignment/README.md
Normal file
31
task_assignment/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
# task_assignment
|
||||
|
||||
任务分配管理系统。
|
||||
|
||||
## 功能
|
||||
|
||||
基于Web的任务分配管理系统,用户可以表达对任务的偏好,系统自动根据可用性进行任务分配并处理冲突。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `python app.py`
|
||||
2. 在浏览器中访问显示的本地地址
|
||||
3. 使用Web界面进行任务管理:
|
||||
- 配置任务列表
|
||||
- 收集用户意向
|
||||
- 查看自动分配结果
|
||||
|
||||
## 主要功能
|
||||
|
||||
- **任务配置**:设置可分配的任务列表
|
||||
- **意向收集**:用户表达任务偏好
|
||||
- **自动分配**:基于可用性和偏好的智能分配
|
||||
- **冲突处理**:处理任务分配冲突
|
||||
- **结果展示**:清晰显示分配结果
|
||||
|
||||
## 特性
|
||||
|
||||
- 友好的Web界面
|
||||
- 自动化分配算法
|
||||
- 冲突解决机制
|
||||
- 实时结果显示
|
31
video/README.md
Normal file
31
video/README.md
Normal file
@ -0,0 +1,31 @@
|
||||
# video
|
||||
|
||||
视频剪切工具。
|
||||
|
||||
## 功能
|
||||
|
||||
使用FFmpeg进行简单的视频剪切,根据用户指定的开始和结束时间提取视频片段,支持无损剪切。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `python cut.py <视频文件>`
|
||||
2. 根据提示输入开始时间(格式:HH:MM:SS)
|
||||
3. 输入结束时间(格式:HH:MM:SS)
|
||||
4. 程序将生成剪切后的视频文件
|
||||
|
||||
## 特性
|
||||
|
||||
- 无损视频剪切
|
||||
- 简单时间区间指定
|
||||
- 快速处理速度
|
||||
- 保持原始视频质量
|
||||
|
||||
## 依赖要求
|
||||
|
||||
需要在指定路径安装FFmpeg:
|
||||
`E:\green\ffmpeg\bin\ffmpeg.exe`
|
||||
|
||||
## 时间格式
|
||||
|
||||
输入时间使用标准格式:`小时:分钟:秒`
|
||||
例如:`00:01:30`(1分30秒)
|
27
wjx/README.md
Normal file
27
wjx/README.md
Normal file
@ -0,0 +1,27 @@
|
||||
# wjx
|
||||
|
||||
问卷星数据抓取工具。
|
||||
|
||||
## 功能
|
||||
|
||||
自动登录问卷星(WJX.cn)平台,获取调查问卷的回复数据,支持会话管理和CSRF令牌处理。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 在 `main.py` 中配置登录凭据
|
||||
2. 运行 `python main.py`
|
||||
3. 程序将自动登录并提取问卷数据
|
||||
|
||||
## 特性
|
||||
|
||||
- 自动登录处理
|
||||
- 会话管理
|
||||
- CSRF令牌自动处理
|
||||
- 调查数据提取
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 需要有效的问卷星账户
|
||||
- 请遵守平台使用条款
|
||||
- 建议将凭据信息外部化配置
|
||||
- 仅用于合法的数据获取
|
34
zxxk_dl/README.md
Normal file
34
zxxk_dl/README.md
Normal file
@ -0,0 +1,34 @@
|
||||
# zxxk_dl
|
||||
|
||||
学科网资源下载工具。
|
||||
|
||||
## 功能
|
||||
|
||||
下载学科网(ZXXK.com)的教育资源,将内容转换为本地HTML文件,支持处理单个文件和RAR压缩包。
|
||||
|
||||
## 使用方法
|
||||
|
||||
1. 运行 `python main.py`
|
||||
2. 根据提示输入软件ID
|
||||
3. 程序将自动下载并转换资源为HTML格式
|
||||
4. 支持连续处理多个资源
|
||||
|
||||
## 特性
|
||||
|
||||
- JSON API交互
|
||||
- 图片URL提取
|
||||
- HTML格式化处理
|
||||
- 自动文件命名(基于哈希值确保唯一性)
|
||||
- 支持RAR压缩包处理
|
||||
- 连续批量处理
|
||||
|
||||
## 输出格式
|
||||
|
||||
- 本地HTML文件
|
||||
- 保持原始内容结构
|
||||
- 便于离线查看和打印
|
||||
|
||||
## 注意事项
|
||||
|
||||
- 请遵守网站使用条款
|
||||
- 仅用于合法的教育资源获取
|
Reference in New Issue
Block a user