吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1102|回复: 50
上一主题 下一主题
收起左侧

[Python 转载] 网易云缓存.UC!文件转.mp3

  [复制链接]
跳转到指定楼层
楼主
矢岛舞美 发表于 2024-4-13 10:41 回帖奖励
在原帖的基础上进行了一些优化,使用更便捷了!https://www.52pojie.cn/thread-1560121-1-1.html
起因是发现一首网易云收藏的歌居然和昨天听到的不一样了,于是想到从缓存文件提取原歌曲,搜索引擎找了半天还是吾爱的靠谱。
转换界面截图:

成品链接:https://www.123pan.com/s/TKR5Vv-rfr5v.html提取码:7AjK


源码:
[Python] 纯文本查看 复制代码
import os
import tkinter as tk
from tkinter import filedialog
from tkinter.scrolledtext import ScrolledText
import threading

def getAllFiles(path):
    # 返回指定目录下的所有文件名
    return [os.path.join(path, f) for f in os.listdir(path) if os.path.isfile(os.path.join(path, f))]

def isUcExtension(file):
    # 判断是否是.uc文件
    return file.endswith('.uc!')


def ucToFlac(file, output_dir):
    # 将指定文件按字节与0xA3进行异或,并对文件格式进行修改
    with open(file, 'rb') as fSource:
        content = bytearray(fSource.read())
    for index in range(len(content)):
        content[index] ^= 0xA3

    # 确保输出文件名正确处理,只保留一个.mp3后缀
    # 先移除".uc!"后缀,然后检查并处理重复的.mp3后缀
    output_file_base = file[:-4]  # 移除".uc!"后缀
    if output_file_base.endswith('.mp3'):
        output_file_name = output_file_base  # 已经是.mp3结尾,无需改动
    else:
        output_file_name = output_file_base + '.mp3'  # 添加.mp3后缀

    output_file = os.path.join(output_dir, os.path.basename(output_file_name))
    with open(output_file, 'wb') as fOut:
        fOut.write(content)
    return output_file

def convertFilesThread(input_dir, output_dir):
    if not os.path.isdir(input_dir) or not os.path.isdir(output_dir):
        logMessage("错误: 输入或输出目录无效\n")
        return
    files = getAllFiles(input_dir)
    for file in files:
        if isUcExtension(file):
            output_file = ucToFlac(file, output_dir)
            logMessage(os.path.basename(output_file) + ' 转换成功\n')

def convertFiles():
    input_dir = input_dir_entry.get()
    output_dir = output_dir_entry.get()
    # 创建并启动一个新线程来执行耗时的转换任务
    threading.Thread(target=convertFilesThread, args=(input_dir, output_dir)).start()

def selectInputDir():
    dirname = filedialog.askdirectory()
    if dirname:
        input_dir_entry.delete(0, tk.END)
        input_dir_entry.insert(0, dirname)

def selectOutputDir():
    dirname = filedialog.askdirectory()
    if dirname:
        output_dir_entry.delete(0, tk.END)
        output_dir_entry.insert(0, dirname)

def logMessage(message):
    # 在文本框中显示信息
    if log_text:
        log_text.config(state=tk.NORMAL)
        log_text.insert(tk.END, message)
        log_text.config(state=tk.DISABLED)
        log_text.see(tk.END)

# 创建GUI界面
root = tk.Tk()
root.title("UC文件转MP3工具")

# 使用grid布局
tk.Label(root, text="输入目录:").grid(row=0, column=0, sticky='e')
input_dir_entry = tk.Entry(root, width=50)
input_dir_entry.grid(row=0, column=1)
tk.Button(root, text="选择", command=selectInputDir).grid(row=0, column=2)

tk.Label(root, text="输出目录:").grid(row=1, column=0, sticky='e')
output_dir_entry = tk.Entry(root, width=50)
output_dir_entry.grid(row=1, column=1)
tk.Button(root, text="选择", command=selectOutputDir).grid(row=1, column=2)

tk.Button(root, text="开始转换", command=convertFiles).grid(row=2, column=0, columnspan=3)

# 增加一个ScrolledText组件来显示转换日志
log_text = ScrolledText(root, height=10)
log_text.grid(row=3, column=0, columnspan=3, sticky='nsew')

# 配置行列权重,确保GUI元素在窗口调整大小时表现良好
root.grid_rowconfigure(3, weight=1)
root.grid_columnconfigure(1, weight=1)

root.mainloop()

免费评分

参与人数 5吾爱币 +4 热心值 +5 收起 理由
yeechou + 1 + 1 鼓励转贴优秀软件安全工具和文档!
kylee + 1 + 1 我很赞同!
我是一个外星人 + 1 + 1 用心讨论,共获提升!
yanglinman + 1 谢谢@Thanks!
内瑟斯 + 1 + 1 谢谢@Thanks!

查看全部评分

本帖被以下淘专辑推荐:

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

推荐
78zhanghao87 发表于 2024-4-13 15:12
看懂了,核心代码就是def ucToFlac(file, output_dir):
    # 将指定文件按字节与0xA3进行异或,并对文件格式进行修改
    with open(file, 'rb') as fSource:
        content = bytearray(fSource.read())
    for index in range(len(content)):
        content[index] ^= 0xA3
推荐
tupaly5 发表于 2024-4-13 10:58
3#
青春莫相随 发表于 2024-4-13 11:02
4#
27149 发表于 2024-4-13 11:05
感谢楼主分享成品!
5#
hhlxxl 发表于 2024-4-13 11:10
先收藏备用
6#
shiqiangge 发表于 2024-4-13 11:18
https://www.52pojie.cn/thread-1560121-1-1.html
这是楼主贴子里的地址,赞一个
7#
dingqh 发表于 2024-4-13 11:44
我要给你一个大大的赞
8#
策士 发表于 2024-4-13 11:46
无法启动此程序,因为计算机中丢失 api-ms-win-core-path-l1-1-0.dll娄试重新安装该程序以解决此间题
9#
ningmi370 发表于 2024-4-13 11:48
本帖最后由 ningmi370 于 2024-4-13 12:24 编辑

感谢分享~~~~
10#
Charlotte0 发表于 2024-4-13 11:49
感谢分享,谢谢大大
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-30 23:01

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表