Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

52
LINES

< > BotCompany Repo | #1032339 // DownloadVideo

JavaX fragment (include) [tags: use-pretranspiled]

Transpiled version (11889L) is out of date.

1  
sclass DownloadVideo {
2  
  S url;
3  
  File dir = downloadedVideoDir();
4  
  new LS options;
5  
  S extension = ".mp4";
6  
  S formatString = dropDotPrefix(extension);
7  
    //"best[ext=mp4]"; // This might work?
8  
    // problem with this is we don't know the output format
9  
    //"bestvideo[height<=720]+bestaudio/best[height<=720]";
10  
  int maxFileSizeInMB = 100;
11  
  
12  
  S cmd;
13  
  
14  
  *(WithURL<?> url) {
15  
    this(url?.url());
16  
  }
17  
  
18  
  *(S *url) {
19  
    options.add("-U --no-playlist --no-mtime --write-description --write-info-json");
20  
    options.add("--write-annotations --write-thumbnail --print-json --restrict-filenames";
21  
    //options.add("--format " + dropDotPrefix(extension)); // demand our format
22  
    options.add("-f " + pqO(formatString));
23  
  }
24  
  
25  
  DownloadedMedia get() {
26  
    if (empty(url)) null;
27  
    
28  
    installFFMPEGIfMissing();
29  
    
30  
    options.add("--max-filesize " + maxFileSizeInMB + "m");
31  
    
32  
    S fn = md5FileName(url);
33  
    File infoFile = newFile(dir, fn + ".info");
34  
    S json = loadTextFile(infoFile);
35  
    if (isPossibleJSONMap(json)) {
36  
      DownloadedMedia dm = new(null, json, extension);
37  
      if (fileExists(dm!)) ret dm;
38  
    }
39  
    
40  
    saveTextFile(newFile(dir, fn + ".url"), url);
41  
    
42  
    cmd = pqO(installYouTubeDL())
43  
      + " " + joinWithSpace(options)
44  
      + " -o " + pqO(newFile(dir, youTubeDLDefaultFileNameTemplate()))
45  
      + " " + safePlatformQuote(url);
46  
    saveTextFile(newFile(dir, fn + ".cmd"), cmd);
47  
    
48  
    S output = backtick_verbose(cmd);
49  
    saveTextFile(infoFile, output);
50  
    ret new DownloadedMedia(cmd, output, extension);
51  
  }
52  
}

Author comment

Began life as a copy of #1032316

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, ekrmjmnbrukm, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx

No comments. add comment

Snippet ID: #1032339
Snippet name: DownloadVideo
Eternal ID of this version: #1032339/10
Text MD5: 459f50b2bd07506175191a1e753c63f5
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-09-02 03:01:04
Source code size: 1614 bytes / 52 lines
Pitched / IR pitched: No / No
Views / Downloads: 107 / 234
Version history: 9 change(s)
Referenced in: [show references]