static DownloadedMedia downloadAudio(WithURL url) { if (url == null) null; ret downloadAudio(url.url()); } static DownloadedMedia downloadAudio(S url) { if (empty(url)) null; File dir = downloadedAudioDir(); S extension = ".opus"; 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); S options = "-U --no-playlist --no-mtime --write-description --write-info-json" + " --write-annotations --write-thumbnail --print-json --restrict-filenames"; options += " -x"; // audio only options += " --audio-format opus"; // demand opus S 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); }