Skip to content

Commit

Permalink
Merge pull request #19 from Diaoxiaozhang:develop
Browse files Browse the repository at this point in the history
feat: selct file/directory with gui
  • Loading branch information
Diaoxiaozhang committed Mar 24, 2024
2 parents 7c5d3bc + 920b61f commit 2dc0aa3
Showing 1 changed file with 29 additions and 39 deletions.
68 changes: 29 additions & 39 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import os
import glob
import mutagen
import tkinter as tk
from tkinter import filedialog
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from mutagen.easyid3 import ID3
Expand Down Expand Up @@ -166,6 +168,22 @@ def replace_invalid_chars(name):
return name


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


if __name__ == "__main__":
while True:
print("欢迎使用喜马拉雅音频解密工具")
Expand All @@ -177,46 +195,18 @@ def replace_invalid_chars(name):
choice = input()
if choice == "1" or choice == "2":
if choice == "1":
while True:
print("请输入需要解密的文件路径:")
file_to_decrypt = input()
if not os.path.exists(file_to_decrypt):
print("您输入文件不存在,请重新输入!")
elif not os.path.isfile(file_to_decrypt):
print("您输入的不是一个合法的文件目录,请重新输入!")
else:
files_to_decrypt = [file_to_decrypt]
break
files_to_decrypt = [select_file()]
elif choice == "2":
dir_to_decrypt = select_directory()
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()
elif choice == "2":
while True:
print("请输入包含需要解密的文件的文件夹路径:")
dir_to_decrypt = input()
if not os.path.exists(dir_to_decrypt):
print("您输入的文件夹不存在,请重新输入!")
elif not os.path.isdir(dir_to_decrypt):
print("您输入的不是一个合法的文件夹目录,请重新输入!")
else:
files_to_decrypt = glob.glob(os.path.join(dir_to_decrypt, "*.xm"))
break
while True:
print("请选择是否需要设置输出路径:(不设置默认为本程序目录下的output文件夹)")
print("1. 设置输出路径")
print("2. 不设置输出路径")
choice = input()
if choice == "1":
print("请输入输出路径:")
output_path = input()
if not os.path.exists(output_path):
print("您输入的文件夹不存在,请重新输入!")
elif not os.path.isdir(output_path):
print("您输入的不是一个合法的文件夹目录,请重新输入!")
else:
break
elif choice == "2":
output_path = ""
break
else:
print("输入错误,请重新输入!")
output_path = ""
for file in files_to_decrypt:
decrypt_xm_file(file, output_path)
elif choice == "3":
Expand Down

0 comments on commit 2dc0aa3

Please sign in to comment.