static DownloadedMedia DownloadAudio(WithURL url) { if (url == null) null; ret downloadAudio(url.url()); } sclass DownloadAudio { S url; File dir = downloadedAudioDir(); new LS options; S extension = ".opus"; int maxFileSizeInMB = 20; S cmd; *(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("-x"); // audio only options.add("--audio-format opus"); // demand opus } DownloadedMedia get() { if (empty(url)) null; options.add("--max-file-size " + maxFileSizeInMB + "m"); S fn = md5FileName(url); File infoFile = newFile(dir, fn + ".info"); S json = loadTextFile(infoFile); if (nempty(json)) { DownloadedMedia dm = new(null, json, extension); if (fileExists(dm!)) ret dm; } saveTextFile(newFile(dir, fn + ".url"), url); cmd = pqO(installYouTubeDL()) + " " + options + " -o " + pqO(newFile(dir, youTubeDLDefaultFileNameTemplate())) + " " + pqO(url); S output = backtick_verbose(cmd); saveTextFile(infoFile, output); ret new DownloadedMedia(cmd, output, extension); } }