Package net.pms.dlna.virtual

Examples of net.pms.dlna.virtual.VirtualFolder


              // Should the child be added to the #--TRANSCODE--# folder?
              if ((child.format.isVideo() || child.format.isAudio()) && child.isTranscodeFolderAvailable()) {
                // true: create (and append) the #--TRANSCODE--# folder to this
                // folder if supported/enabled and if it doesn't already exist
                VirtualFolder transcodeFolder = getTranscodeFolder(true);
                if (transcodeFolder != null) {
                  VirtualFolder fileTranscodeFolder = new FileTranscodeVirtualFolder(child.getDisplayName(), null);

                  DLNAResource newChild = child.clone();
                  newChild.player = player;
                  newChild.media = child.media;
                  fileTranscodeFolder.addChildInternal(newChild);
                  LOGGER.trace("Adding \"{}\" to transcode folder for player: \"{}\"", child.getName(), player.toString());

                  transcodeFolder.updateChild(fileTranscodeFolder);
                }
              }

              if (child.format.isVideo() && child.isSubSelectable() && !(this instanceof SubSelFile)) {
                VirtualFolder vf = getSubSelector(true);
                if (vf != null) {
                  DLNAResource newChild = child.clone();
                  newChild.setPlayer(player);
                  newChild.setMedia(child.media);
                  LOGGER.trace("Duplicate subtitle " + child.getName() + " with player: " + player.toString());

                  vf.addChild(new SubSelFile(newChild));
                }
              }

              for (ExternalListener listener : ExternalFactory.getExternalListeners()) {
                if (listener instanceof AdditionalResourceFolderListener) {
View Full Code Here


 
              // Should the child be added to the #--TRANSCODE--# folder?
              if ((child.getFormat().isVideo() || child.getFormat().isAudio()) && child.isTranscodeFolderAvailable()) {
                // true: create (and append) the #--TRANSCODE--# folder to this
                // folder if supported/enabled and if it doesn't already exist
                VirtualFolder transcodeFolder = getTranscodeFolder(true);
                if (transcodeFolder != null) {
                  VirtualFolder fileTranscodeFolder = new FileTranscodeVirtualFolder(child.getName(), null);
 
                  DLNAResource newChild = child.clone();
                  newChild.setPlayer(player);
                  newChild.setMedia(child.getMedia());
                  fileTranscodeFolder.addChildInternal(newChild);
                  logger.trace("Adding \"{}\" to transcode folder for player: \"{}\"", child.getName(), player.toString());
 
                  transcodeFolder.addChild(fileTranscodeFolder);
                }
              }
View Full Code Here

                  while (st.hasMoreTokens()) {
                    String folder = st.nextToken();
                    parent = currentRoot.searchByName(folder);

                    if (parent == null) {
                      parent = new VirtualFolder(folder, "");
                      currentRoot.addChild(parent);
                    }

                    currentRoot = parent;
                  }
View Full Code Here

   * Mac OS X only.
   *
   * @return iPhotoVirtualFolder the populated <code>VirtualFolder</code>, or null if one couldn't be created.
   */
  private DLNAResource getiPhotoFolder() {
    VirtualFolder iPhotoVirtualFolder = null;

    if (Platform.isMac()) {
      logger.debug("Adding iPhoto folder");
      InputStream inputStream = null;

      try {
        // This command will show the XML files for recently opened iPhoto databases
        Process process = Runtime.getRuntime().exec("defaults read com.apple.iApps iPhotoRecentDatabases");
        inputStream = process.getInputStream();
        List<String> lines = IOUtils.readLines(inputStream);
        logger.debug("iPhotoRecentDatabases: {}", lines);

        if (lines.size() >= 2) {
          // we want the 2nd line
          String line = lines.get(1);

          // Remove extra spaces
          line = line.trim();

          // Remove quotes
          line = line.substring(1, line.length() - 1);

          URI uri = new URI(line);
          URL url = uri.toURL();
          File file = FileUtils.toFile(url);
          logger.debug("Resolved URL to file: {} -> {}", url, file.getAbsolutePath());

          // Load the properties XML file.
          Map<String, Object> iPhotoLib = Plist.load(file);

          // The list of all photos
          Map<?, ?> photoList = (Map<?, ?>) iPhotoLib.get("Master Image List");

          // The list of events (rolls)
          List<Map<?, ?>> listOfRolls = (List<Map<?, ?>>) iPhotoLib.get("List of Rolls");

          iPhotoVirtualFolder = new VirtualFolder("iPhoto Library", null);

          for (Map<?, ?> roll : listOfRolls) {
            Object rollName = roll.get("RollName");

            if (rollName != null) {
              VirtualFolder virtualFolder = new VirtualFolder(rollName.toString(), null);

              // List of photos in an event (roll)
              List<?> rollPhotos = (List<?>) roll.get("KeyList");

              for (Object photo : rollPhotos) {
                Map<?, ?> photoProperties = (Map<?, ?>) photoList.get(photo);

                if (photoProperties != null) {
                  Object imagePath = photoProperties.get("ImagePath");

                  if (imagePath != null) {
                    RealFile realFile = new RealFile(new File(imagePath.toString()));
                    virtualFolder.addChild(realFile);
                  }
                }
              }

              iPhotoVirtualFolder.addChild(virtualFolder);
View Full Code Here

   * Returns Aperture folder. Used by manageRoot, so it is usually used as
   * a folder at the root folder. Only works when PMS is run on Mac OS X.
   * TODO: Requirements for Aperture.
   */
  private DLNAResource getApertureFolder() {
    VirtualFolder res = null;

    if (Platform.isMac()) {
      Process process = null;

      try {
        process = Runtime.getRuntime().exec("defaults read com.apple.iApps ApertureLibraries");
        BufferedReader in = new BufferedReader(new InputStreamReader(process.getInputStream()));
        // Every line entry is one aperture library. We want all of them as a dlna folder.
        String line;
        res = new VirtualFolder("Aperture libraries", null);

        while ((line = in.readLine()) != null) {
          if (line.startsWith("(") || line.startsWith(")")) {
            continue;
          }

          line = line.trim(); // remove extra spaces
          line = line.substring(1, line.lastIndexOf("\"")); // remove quotes and spaces
          VirtualFolder apertureLibrary = createApertureDlnaLibrary(line);

          if (apertureLibrary != null) {
            res.addChild(apertureLibrary);
          }
        }
View Full Code Here

    return res;
  }

  private VirtualFolder createApertureDlnaLibrary(String url) throws UnsupportedEncodingException, MalformedURLException, XmlParseException, IOException, URISyntaxException {
    VirtualFolder res = null;

    if (url != null) {
      Map<String, Object> iPhotoLib;
      // every project is a album, too
      List<?> listOfAlbums;
      Map<?, ?> album;
      Map<?, ?> photoList;

      URI tURI = new URI(url);
      iPhotoLib = Plist.load(URLDecoder.decode(tURI.toURL().getFile(), System.getProperty("file.encoding"))); // loads the (nested) properties.
      photoList = (Map<?, ?>) iPhotoLib.get("Master Image List"); // the list of photos
      final Object mediaPath = iPhotoLib.get("Archive Path");
      String mediaName;

      if (mediaPath != null) {
        mediaName = mediaPath.toString();

        if (mediaName != null && mediaName.lastIndexOf("/") != -1 && mediaName.lastIndexOf(".aplibrary") != -1) {
          mediaName = mediaName.substring(mediaName.lastIndexOf("/"), mediaName.lastIndexOf(".aplibrary"));
        } else {
          mediaName = "unknown library";
        }
      } else {
        mediaName = "unknown library";
      }

      logger.info("Going to parse aperture library: " + mediaName);
      res = new VirtualFolder(mediaName, null);
      listOfAlbums = (List<?>) iPhotoLib.get("List of Albums"); // the list of events (rolls)

      for (Object item : listOfAlbums) {
        album = (Map<?, ?>) item;

        if (album.get("Parent") == null) {
          VirtualFolder vAlbum = createApertureAlbum(photoList, album, listOfAlbums);
          res.addChild(vAlbum);
        }
      }
    } else {
      logger.info("No Aperture library found.");
View Full Code Here

    Map<?, ?> album, List<?> listOfAlbums
  ) {

    List<?> albumPhotos;
    int albumId = (Integer) album.get("AlbumId");
    VirtualFolder vAlbum = new VirtualFolder(album.get("AlbumName").toString(), null);

    for (Object item : listOfAlbums) {
      Map<?, ?> sub = (Map<?, ?>) item;

      if (sub.get("Parent") != null) {
        // recursive album creation
        int parent = (Integer) sub.get("Parent");

        if (parent == albumId) {
          VirtualFolder subAlbum = createApertureAlbum(photoList, sub, listOfAlbums);
          vAlbum.addChild(subAlbum);
        }
      }
    }
View Full Code Here

        if (iTunesFile != null && (new File(iTunesFile)).exists()) {
          iTunesLib = Plist.load(URLDecoder.decode(iTunesFile, System.getProperty("file.encoding"))); // loads the (nested) properties.
          Tracks = (Map<?, ?>) iTunesLib.get("Tracks"); // the list of tracks
          Playlists = (List<?>) iTunesLib.get("Playlists"); // the list of Playlists
          res = new VirtualFolder("iTunes Library", null);

          VirtualFolder playlistsFolder = null;

          for (Object item : Playlists) {
            Playlist = (Map<?, ?>) item;

            if (Playlist.containsKey("Visible") && Playlist.get("Visible").equals(Boolean.FALSE))
              continue;

            if (Playlist.containsKey("Music") && Playlist.get("Music").equals(Boolean.TRUE)) {
              // Create virtual folders for artists, albums and genres

              VirtualFolder musicFolder = new VirtualFolder(Playlist.get("Name").toString(), null);
              res.addChild(musicFolder);

              VirtualFolder virtualFolderArtists = new VirtualFolder(Messages.getString("PMS.13"), null);
              VirtualFolder virtualFolderAlbums = new VirtualFolder(Messages.getString("PMS.16"), null);
              VirtualFolder virtualFolderGenres = new VirtualFolder(Messages.getString("PMS.19"), null);
              VirtualFolder virtualFolderAllTracks = new VirtualFolder(Messages.getString("PMS.11"), null);

              PlaylistTracks = (List<?>) Playlist.get("Playlist Items"); // list of tracks in a playlist

              String artistName;
              String albumName;
              String genreName;
              if (PlaylistTracks != null) {
                for (Object t : PlaylistTracks) {
                  Map<?, ?> td = (Map<?, ?>) t;
                  track = (Map<?, ?>) Tracks.get(td.get("Track ID").toString());

                  if (track != null && track.get("Location") != null && track.get("Location").toString().startsWith("file://")) {

                    String name = Normalizer.normalize((String)track.get("Name"), Normalizer.Form.NFC);
                    // remove dots from name to prevent media renderer from trimming
                    name = name.replace('.', '-');

                    if (track.containsKey("Protected") && track.get("Protected").equals(Boolean.TRUE))
                      name = String.format(Messages.getString("RootFolder.1"), name);

                    boolean isCompilation = (track.containsKey("Compilation") && track.get("Compilation").equals(Boolean.TRUE));

                    artistName = (String) (isCompilation ? "Compilation" :
                                 track.containsKey("Album Artist") ? track.get("Album Artist") : track.get("Artist"));
                    albumName = (String) track.get("Album");
                    genreName = (String) track.get("Genre");

                    if (artistName == null) {
                      artistName = "Unknown Artist";
                    } else {
                      artistName = Normalizer.normalize(artistName, Normalizer.Form.NFC);
                    }

                    if (albumName == null) {
                      albumName = "Unknown Album";
                    } else {
                      albumName = Normalizer.normalize(albumName, Normalizer.Form.NFC);
                    }

                    if (genreName == null) {
                      genreName = "Unknown Genre";
                    } else if ("".equals(genreName.replaceAll("[^a-zA-Z]", ""))) {
                      // This prevents us from adding blank or numerical genres
                      genreName = "Unknown Genre";
                    } else {
                      genreName = Normalizer.normalize(genreName, Normalizer.Form.NFC);
                    }

                    // Replace &nbsp with space and then trim
                    artistName = artistName.replace('\u0160', ' ').trim();
                    albumName = albumName.replace('\u0160', ' ').trim();
                    genreName = genreName.replace('\u0160', ' ').trim();

                    URI tURI2 = new URI(track.get("Location").toString());
                    File refFile = new File(URLDecoder.decode(tURI2.toURL().getFile(), "UTF-8"));
                    RealFile file = new RealFile(refFile, name);

                    // ARTISTS FOLDER - Put the track into the artist's album folder and the artist's "All tracks" folder
                    {
                      VirtualFolder individualArtistFolder = null;
                      VirtualFolder individualArtistAllTracksFolder = null;
                      VirtualFolder individualArtistAlbumFolder = null;

                      for (DLNAResource artist : virtualFolderArtists.getChildren()) {
                        if (areNamesEqual(artist.getName(), artistName)) {
                          individualArtistFolder = (VirtualFolder) artist;
                          for (DLNAResource album : individualArtistFolder.getChildren()) {
                            if (areNamesEqual(album.getName(), albumName)) {
                              individualArtistAlbumFolder = (VirtualFolder) album;
                            }
                          }
                          break;
                        }
                      }

                      if (individualArtistFolder == null) {
                        individualArtistFolder = new VirtualFolder(artistName, null);
                        virtualFolderArtists.addChild(individualArtistFolder);
                        individualArtistAllTracksFolder = new VirtualFolder(Messages.getString("PMS.11"), null);
                        individualArtistFolder.addChild(individualArtistAllTracksFolder);
                      } else {
                        individualArtistAllTracksFolder = (VirtualFolder)individualArtistFolder.getChildren().get(0);
                      }

                      if (individualArtistAlbumFolder == null) {
                        individualArtistAlbumFolder = new VirtualFolder(albumName, null);
                        individualArtistFolder.addChild(individualArtistAlbumFolder);
                      }

                      individualArtistAlbumFolder.addChild(file.clone());
                      individualArtistAllTracksFolder.addChild(file);
                    }

                    // ALBUMS FOLDER - Put the track into its album folder
                    {
                      if (!isCompilation)
                        albumName += " – " + artistName;

                      VirtualFolder individualAlbumFolder = null;
                      for (DLNAResource album : virtualFolderAlbums.getChildren()) {
                        if (areNamesEqual(album.getName(), albumName)) {
                          individualAlbumFolder = (VirtualFolder) album;
                          break;
                        }
                      }
                      if (individualAlbumFolder == null) {
                        individualAlbumFolder = new VirtualFolder(albumName, null);
                        virtualFolderAlbums.addChild(individualAlbumFolder);
                      }
                      individualAlbumFolder.addChild(file.clone());
                    }

                    // GENRES FOLDER - Put the track into its genre folder
                    {
                      VirtualFolder individualGenreFolder = null;
                      for (DLNAResource genre : virtualFolderGenres.getChildren()) {
                        if (areNamesEqual(genre.getName(), genreName)) {
                          individualGenreFolder = (VirtualFolder) genre;
                          break;
                        }
                      }
                      if (individualGenreFolder == null) {
                        individualGenreFolder = new VirtualFolder(genreName, null);
                        virtualFolderGenres.addChild(individualGenreFolder);
                      }
                      individualGenreFolder.addChild(file.clone());
                    }

                    // ALL TRACKS - Put the track into the global "All tracks" folder
                    virtualFolderAllTracks.addChild(file.clone());
                  }
                }
              }

              musicFolder.addChild(virtualFolderArtists);
              musicFolder.addChild(virtualFolderAlbums);
              musicFolder.addChild(virtualFolderGenres);
              musicFolder.addChild(virtualFolderAllTracks);

              // Sort the virtual folders alphabetically
              Collections.sort(virtualFolderArtists.getChildren(), new Comparator<DLNAResource>() {
                @Override
                public int compare(DLNAResource o1, DLNAResource o2) {
                  VirtualFolder a = (VirtualFolder) o1;
                  VirtualFolder b = (VirtualFolder) o2;
                  return a.getName().compareToIgnoreCase(b.getName());
                }
              });

              Collections.sort(virtualFolderAlbums.getChildren(), new Comparator<DLNAResource>() {
                @Override
                public int compare(DLNAResource o1, DLNAResource o2) {
                  VirtualFolder a = (VirtualFolder) o1;
                  VirtualFolder b = (VirtualFolder) o2;
                  return a.getName().compareToIgnoreCase(b.getName());
                }
              });

              Collections.sort(virtualFolderGenres.getChildren(), new Comparator<DLNAResource>() {
                @Override
                public int compare(DLNAResource o1, DLNAResource o2) {
                  VirtualFolder a = (VirtualFolder) o1;
                  VirtualFolder b = (VirtualFolder) o2;
                  return a.getName().compareToIgnoreCase(b.getName());
                }
              });

            } else {
              // Add all playlists
              VirtualFolder pf = new VirtualFolder(Playlist.get("Name").toString(), null);
              PlaylistTracks = (List<?>) Playlist.get("Playlist Items"); // list of tracks in a playlist

              if (PlaylistTracks != null) {
                for (Object t : PlaylistTracks) {
                  Map<?, ?> td = (Map<?, ?>) t;
                  track = (Map<?, ?>) Tracks.get(td.get("Track ID").toString());

                  if (track != null
                        && track.get("Location") != null
                        && track.get("Location").toString().startsWith("file://")
                      ) {
                    String name = Normalizer.normalize(track.get("Name").toString(), Normalizer.Form.NFC);
                    // remove dots from name to prevent media renderer from trimming
                    name = name.replace('.', '-');

                    if (track.containsKey("Protected") && track.get("Protected").equals(Boolean.TRUE))
                      name = String.format(Messages.getString("RootFolder.1"), name);

                    URI tURI2 = new URI(track.get("Location").toString());
                    RealFile file = new RealFile(new File(URLDecoder.decode(tURI2.toURL().getFile(), "UTF-8")), name);
                    pf.addChild(file);
                  }
                }
              }

              int kind = Playlist.containsKey("Distinguished Kind") ? ((Number)Playlist.get("Distinguished Kind")).intValue() : -1;
              if (kind >= 0 && kind != 17 && kind != 19 && kind != 20) {
                // System folder, but not voice memos (17) and purchased items (19 & 20)
                res.addChild(pf);

              } else {
                // User playlist or playlist folder
                if (playlistsFolder == null) {
                  playlistsFolder = new VirtualFolder("Playlists", null);
                  res.addChild(playlistsFolder);
                }
                playlistsFolder.addChild(pf);
              }
            }
View Full Code Here

   */
  private DLNAResource getVideoSettingsFolder() {
    DLNAResource res = null;

    if (!configuration.getHideVideoSettings()) {
      res = new VirtualFolder(Messages.getString("PMS.37"), null);
      VirtualFolder vfSub = new VirtualFolder(Messages.getString("PMS.8"), null);
      res.addChild(vfSub);

      res.addChild(new VirtualVideoAction(Messages.getString("PMS.3"), configuration.isMencoderNoOutOfSync()) {
        @Override
        public boolean enable() {
          configuration.setMencoderNoOutOfSync(!configuration.isMencoderNoOutOfSync());
          return configuration.isMencoderNoOutOfSync();
        }
      });

      res.addChild(new VirtualVideoAction("  !!-- Fix 23.976/25fps A/V Mismatch --!!", configuration.isFix25FPSAvMismatch()) {
        @Override
        public boolean enable() {
          configuration.setMencoderForceFps(!configuration.isFix25FPSAvMismatch());
          configuration.setFix25FPSAvMismatch(!configuration.isFix25FPSAvMismatch());
          return configuration.isFix25FPSAvMismatch();
        }
      });

      res.addChild(new VirtualVideoAction(Messages.getString("PMS.4"), configuration.isMencoderYadif()) {
        @Override
        public boolean enable() {
          configuration.setMencoderYadif(!configuration.isMencoderYadif());

          return configuration.isMencoderYadif();
        }
      });

      vfSub.addChild(new VirtualVideoAction(Messages.getString("TrTab2.51"), configuration.isDisableSubtitles()) {
        @Override
        public boolean enable() {
          boolean oldValue = configuration.isDisableSubtitles();
          boolean newValue = !oldValue;
          configuration.setDisableSubtitles(newValue);
          return newValue;
        }
      });

      vfSub.addChild(new VirtualVideoAction(Messages.getString("PMS.6"), configuration.isAutoloadExternalSubtitles()) {
        @Override
        public boolean enable() {
          boolean oldValue = configuration.isAutoloadExternalSubtitles();
          boolean newValue = !oldValue;
          configuration.setAutoloadExternalSubtitles(newValue);
          return newValue;
        }
      });

      vfSub.addChild(new VirtualVideoAction(Messages.getString("MEncoderVideo.36"), configuration.isMencoderAssDefaultStyle()) {
        @Override
        public boolean enable() {
          boolean oldValue = configuration.isMencoderAssDefaultStyle();
          boolean newValue = !oldValue;
          configuration.setMencoderAssDefaultStyle(newValue);
View Full Code Here

      for (Track track : tracks) {
        addChild(trackToStream(track));
      }
      for (Set set : sets)
      {
        VirtualFolder setFolder = new VirtualFolder(set.getTitle(), set.getArtworkUrl());
        for (Track track : set.getTracks()) {
          setFolder.addChild(trackToStream(track));
        }
        addChild(setFolder)
      }
    }
    this.refresh = false;
View Full Code Here

TOP

Related Classes of net.pms.dlna.virtual.VirtualFolder

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.