## Pre-requisities: run 'pip install youtube-dl' to install the youtube-dl package. ## Specify your location of output videos and input json file. import json import os import yt_dlp from tqdm import tqdm output_path = '/data/coin/videos' json_path = 'datasets/download_tools/coin_files.json' cookies_file_location = "datasets/download_tools/cookies.txt" if not os.path.exists(output_path): os.mkdir(output_path) data = json.load(open(json_path, 'r'))['database'] youtube_ids = list(data.keys()) def dwl_vid(video_url, save_path, filename): if os.path.exists(f"{save_path}/{filename}.mp4"): print("Skipping, yt") return ydl_opts = { 'format': 'bestvideo+bestaudio/best', # Combine the best video and audio streams 'outtmpl': f'{save_path}/{filename}.%(ext)s', # Custom filename template 'cookiefile': cookies_file_location, "cachedir": False, 'postprocessors': [{ 'key': 'FFmpegVideoConvertor', # Convert video format 'preferedformat': 'mp4', # Convert to MP4 }], 'quiet': True, # Suppresses all output messages 'no_warnings': True, } with yt_dlp.YoutubeDL(ydl_opts) as ydl: ydl.download([video_url]) for youtube_id in tqdm(data): info = data[youtube_id] type = info['recipe_type'] url = info['video_url'] vid_loc = output_path if not os.path.exists(vid_loc): os.mkdir(vid_loc) try: dwl_vid(url, output_path, youtube_id) except Exception as e: print(e) # os.system('youtube-dl -o ' + vid_loc + '/' + youtube_id + '.mp4' + ' -f best ' + url) # To save disk space, you could download the best format available # but not better that 480p or any other qualities optinally # See https://askubuntu.com/questions/486297/how-to-select-video-quality-from-youtube-dl