import os, json



folderPath = 'STREAM_IMPORTED'
jsonFile = 'bunnyVideos.json'

data = json.load(open(jsonFile))

for item in data:
    username = item['title']
    filepath = os.path.join(folderPath, item['guid'] + '.mp4')
    
    if username in filepath:
        continue
    
    username = item['title']
    output = os.path.join(folderPath, username, os.path.basename(filepath))
    os.makedirs(os.path.dirname(output), exist_ok=True)
    if os.path.exists(filepath):
        os.rename(filepath, output)
    item['filepath'] = output
        
        
# save to fiel
with open(jsonFile, 'w') as f:
    json.dump(data, f, indent=4)