Uses 107K of libraries. Click here for Pure Java version (6476L/47K/153K).
1 | !7 |
2 | |
3 | lib 1013692 |
4 | |
5 | import org.apache.commons.exec.*; |
6 | |
7 | sbool useApacheCommonsExec = true; |
8 | |
9 | sS youTubeOptions = "-f 140/171"; // audio only |
10 | static File outputDir; |
11 | |
12 | static StringBuilder output; |
13 | |
14 | p { |
15 | //useApacheCommonsExec = isWindows(); |
16 | set backtick_verbose; |
17 | set backtick_keepScript; |
18 | |
19 | //print("args: " + struct(args)); |
20 | S url = or2(first(args), "https://www.youtube.com/watch?v=99Q31nyH16w"); |
21 | |
22 | // get youtube-dl |
23 | File youtubeDL = installYouTubeDL(); |
24 | S outputTemplate = f2s(new File(or(outputDir, programDir()), "%(title)s-%(id)s.%(ext)s")); |
25 | |
26 | output = new StringBuilder; |
27 | |
28 | // update console title with percentages |
29 | final new LastLineBuffer buf; |
30 | O onOutput = voidfunc(S s) { |
31 | S fixed = fixNewLines(s); |
32 | buf.append(fixed); |
33 | output.append(fixed); |
34 | S percent = regexpFirstGroup("([0-9.]+)%", buf.lastCompleteLine()); |
35 | if (nempty(percent)) |
36 | consoleTitleIfMain(percent + "% - " + programTitle()); |
37 | }; |
38 | |
39 | // do the job |
40 | |
41 | S host = hostNameFromURL(url); |
42 | S theOptions = cic(host, "youtu") ? youTubeOptions : ""; |
43 | |
44 | S cmd = platformQuote(youtubeDL) + " " + theOptions + " -o " + bashQuote(outputTemplate) + " " + platformQuote(url); |
45 | |
46 | if (useApacheCommonsExec) { |
47 | print("Running with Apache: " + cmd); |
48 | CommandLine cmdLine = CommandLine.parse(cmd); |
49 | new DefaultExecutor executor; |
50 | new ByteArrayOutputStream baos; |
51 | OutputStream stream = teeOutputStream(printOutputStream(), baos); |
52 | PumpStreamHandler pump = new(stream, stream); |
53 | executor.setStreamHandler(pump); |
54 | print("Exit value: " + executor.execute(cmdLine)); |
55 | output.append(fromUTF8(toByteArray(baos))); |
56 | } else |
57 | backtickToConsoleX(cmd, onOutput); |
58 | |
59 | // done |
60 | consoleTitle("DONE - " + programTitle()); |
61 | } |
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: | 835 / 2936 |
Version history: | 51 change(s) |
Referenced in: | [show references] |