Package net.pms.dlna

Examples of net.pms.dlna.RootFolder


  }

  public RootFolder getRoot(String name, boolean create, HttpExchange t) {
    String groupTag = getTag(name);
    String cookie = getCookie(t.getRequestHeaders().getFirst("Cookie"));
    RootFolder root = roots.get(cookie);
    if (!create || (root != null)) {
      t.getResponseHeaders().add("Set-Cookie", "UMS=" + cookie + ";Path=/");
      return root;
    }
    ArrayList<String> tag = new ArrayList<>();
    tag.add(name);
    if (!groupTag.equals(name)) {
      tag.add(groupTag);
    }

    tag.add(t.getRemoteAddress().getHostString());
    tag.add("web");
    root = new RootFolder(tag);
    try {
      WebRender render = new WebRender(name);
      root.setDefaultRenderer(render);
      render.associateIP(t.getRemoteAddress().getAddress());
      render.associatePort(t.getRemoteAddress().getPort());
      render.setUA(t.getRequestHeaders().getFirst("User-agent"));
      PMS.get().setRendererFound(render);
    } catch (ConfigurationException e) {
      root.setDefaultRenderer(RendererConfiguration.getDefaultConf());
    }
    //root.setDefaultRenderer(RendererConfiguration.getRendererConfigurationByName("web"));
    root.discoverChildren();
    cookie = UUID.randomUUID().toString();
    t.getResponseHeaders().add("Set-Cookie", "UMS=" + cookie + ";Path=/");
    roots.put(cookie, root);
    return root;
  }
View Full Code Here


      LOGGER.trace("web thumb req " + id);
      if (id.contains("logo")) {
        RemoteUtil.sendLogo(t);
        return;
      }
      RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
      if (root == null) {
        LOGGER.debug("weird root in thumb req");
        throw new IOException("Unknown root");
      }
      final List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, root.getDefaultRenderer());
      if (res.size() != 1) {
        // another error
        LOGGER.debug("media unkonwn");
        throw new IOException("Bad id");
      }
View Full Code Here

  @Override
  public void handle(HttpExchange t) throws IOException {
    if (RemoteUtil.deny(t)) {
      throw new IOException("Access denied");
    }
    RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
    if (root == null) {
      throw new IOException("Unknown root");
    }
    Headers h = t.getRequestHeaders();
    for(String h1: h.keySet())  {
      LOGGER.debug("key "+h1+"="+h.get(h1));
    }
    String id = RemoteUtil.getId(path, t);
    id = RemoteUtil.strip(id);
    RendererConfiguration r = render;
    if (render == null) {
      r = root.getDefaultRenderer();
    }
    List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, r);
    if (res.size() != 1) {
      // another error
      LOGGER.debug("media unkonwn");
      throw new IOException("Bad id");
    }
    long len = res.get(0).length();
    Range range = RemoteUtil.parseRange(t.getRequestHeaders(), len);
    String mime = root.getDefaultRenderer().getMimeType(res.get(0).mimeType());
    DLNAResource dlna = res.get(0);
    DLNAMediaInfo m = dlna.getMedia();
    if(mime.equals(FormatConfiguration.MIMETYPE_AUTO) && m != null && m.getMimeType() != null) {
      mime = m.getMimeType();
    }
    if (dlna.getFormat().isVideo()) {
      if (flash) {
        mime = "video/flash";
        dlna.setPlayer(new WebPlayer(WebPlayer.FLASH));
      } else if (!RemoteUtil.directmime(mime)) {
        mime = RemoteUtil.MIME_TRANS;
        dlna.setPlayer(new WebPlayer(WebPlayer.TRANS));
      }
      else {
        dlna.setPlayer(null);
      }
    }

    LOGGER.debug("dumping media " + mime + " " + res);
    InputStream in = dlna.getInputStream(range, root.getDefaultRenderer());
    Headers hdr = t.getResponseHeaders();
    hdr.add("Content-Type", mime);
    hdr.add("Accept-Ranges", "bytes");
    hdr.add("Server", PMS.get().getServerName());
    hdr.add("Connection", "keep-alive");
View Full Code Here

  private String mkPage(String id, HttpExchange t) throws IOException {
    boolean flowplayer = true;

    LOGGER.debug("make play page " + id);
    RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
    if (root == null) {
      throw new IOException("Unknown root");
    }
    List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, root.getDefaultRenderer());
    if (res == null || res.isEmpty()) {
      LOGGER.debug("Bad id in web if " + id);
      throw new IOException("Bad Id");
    }
    DLNAResource r = res.get(0);
    String auto = " autoplay>";
    // next/prev handling
    String dir = RemoteUtil.getQueryVars(t.getRequestURI().getQuery(), "nxt");
    if (StringUtils.isNotEmpty(dir)) {
      // if the "nxt" field is set we should calculate the next media
      // 1st fetch or own index in the child list
      List<DLNAResource> children = r.getParent().getChildren();
      int i = children.indexOf(r);
      DLNAResource n = null;
      int inc;
      int loopPos;
      if (dir.equals("next")) {
        inc = 1;
        loopPos = 0;
      } else {
        inc = -1;
        loopPos = children.size() - 1;
      }
      n = findNext(i + inc, inc, children);
      if (n == null && configuration.getWebAutoLoop(r.getFormat())) {
        // we were last/first so if we loop pick first/last in list
        n = findNext(loopPos, inc, children);
      }
      if (n != null) {
        // all done, change the id
        id = n.getResourceId();
        r = n;
      } else {
        // trick here to stop continuing if loop is off
        auto = ">";
      }
    }
    String id1 = URLEncoder.encode(id, "UTF-8");
    String rawId = id;

    String nxtJs = "window.location.replace('/play/" + id1 + "?nxt=next');";
    String prvJs = "window.location.replace('/play/" + id1 + "?nxt=prev');";
    // hack here to ensure we got a root folder to use for recently played etc.
    root.getDefaultRenderer().setRootFolder(root);
    String mime = root.getDefaultRenderer().getMimeType(r.mimeType());
    String mediaType = "";
    String coverImage = "";
    if (r instanceof VirtualVideoAction) {
      // for VVA we just call the enable fun directly
      // waste of resource to play dummy video
View Full Code Here

    this.parent = parent;
  }

  private String mkBrowsePage(String id, HttpExchange t) throws IOException {
    String user = RemoteUtil.userName(t);
    RootFolder root = parent.getRoot(user, true, t);
    String search = RemoteUtil.getQueryVars(t.getRequestURI().getQuery(), "str");

    List<DLNAResource> res = root.getDLNAResources(id, true, 0, 0, root.getDefaultRenderer(), search);
    if (StringUtils.isNotEmpty(search)) {
      UMSUtils.postSearch(res, search);
    }

    // Media browser HTML
View Full Code Here

  public void handle(HttpExchange t) throws IOException {
    LOGGER.debug("got a raw request " + t.getRequestURI());
    if (RemoteUtil.deny(t)) {
      throw new IOException("Access denied");
    }
    RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
    if (root == null) {
      throw new IOException("Unknown root");
    }
    String id;
    id = RemoteUtil.strip(RemoteUtil.getId("raw/", t));
    LOGGER.debug("raw id " + id);
    List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, root.getDefaultRenderer());
    if (res.size() != 1) {
      // another error
      LOGGER.debug("media unkonwn");
      throw new IOException("Bad id");
    }
    DLNAResource dlna = res.get(0);
    long len = dlna.length();
    dlna.setPlayer(null);
    Range range = RemoteUtil.parseRange(t.getRequestHeaders(), len);
    Range.Byte rb = range.asByteRange();
    InputStream in = dlna.getInputStream(range, root.getDefaultRenderer());
    String mime = root.getDefaultRenderer().getMimeType(dlna.mimeType());
    Headers hdr = t.getResponseHeaders();
    LOGGER.debug("dumping media " + mime + " " + dlna);
    hdr.add("Content-Type", mime);
    hdr.add("Accept-Ranges", "bytes");
    hdr.add("Server", PMS.get().getServerName());
View Full Code Here

        if (addressAssociation.get(sa) == this) {
          tags.add(sa.getHostAddress());
        }
      }

      rootFolder = new RootFolder(tags);
      if (pmsConfiguration.getUseCache()) {
        rootFolder.discoverChildren();
      }
    }
View Full Code Here

    }

    ArrayList<RendererConfiguration> renderers = RendererConfiguration.getEnabledRenderersConfigurations();

    for (RendererConfiguration r : renderers) {
      RootFolder rf = r.getRootFolder();
      rf.reset();
    }

    if (remove != null) {
      externalListeners.remove(remove);
      remove.shutdown();
View Full Code Here

    }
  }

  public RootFolder getRootFolder() {
    if (rootFolder == null) {
      rootFolder = new RootFolder();
      if (pmsConfiguration.getUseCache()) {
        rootFolder.discoverChildren();
      }
    }
View Full Code Here

TOP

Related Classes of net.pms.dlna.RootFolder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.