Uses 107K of libraries. Click here for Pure Java version (6476L/47K/153K).
!7 lib 1013692 import org.apache.commons.exec.*; sbool useApacheCommonsExec = true; sS youTubeOptions = "-f 140/171"; // audio only static File outputDir; static StringBuilder output; p { //useApacheCommonsExec = isWindows(); set backtick_verbose; set backtick_keepScript; //print("args: " + struct(args)); S url = or2(first(args), "https://www.youtube.com/watch?v=99Q31nyH16w"); // get youtube-dl File youtubeDL = installYouTubeDL(); S outputTemplate = f2s(new File(or(outputDir, programDir()), "%(title)s-%(id)s.%(ext)s")); output = new StringBuilder; // update console title with percentages final new LastLineBuffer buf; O onOutput = voidfunc(S s) { S fixed = fixNewLines(s); buf.append(fixed); output.append(fixed); S percent = regexpFirstGroup("([0-9.]+)%", buf.lastCompleteLine()); if (nempty(percent)) consoleTitleIfMain(percent + "% - " + programTitle()); }; // do the job S host = hostNameFromURL(url); S theOptions = cic(host, "youtu") ? youTubeOptions : ""; S cmd = platformQuote(youtubeDL) + " " + theOptions + " -o " + bashQuote(outputTemplate) + " " + platformQuote(url); if (useApacheCommonsExec) { print("Running with Apache: " + cmd); CommandLine cmdLine = CommandLine.parse(cmd); new DefaultExecutor executor; new ByteArrayOutputStream baos; OutputStream stream = teeOutputStream(printOutputStream(), baos); PumpStreamHandler pump = new(stream, stream); executor.setStreamHandler(pump); print("Exit value: " + executor.execute(cmdLine)); output.append(fromUTF8(toByteArray(baos))); } else backtickToConsoleX(cmd, onOutput); // done consoleTitle("DONE - " + programTitle()); }
TODO: spaces in path
download show line numbers debug dex old transpilations
Travelled to 16 computer(s): aoiabmzegqzx, bhatertpkbcr, cbybwowwnfue, cfunsshuasjs, gwrvuhgaqvyk, irmadwmeruwu, ishqpsrjomds, lpdgvwnxivlt, mqqgnosmbjvj, onxytkatvevr, pyentgdyhuwx, pzhvpgtvlbxg, tslmcundralx, tvejysmllsmz, vouqrxazstgt, wtqryiryparv
No comments. add comment
Snippet ID: | #1006739 |
Snippet name: | Run youtube-dl to get .m4a audio [WORKS on Linux & Windows] |
Eternal ID of this version: | #1006739/52 |
Text MD5: | 8c3c6ef170b7b54e2c6684ebe3f36837 |
Transpilation MD5: | e2e601da58c6d548e887e090a2356b90 |
Author: | stefan |
Category: | javax / video |
Type: | JavaX source code |
Public (visible to everyone): | Yes |
Archived (hidden from active list): | No |
Created/modified: | 2019-09-04 00:28:24 |
Source code size: | 1791 bytes / 61 lines |
Pitched / IR pitched: | No / No |
Views / Downloads: | 834 / 2935 |
Version history: | 51 change(s) |
Referenced in: | [show references] |