Update:更新了一些小脚本
This commit is contained in:
@@ -7,7 +7,7 @@ from requests.adapters import HTTPAdapter
|
||||
from urllib3.util.retry import Retry
|
||||
|
||||
# 配置
|
||||
url = "https://unpkg.ovofish.com/"
|
||||
url = "https://unpkg.com/"
|
||||
headers = {
|
||||
'Accept-Language': 'zh-CN,zh;q=0.8',
|
||||
'Content-Type': 'text/html; Charset=utf-8',
|
||||
@@ -123,8 +123,8 @@ else:
|
||||
use_proxy = input("是否使用代理?(输入 'y' 或 'n'): ").lower()
|
||||
if use_proxy == 'y':
|
||||
# 获取代理设置
|
||||
default_proxy_host = "10.10.50.210" # 设置默认代理主机
|
||||
default_proxy_port = 65115 # 设置默认代理端口
|
||||
default_proxy_host = "10.10.50.65" # 设置默认代理主机
|
||||
default_proxy_port = 7897 # 设置默认代理端口
|
||||
|
||||
proxy_host = input(f"请输入代理主机 (默认为 {default_proxy_host}): ") or default_proxy_host
|
||||
proxy_port = int(input(f"请输入代理端口 (默认为 {default_proxy_port}): ") or default_proxy_port)
|
||||
|
||||
13
Python/wav_flac_music/Readme.md
Normal file
13
Python/wav_flac_music/Readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
<div align="center">
|
||||
<img height="100px" alt="logo" src="https://img-bohe.lolicon.team/i/img/svg/logo.ico"/>
|
||||
<p><em>🗂️OVOFISH STUDIO</em></p>
|
||||
|
||||
# 说明
|
||||
|
||||
这是一个自动化音频转换格式的脚本
|
||||
因为wav格式不支持内部歌词数据所以要转为flac格式
|
||||
运行前请先安装依赖库
|
||||
|
||||
```
|
||||
pip install pydub mutagen eyed3
|
||||
```
|
||||
71
Python/wav_flac_music/main.py
Normal file
71
Python/wav_flac_music/main.py
Normal file
@@ -0,0 +1,71 @@
|
||||
import os
|
||||
from pydub import AudioSegment
|
||||
import eyed3
|
||||
from mutagen.flac import FLAC
|
||||
|
||||
def convert_and_clean(wav_path):
|
||||
try:
|
||||
# 增强版元数据读取
|
||||
tags = {}
|
||||
audiofile = eyed3.load(wav_path)
|
||||
|
||||
# 处理无标签文件
|
||||
if audiofile is not None and audiofile.tag is not None:
|
||||
tags = {
|
||||
'ARTIST': audiofile.tag.artist or '',
|
||||
'ALBUM': audiofile.tag.album or '',
|
||||
'TITLE': audiofile.tag.title or '',
|
||||
'GENRE': audiofile.tag.genre.name if audiofile.tag.genre else '',
|
||||
'DATE': str(audiofile.tag.getBestDate()) or '',
|
||||
'TRACKNUMBER': str(audiofile.tag.track_num[0]) if audiofile.tag.track_num else ''
|
||||
}
|
||||
else:
|
||||
# 从文件名提取基础信息
|
||||
filename = os.path.basename(wav_path)
|
||||
base_info = os.path.splitext(filename)[0].split('-', 1)
|
||||
if len(base_info) > 1:
|
||||
tags['ARTIST'] = base_info[0].strip()
|
||||
tags['TITLE'] = base_info[1].strip()
|
||||
|
||||
# 转换音频格式
|
||||
flac_path = os.path.splitext(wav_path)[0] + '.flac'
|
||||
AudioSegment.from_wav(wav_path).export(flac_path, format='flac')
|
||||
|
||||
# 写入FLAC元数据
|
||||
if tags:
|
||||
flac_audio = FLAC(flac_path)
|
||||
flac_audio.delete()
|
||||
flac_audio.update(tags)
|
||||
flac_audio.save()
|
||||
|
||||
# 安全删除验证
|
||||
if os.path.exists(flac_path) and os.path.getsize(flac_path) > 0:
|
||||
os.remove(wav_path)
|
||||
print(f"成功转换并删除: {wav_path}")
|
||||
return True
|
||||
return False
|
||||
|
||||
except Exception as e:
|
||||
print(f"处理失败 {wav_path}: {str(e)}")
|
||||
if 'flac_path' in locals() and os.path.exists(flac_path):
|
||||
os.remove(flac_path)
|
||||
return False
|
||||
|
||||
def batch_convert():
|
||||
deleted_count = 0
|
||||
error_count = 0
|
||||
|
||||
for root, _, files in os.walk('.'):
|
||||
for file in files:
|
||||
if file.lower().endswith('.wav'):
|
||||
full_path = os.path.join(root, file)
|
||||
if convert_and_clean(full_path):
|
||||
deleted_count += 1
|
||||
else:
|
||||
error_count += 1
|
||||
|
||||
print(f"\n转换总结:\n成功转换并删除: {deleted_count} 个文件\n失败文件: {error_count} 个")
|
||||
|
||||
if __name__ == "__main__":
|
||||
print("=== WAV转FLAC工具 (增强安全版) ===")
|
||||
batch_convert()
|
||||
Reference in New Issue
Block a user