import os
import json
import string
import random
import subprocess


save_dir = 'mlb_dataset/input'
os.makedirs(save_dir)
with open('data/mlb-youtube-segmented-small.json', 'r') as f:
    data = json.load(f)
    for entry in data:
        print(entry)
        yturl = data[f'{entry}']['url']
        ytid = yturl.split('=')[-1]

        if os.path.exists(os.path.join(save_dir, ytid+'.mkv')):
            continue

        cmd = 'youtube-dl -f mp4 '+yturl+' -o '+os.path.join(save_dir, ytid+'.mp4')
        os.system(cmd)
