sclass DownloadVideo { S url; File dir = downloadedVideoDir(); new LS options; S extension = ".mp4"; S formatString = dropDotPrefix(extension); //"best[ext=mp4]"; // This might work? // problem with this is we don't know the output format //"bestvideo[height<=720]+bestaudio/best[height<=720]"; int maxFileSizeInMB = 100; S cmd; *(WithURL url) { this(url?.url()); } *(S *url) { options.add("-U --no-playlist --no-mtime --write-description --write-info-json"); options.add("--write-annotations --write-thumbnail --print-json --restrict-filenames"; //options.add("--format " + dropDotPrefix(extension)); // demand our format options.add("-f " + pqO(formatString)); } DownloadedMedia get() { if (empty(url)) null; installFFMPEGIfMissing(); options.add("--max-filesize " + maxFileSizeInMB + "m"); S fn = md5FileName(url); File infoFile = newFile(dir, fn + ".info"); S json = loadTextFile(infoFile); if (isPossibleJSONMap(json)) { DownloadedMedia dm = new(null, json, extension); if (fileExists(dm!)) ret dm; } saveTextFile(newFile(dir, fn + ".url"), url); cmd = pqO(installYouTubeDL()) + " " + joinWithSpace(options) + " -o " + pqO(newFile(dir, youTubeDLDefaultFileNameTemplate())) + " " + safePlatformQuote(url); saveTextFile(newFile(dir, fn + ".cmd"), cmd); S output = backtick_verbose(cmd); saveTextFile(infoFile, output); ret new DownloadedMedia(cmd, output, extension); } }