网易云音乐的云盘上传了很多歌大概一千
过了很久发现有几个歌曲在云盘存在,但是歌单不见了
后面发现是歌下架了,不能加到歌单
于是想找出那些歌单是下架的
目前有两个想法,一是调api接口,分别获取自己的歌单和云盘的歌,然后操作集合拿差异集合
二是可以在以下路径找到Windows下的播放器的歌单文件,对比文件
文件是标准的json字符串记录播放列表:
%LOCALAPPDATA%\Netease\CloudMusic\webdata\file\queue
格式如下:
[
{
"track": {
"name": "一点点"
}
},
{
"track": {
"name": "golden hour"
}
}
]
对比效果:
json文件最好指定编码,支持交集差集,如果是对比歌名,默认值选track.name、差集就行
代码如下(找ai写了个对比集合的东西随便改了下):
# # 选择两个json文件取json集合某个对象的某个属性,为两个set集合,输出交集 # # 依赖 pip install pyinstaller # 打包 pyinstaller -F -w json_comparator_gui.py -n JsonComparator # -F 打包成一个exe文件 # -w 使用窗口,无控制台 # -n 指定程序名称 # import json import tkinter as tk from tkinter import filedialog, messagebox def load_json(file_path, encoding): with open(file_path, 'r', encoding=encoding) as json_file: return json.load(json_file) def get_nested_property(obj, properties): for prop in properties: obj = obj.get(prop) if obj is None: return None return obj def compare_json_properties(): file_path1 = filedialog.askopenfilename(title="Select the first JSON file") file_path2 = filedialog.askopenfilename(title="Select the second JSON file") encoding = encoding_entry.get() property_path = property_entry.get() try: json_data1 = load_json(file_path1, encoding) json_data2 = load_json(file_path2, encoding) property_names = property_path.split('.') values1 = set() for item in json_data1: nested_property = get_nested_property(item, property_names) if nested_property is not None: values1.add(nested_property) values2 = set() for item in json_data2: nested_property = get_nested_property(item, property_names) if nested_property is not None: values2.add(nested_property) diff = values1.symmetric_difference(values2) # 将set转换为包含字符串的列表 diff_list = [str(x) for x in diff] # 将列表转换为JSON字符串, 并保持中文输出, 指定4个缩进空格数 diff_json_string = json.dumps(diff_list, ensure_ascii=False, indent=4) result_text.delete(1.0, tk.END) result_text.insert(tk.END, diff_json_string) except Exception as e: messagebox.showerror("Error", f"An error occurred: {str(e)}") # Create the GUI root = tk.Tk() root.title("JSON Comparator by ssw") window_width = 800 window_height = 500 screen_width = root.winfo_screenwidth() screen_height = root.winfo_screenheight() x_coordinate = int((screen_width - window_width) / 2) y_coordinate = int((screen_height - window_height) / 2) root.geometry(f"{window_width}x{window_height}+{x_coordinate}+{y_coordinate}") encoding_label = tk.Label(root, text="Enter the file encoding (eg: utf-8):") encoding_label.grid(row=0, column=0, sticky="w") encoding_entry = tk.Entry(root) encoding_entry.insert(tk.END, 'utf-8') # Set default value encoding_entry.grid(row=0, column=1) property_label = tk.Label(root, text="Enter the property path (eg: obj1.obj2.property):") property_label.grid(row=1, column=0, sticky="w") property_entry = tk.Entry(root) property_entry.insert(tk.END, 'track.name') # Set default value property_entry.grid(row=1, column=1) compare_button = tk.Button(root, text="Select json file and compare", command=compare_json_properties, bg="#90EE90") compare_button.grid(row=2, columnspan=3) result_label = tk.Label(root, text="Differences:") result_label.grid(row=3, column=0, sticky="w") result_text = tk.Text(root, height=30, width=40) result_text.grid(row=4, column=0, sticky="w") info_label = tk.Label(root, text="Additional Info:") info_label.grid(row=3, column=1, sticky="w") info_text = tk.Text(root, height=30, width=70) info_text.insert(tk.END, ''' 选择两个json文件取json集合某个对象的某个属性,为两个set集合,输出交集\n 1.例如网易云音乐的播放列表json: %LOCALAPPDATA%\\Netease\\CloudMusic\\webdata\\file\\queue\n 2.json样例: [ { "track": { "name": "一点点" } }, { "track": { "name": "golden hour" } } ]\n 3.取全部歌名到set集合的property path: track.name ''') info_text.grid(row=4, column=1, sticky="e") root.mainloop() |