ToughStone commited on
Commit
cefaceb
·
verified ·
1 Parent(s): a044f5d

Upload 3 files

Browse files
Files changed (3) hide show
  1. GT.json +0 -0
  2. filter.py +44 -0
  3. raw_data.json +0 -0
GT.json ADDED
The diff for this file is too large to render. See raw diff
 
filter.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+ from urllib.parse import urlparse
4
+
5
+ # 读取 JSON 文件
6
+ with open('raw_data.json', 'r', encoding='utf-8') as f:
7
+ data = json.load(f)
8
+
9
+ # 按原始 id 排序
10
+ sorted_data = sorted(data, key=lambda x: x['id'])
11
+
12
+ # 重新分配 id(从 1 开始连续编号)
13
+ for new_id, item in enumerate(sorted_data, start=1):
14
+ item['id'] = new_id
15
+
16
+ # 保存重新编号后的 JSON 文件
17
+ with open('raw_data.json', 'w', encoding='utf-8') as f:
18
+ json.dump(sorted_data, f, ensure_ascii=False, indent=4)
19
+
20
+ # 1. 读取 JSON 文件
21
+ json_path = 'raw_data.json' # JSON 文件路径
22
+ video_dir = 'videos' # 视频文件夹路径(与 JSON 文件同级)
23
+
24
+ with open(json_path, 'r', encoding='utf-8') as f:
25
+ data = json.load(f)
26
+
27
+ # 2. 提取 JSON 中所有视频的编号(如 BV1qzg2zBEsN)
28
+ valid_video_ids = set()
29
+ for item in data:
30
+ url = item['url']
31
+ # 从 URL 中提取视频 ID(如 B站 BV 号)
32
+ video_id = url.split('/')[-1] # 假设 URL 以 BV 号结尾
33
+ valid_video_ids.add(video_id)
34
+
35
+ # 3. 遍历视频文件夹,删除不在 valid_video_ids 中的文件
36
+ deleted_files = []
37
+ for filename in os.listdir(video_dir):
38
+ file_id = os.path.splitext(filename)[0] # 去掉扩展名,如 BV1qzg2zBEsN.mp4 -> BV1qzg2zBEsN
39
+ if file_id not in valid_video_ids:
40
+ file_path = os.path.join(video_dir, filename)
41
+ os.remove(file_path)
42
+ deleted_files.append(filename)
43
+
44
+ print(f"已删除 {len(deleted_files)} 个无效视频文件: {deleted_files}")
raw_data.json ADDED
The diff for this file is too large to render. See raw diff