Example #1
0
 private static ProcessBuilder buildPid(String fName, String url) {
   int rtmpMet = Channels.rtmpMethod();
   if (rtmpMet == Channels.RTMP_MAGIC_TOKEN) {
     url = url.replace("!!!pms_ch_dash_y!!!", " -y ");
     url = url.replace("!!!pms_ch_dash_w!!!", " -W ");
     return null;
   }
   ArrayList<String> args = new ArrayList<String>();
   args.add(Channels.cfg().getRtmpPath());
   int pos = url.indexOf('?');
   if (pos == -1) return null;
   String[] data = url.substring(pos + 1).split("&");
   for (int i = 0; i < data.length; i++) {
     String[] kv = data[i].split("=");
     args.add(kv[0]);
     if (kv.length > 1) args.add("\"" + ChannelUtil.unescape(kv[1]) + "\"");
   }
   args.add("-o");
   args.add("\"" + fName + "\"");
   return new ProcessBuilder(args);
 }
Example #2
0
  public static Thread backgroundDownload(String name, String url, boolean cache) {
    String fName = ChannelUtil.guessExt(Channels.fileName(name, cache), url);
    if (ChannelUtil.rtmpStream(url)) {
      try {
        //		URL u=new URL(url);
        // rtmp stream special fix
        if (empty(extension(fName))) // no extension. Rtmp is normally mp4
        fName = fName + ".mp4";
        final ProcessBuilder pb = buildPid(fName, url);
        if (pb == null) return null;
        Channels.debug("start process ");
        Runnable r =
            new Runnable() {
              public void run() {
                ChannelUtil.execute(pb);
              }
            };
        return new Thread(r);
      } catch (Exception e) {
        return null;
      }
    }

    String subFile = "";
    if (url.startsWith("http") || url.startsWith("navix") || url.startsWith("subs")) {
      if (url.startsWith("navix") || url.startsWith("subs")) {
        int pos = url.indexOf('?');
        if (pos == -1) return null;
        String[] data = url.substring(pos + 1).split("&");
        for (int i = 0; i < data.length; i++) {
          String[] kv = data[i].split("=");
          if (kv[0].equals("url")) url = ChannelUtil.unescape(kv[1]);
          if (kv[0].equals("subs")) subFile = unescape(kv[1]);
        }
      }
      if (empty(url)) return null;
      final String rUrl = url;
      final String sFile = subFile;
      if (empty(extension(fName))) // no ext guess mpg as ext
      fName = fName + ".mpg";
      final String fName1 = fName;
      Runnable r =
          new Runnable() {
            public void run() {
              File f = new File(fName1);
              if (!empty(sFile)) {
                File s = new File(sFile);
                byte[] buf = new byte[4096];
                try {
                  FileInputStream in = new FileInputStream(s);
                  FileOutputStream out =
                      new FileOutputStream(new File(f.getParent() + File.separator + s.getName()));
                  while ((in.read(buf)) != -1) out.write(buf);

                  in.close();
                  out.close();
                } catch (Exception e) {
                  // ignore this
                  Channels.debug("Error moving subtitle file " + sFile);
                }
              }
              // download the actaul movie, subtitles are done
              downloadBin(rUrl, f);
            }
          };
      return new Thread(r);
    }
    return null;
  }