-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy pathmerger.py
More file actions
27 lines (19 loc) · 793 Bytes
/
merger.py
File metadata and controls
27 lines (19 loc) · 793 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import os
import sys
import json
"""Merge the metadata.json of different features"""
dataset_dir = sys.argv[1]
sub_dirs = [i for i in os.listdir(sys.argv[1]) if 'json' not in i]
metas = []
merged = {}
for sub_dir in sub_dirs:
metas.append(json.load(open(os.path.join(dataset_dir, sub_dir, 'metadata.json'))))
for key in metas[0].keys():
if key == 'feature_name':
continue
merged[key] = [{} for i in range(len(metas[0][key]))]
for subdir, meta in zip(sub_dirs, metas):
for idx, value in enumerate(meta[key]):
merged[key][idx]['audio_path'] = value['audio_path']
merged[key][idx][meta['feature_name']] = os.path.join(subdir, value['feature_path'])
json.dump(merged, open(os.path.join(dataset_dir, 'metadata.json'), 'w'), indent=2)