Initial commit: skills library
- 70 skills with code and documentation - Add .gitignore (ignore __pycache__, output/, temp/, venv/) - Clean up test intermediates and caches
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
#!/usr/bin/env python3
|
||||
"""
|
||||
乐谱下载器主脚本
|
||||
支持从人人钢琴网等网站下载高质量乐谱
|
||||
自动识别高清版本并清理低质量文件
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import requests
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
|
||||
|
||||
def download_sheet_music(song_name, output_dir=None, quality_threshold=50000):
|
||||
"""
|
||||
下载乐谱的主函数
|
||||
|
||||
Args:
|
||||
song_name: 歌曲名称(用于搜索)
|
||||
output_dir: 输出目录
|
||||
quality_threshold: 文件大小阈值(字节),小于该值的文件将被删除
|
||||
"""
|
||||
if output_dir is None:
|
||||
output_dir = f"{song_name}_sheet_music"
|
||||
|
||||
# 创建输出目录
|
||||
Path(output_dir).mkdir(exist_ok=True)
|
||||
|
||||
# 人人钢琴网的URL模式
|
||||
base_url = "https://www.everyonepiano.cn"
|
||||
search_url = f"{base_url}/Music-search/?word={song_name}"
|
||||
|
||||
print(f"正在搜索: {song_name}")
|
||||
print(f"搜索URL: {search_url}")
|
||||
|
||||
# 这里需要实现实际的搜索和解析逻辑
|
||||
# 由于网页结构复杂,建议使用playwright或selenium
|
||||
# 当前版本提供基础框架
|
||||
|
||||
return output_dir
|
||||
|
||||
|
||||
def cleanup_low_quality_files(directory, threshold=50000):
|
||||
"""
|
||||
清理低质量的小文件
|
||||
|
||||
Args:
|
||||
directory: 目录路径
|
||||
threshold: 文件大小阈值(字节)
|
||||
"""
|
||||
deleted_count = 0
|
||||
for file_path in Path(directory).glob("*"):
|
||||
if file_path.is_file() and file_path.stat().st_size < threshold:
|
||||
print(
|
||||
f"删除低质量文件: {file_path.name} ({file_path.stat().st_size} bytes)"
|
||||
)
|
||||
file_path.unlink()
|
||||
deleted_count += 1
|
||||
|
||||
print(f"共删除 {deleted_count} 个低质量文件")
|
||||
return deleted_count
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="乐谱下载器")
|
||||
parser.add_argument("song_name", help="歌曲名称")
|
||||
parser.add_argument("--output", "-o", default=None, help="输出目录")
|
||||
parser.add_argument(
|
||||
"--threshold", "-t", type=int, default=50000, help="文件大小阈值(字节)"
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
output_dir = download_sheet_music(args.song_name, args.output, args.threshold)
|
||||
cleanup_low_quality_files(output_dir, args.threshold)
|
||||
print(f"乐谱已保存到: {output_dir}")
|
||||
except Exception as e:
|
||||
print(f"错误: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user