Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

已经无法使用,win11,以前使用好使,今天用了没任何反应了,只是直接跳到继续选择1或者2,而没有任何转换出的文件 #42

Open
Bob8852 opened this issue Aug 27, 2024 · 2 comments

Comments

@Bob8852
Copy link

Bob8852 commented Aug 27, 2024

No description provided.

@HousenWang
Copy link

HousenWang commented Sep 22, 2024

def select_file():
    root = tk.Tk()
    root.withdraw()
    file_path = filedialog.askopenfilename()
    root.destroy()
    return file_path


def select_directory():
    root = tk.Tk()
    root.withdraw()
    directory_path = filedialog.askdirectory()
    root.destroy()
    return directory_path

大佬好,上述这两个函数单独放在一个test.py文件中测试时可以弹出目录选择窗口,但是在main.py中无法正常使用。

环境为win11,python版本为3.8。

@HousenWang
Copy link

def get_xm_files(directory_path):
    """
    输入一个文件夹地址,返回该文件夹下所有 .xm 文件的路径列表
    """
    if not os.path.isdir(directory_path):
        raise ValueError(f"{directory_path} 不是一个有效的文件夹路径")
    
    # 使用glob.glob查找所有扩展名为 .xm 的文件
    xm_files = glob.glob(os.path.join(directory_path, "*.xm"))
    
    return xm_files

@Bob8852 要是急的话,可以将上面的函数放到main.py文件中,然后将源代码

if __name__ == "__main__":
    while True:
        print("欢迎使用喜马拉雅音频解密工具")
        print("本工具仅供学习交流使用,严禁用于商业用途")
        print("请选择您想要使用的功能:")
        print("1. 解密单个文件")
        print("2. 批量解密文件")
        print("3. 退出")
        choice = input()
        if choice == "1" or choice == "2":
            if choice == "1":
                files_to_decrypt = [select_file()]
                if files_to_decrypt == [""]:
                    print("检测到文件选择窗口被关闭")
                    continue
            elif choice == "2":
                dir_to_decrypt = select_directory()
                if dir_to_decrypt == "":
                    print("检测到目录选择窗口被关闭")
                    continue
                files_to_decrypt = glob.glob(os.path.join(dir_to_decrypt, "*.xm"))
            print("请选择是否需要设置输出路径:(不设置默认为本程序目录下的output文件夹)")
            print("1. 设置输出路径")
            print("2. 不设置输出路径")
            choice = input()
            if choice == "1":
                output_path = select_directory()
                if output_path == "":
                    print("检测到目录选择窗口被关闭")
                    continue
            elif choice == "2":
                output_path = "./output"
            for file in files_to_decrypt:
                decrypt_xm_file(file, output_path)
        elif choice == "3":
            sys.exit()
        else:
            print("输入错误,请重新输入!")

替换为

if __name__ == "__main__":
    while True:
        print("欢迎使用喜马拉雅音频解密工具")
        print("本工具仅供学习交流使用,严禁用于商业用途")
        print("请选择您想要使用的功能:")
        print("1. 解密单个文件")
        print("2. 批量解密文件")
        print("3. 退出")
        choice = input()
        if choice == "1" or choice == "2":
            folder_path = input('输入文件所在文件夹地址:')
            files_to_decrypt = get_xm_files(rf'{folder_path}')
            print("请选择是否需要设置输出路径:(不设置默认为本程序目录下的output文件夹)")
            print("1. 设置输出路径")
            print("2. 不设置输出路径")
            choice = input()
            if choice == "1":
                folder_path = input("请设置输出路径: ")
                output_path = folder_path.replace("\\", "/")
            elif choice == "2":
                output_path = "./output"
            for file in files_to_decrypt:
                decrypt_xm_file(file, output_path)
        elif choice == "3":
            sys.exit()
        else:
            print("输入错误,请重新输入!")

手动输入xm文件所在文件夹的路径,这样就可以正常解密了。
希望可以帮到你!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants