예제 #1
0
 public static String append(String res, String sep, String data) {
   res = ChannelUtil.separatorToken(res);
   data = ChannelUtil.separatorToken(data);
   sep = ChannelUtil.separatorToken(sep);
   if (empty(res)) return data;
   if (empty(data)) return res;
   if (empty(sep)) return res + data;
   return res + sep + data;
 }
예제 #2
0
 public static int calcCont(String[] props) {
   String lim = ChannelUtil.getPropertyValue(props, "continue_limit");
   int ret = Channels.DeafultContLim;
   if (!ChannelUtil.empty(lim)) {
     try {
       ret = Integer.parseInt(lim);
     } catch (Exception e) {
     }
   }
   if (ret < 0) ret = Channels.DeafultContLim;
   return ret;
 }
예제 #3
0
 public static String extension(String fileName, boolean stripDot) {
   if (ChannelUtil.empty(fileName)) return null;
   int pos = fileName.lastIndexOf('.');
   if ((pos > 0) && (pos < fileName.length() - 1))
     return fileName.substring(pos + (stripDot ? 1 : 0));
   return null;
 }
예제 #4
0
 public static int[] getNameIndex(String[] prop) {
   try {
     String x = ChannelUtil.getPropertyValue(prop, "name_index");
     if (!empty(x)) {
       String[] idx = x.split("\\+");
       int[] res = new int[idx.length];
       for (int i = 0; i < idx.length; i++) {
         int j = new Integer(idx[i]).intValue();
         if (j > 0) res[i] = j;
       }
       return res;
     }
   } catch (Exception e) {
     Channels.debug("excep " + e);
   }
   return null;
 }
예제 #5
0
 public static String parseASX(String url, int type) {
   if (type == ChannelUtil.ASXTYPE_NONE) return url;
   if (type == ChannelUtil.ASXTYPE_AUTO && !isASX(url)) return url;
   String page;
   try {
     page = ChannelUtil.fetchPage(new URL(url).openConnection());
   } catch (Exception e) {
     Channels.debug("asx fetch failed " + e);
     return url;
   }
   Channels.debug("page " + page);
   int first = page.indexOf("href=");
   if (first == -1) return url;
   int last = page.indexOf('\"', first + 6);
   if (last == -1) return url;
   return page.substring(first + 6, last);
 }
예제 #6
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);
 }
예제 #7
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;
  }
예제 #8
0
  public static String createMediaUrl(HashMap<String, String> vars, int format, Channel ch) {
    String rUrl = vars.get("url");
    if (empty(rUrl) || Channels.noPlay()) // what do we do?
    return null;
    int rtmpMet = Channels.rtmpMethod();
    String type = vars.get("__type__");
    Channels.debug("create media url entry " + rUrl + " format " + format + " type " + type);
    if (rUrl.startsWith("http")) {
      if ((format != Format.VIDEO) || (rtmpMet == Channels.RTMP_MAGIC_TOKEN)) return rUrl;
      // rUrl="navix://channel?url="+escape(rUrl);
      rUrl = "channel?url=" + escape(rUrl);
      String agent = vars.get("agent");
      if (empty(agent)) agent = ChannelUtil.defAgentString;
      rUrl = append(rUrl, "&agent=", escape(agent));
      if (!empty(vars.get("referer")))
        rUrl = append(rUrl, "&referer=", escape(vars.get("referer")));
      String sub = vars.get("subtitle");
      if (!empty(sub)) { // we got subtitles
        rUrl = "subs://" + rUrl;
        // lot of things to append here
        rUrl = addSubs(rUrl, sub);
      } else if (!empty(type) && type.equals("navix")) rUrl = "navix://" + rUrl;
      else rUrl = vars.get("url");
      Channels.debug("return media url " + rUrl);
      return rUrl;
    }

    if (!empty(type) && type.equals("RTMPDUMP")) {
      Channels.debug("rmtpdump spec " + rUrl);
      String[] args = rUrl.split("!!!");
      String res = "";
      for (int i = 0; i < args.length; i++) {
        if (empty(args[i])) continue;
        String[] kv = args[i].split("=", 2);
        if (kv.length < 2) continue;
        if (kv[0].equals("flv")) continue;
        res = append(res, "&", kv[0] + "=" + escape(kv[1]));
      }
      rUrl = "rtmpdump://channel?" + res;
      String sub = vars.get("subtitle");
      if (!empty(sub)) { // we got subtitles
        // lot of things to append here
        rUrl = addSubs(rUrl, sub);
      }
      Channels.debug("return media url rtmpdump spec " + rUrl);
      return rUrl;
    }

    String[] s = rUrl.split(" ");
    if (s.length > 1) {
      // This is likely rtmp from navix
      rUrl = s[0]; // first one is the url
      for (int i = 1; i < s.length; i++) {
        String[] ss = s[i].split("=", 2);
        if (ss.length < 2) vars.put(ss[0].toLowerCase(), "");
        else vars.put(ss[0].toLowerCase(), ss[1]);
      }
    }

    if (!rtmpStream(rUrl)) // type is sopcast etc.
    return rUrl;
    if (rUrl.startsWith("rtmpdump://")) return rUrl;

    switch (rtmpMet) {
      case Channels.RTMP_MAGIC_TOKEN:
        rUrl = ChannelUtil.append(rUrl, "!!!pms_ch_dash_y!!!", vars.get("playpath"));
        rUrl = ChannelUtil.append(rUrl, "!!!pms_ch_dash_w!!!", vars.get("swfVfy"));
        break;

      case Channels.RTMP_DUMP:
        Channels.debug("rtmpdump method");
        rUrl = "rtmpdump://channel?-r=" + escape(rUrl);
        if (!empty(vars.get("live"))) rUrl = append(rUrl, "", "&-v");
        rUrl = ChannelUtil.append(rUrl, "&-y=", escape(vars.get("playpath")));
        rUrl = ChannelUtil.append(rUrl, "&--swfVfy=", escape(vars.get("swfVfy")));
        rUrl = ChannelUtil.append(rUrl, "&--swfVfy=", escape(vars.get("swfvfy")));
        rUrl = ChannelUtil.append(rUrl, "&-s=", escape(vars.get("swfplayer")));
        rUrl = ChannelUtil.append(rUrl, "&-a=", escape(vars.get("app")));
        rUrl = ChannelUtil.append(rUrl, "&-p=", escape(vars.get("pageurl")));
        rUrl = ChannelUtil.append(rUrl, "&-s=", escape(vars.get("swfurl")));
        String sub = vars.get("subtitle");
        if (!empty(sub)) { // we got subtitles
          // lot of things to append here
          rUrl = addSubs(rUrl, sub);
        }
        break;

      default:
        rUrl = vars.get("url");
        break;
    }
    Channels.debug("return media url " + rUrl);
    return rUrl;
  }