Search in sources :

Example 6 with VirtualFolder

use of net.pms.dlna.virtual.VirtualFolder in project UniversalMediaServer by UniversalMediaServer.

the class RootFolder method getVideoSettingsFolder.

/**
 * Returns Video Settings folder. Used by manageRoot, so it is usually
 * used as a folder at the root folder. Child objects are created when
 * this folder is created.
 */
private DLNAResource getVideoSettingsFolder() {
    DLNAResource res = null;
    if (configuration.isShowServerSettingsFolder()) {
        res = new VirtualFolder(Messages.getString("PMS.37"), null);
        VirtualFolder vfSub = new VirtualFolder(Messages.getString("PMS.8"), null);
        res.addChild(vfSub);
        if (configuration.useCode() && !PMS.get().masterCodeValid() && StringUtils.isNotEmpty(PMS.get().codeDb().lookup(CodeDb.MASTER))) {
            // if the master code is valid we don't add this
            VirtualVideoAction vva = new VirtualVideoAction("MasterCode", true) {

                @Override
                public boolean enable() {
                    CodeEnter ce = (CodeEnter) getParent();
                    if (ce.validCode(this)) {
                        PMS.get().setMasterCode(ce);
                        return true;
                    }
                    return false;
                }
            };
            CodeEnter ce1 = new CodeEnter(vva);
            ce1.setCode(CodeDb.MASTER);
            res.addChild(ce1);
        }
        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(Messages.getString("PMS.14"), configuration.isMencoderMuxWhenCompatible()) {

            @Override
            public boolean enable() {
                configuration.setMencoderMuxWhenCompatible(!configuration.isMencoderMuxWhenCompatible());
                return configuration.isMencoderMuxWhenCompatible();
            }
        });
        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("MEncoderVideo.22"), 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.isUseEmbeddedSubtitlesStyle()) {

            @Override
            public boolean enable() {
                boolean oldValue = configuration.isUseEmbeddedSubtitlesStyle();
                boolean newValue = !oldValue;
                configuration.setUseEmbeddedSubtitlesStyle(newValue);
                return newValue;
            }
        });
        res.addChild(new VirtualVideoAction(Messages.getString("MEncoderVideo.0"), configuration.getSkipLoopFilterEnabled()) {

            @Override
            public boolean enable() {
                configuration.setSkipLoopFilterEnabled(!configuration.getSkipLoopFilterEnabled());
                return configuration.getSkipLoopFilterEnabled();
            }
        });
        res.addChild(new VirtualVideoAction(Messages.getString("TrTab2.28"), configuration.isAudioEmbedDtsInPcm()) {

            @Override
            public boolean enable() {
                configuration.setAudioEmbedDtsInPcm(!configuration.isAudioEmbedDtsInPcm());
                return configuration.isAudioEmbedDtsInPcm();
            }
        });
        res.addChild(new VirtualVideoAction(Messages.getString("PMS.27"), true) {

            @Override
            public boolean enable() {
                try {
                    configuration.save();
                } catch (ConfigurationException e) {
                    LOGGER.debug("Caught exception", e);
                }
                return true;
            }
        });
        res.addChild(new VirtualVideoAction(Messages.getString("LooksFrame.12"), true) {

            @Override
            public boolean enable() {
                PMS.get().reset();
                return true;
            }
        });
        res.addChild(new VirtualVideoAction(Messages.getString("FoldTab.42"), configuration.isShowLiveSubtitlesFolder()) {

            @Override
            public boolean enable() {
                configuration.setShowLiveSubtitlesFolder(configuration.isShowLiveSubtitlesFolder());
                return configuration.isShowLiveSubtitlesFolder();
            }
        });
    }
    return res;
}
Also used : VirtualFolder(net.pms.dlna.virtual.VirtualFolder) ConfigurationException(org.apache.commons.configuration.ConfigurationException) VirtualVideoAction(net.pms.dlna.virtual.VirtualVideoAction)

Example 7 with VirtualFolder

use of net.pms.dlna.virtual.VirtualFolder in project UniversalMediaServer by UniversalMediaServer.

the class RootFolder method getiPhotoFolder.

/**
 * Creates, populates and returns a virtual folder mirroring the
 * contents of the system's iPhoto folder.
 * 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);
                    }
                }
            } else {
                LOGGER.info("iPhoto folder not found");
            }
        } catch (XmlParseException | URISyntaxException | IOException e) {
            LOGGER.error("Something went wrong with the iPhoto Library scan: ", e);
        } finally {
            IOUtils.closeQuietly(inputStream);
        }
    }
    return iPhotoVirtualFolder;
}
Also used : VirtualFolder(net.pms.dlna.virtual.VirtualFolder) XmlParseException(xmlwise.XmlParseException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) URL(java.net.URL)

Example 8 with VirtualFolder

use of net.pms.dlna.virtual.VirtualFolder in project UniversalMediaServer by UniversalMediaServer.

the class RootFolder method addWebFolder.

private void addWebFolder(File webConf) {
    try {
        try (LineNumberReader br = new LineNumberReader(new InputStreamReader(new FileInputStream(webConf), StandardCharsets.UTF_8))) {
            String line;
            while ((line = br.readLine()) != null) {
                line = line.trim();
                if (line.length() > 0 && !line.startsWith("#") && line.indexOf('=') > -1) {
                    String key = line.substring(0, line.indexOf('='));
                    String value = line.substring(line.indexOf('=') + 1);
                    String[] keys = parseFeedKey(key);
                    try {
                        if (keys[0].equals("imagefeed") || keys[0].equals("audiofeed") || keys[0].equals("videofeed") || keys[0].equals("audiostream") || keys[0].equals("videostream")) {
                            String[] values = parseFeedValue(value);
                            DLNAResource parent = null;
                            if (keys[1] != null) {
                                StringTokenizer st = new StringTokenizer(keys[1], ",");
                                DLNAResource currentRoot = this;
                                while (st.hasMoreTokens()) {
                                    String folder = st.nextToken();
                                    parent = currentRoot.searchByName(folder);
                                    if (parent == null) {
                                        parent = new VirtualFolder(folder, "");
                                        if (currentRoot == this) {
                                            // parent is a top-level web folder
                                            webFolders.add(parent);
                                        }
                                        currentRoot.addChild(parent);
                                    }
                                    currentRoot = parent;
                                }
                            }
                            if (parent == null) {
                                parent = this;
                            }
                            if (keys[0].endsWith("stream")) {
                                int type = keys[0].startsWith("audio") ? Format.AUDIO : Format.VIDEO;
                                DLNAResource playlist = PlaylistFolder.getPlaylist(values[0], values[1], type);
                                if (playlist != null) {
                                    parent.addChild(playlist);
                                    continue;
                                }
                            }
                            switch(keys[0]) {
                                case "imagefeed":
                                    parent.addChild(new ImagesFeed(values[0]));
                                    break;
                                case "videofeed":
                                    parent.addChild(new VideosFeed(values[0]));
                                    break;
                                case "audiofeed":
                                    parent.addChild(new AudiosFeed(values[0]));
                                    break;
                                case "audiostream":
                                    parent.addChild(new WebAudioStream(values[0], values[1], values[2]));
                                    break;
                                case "videostream":
                                    parent.addChild(new WebVideoStream(values[0], values[1], values[2]));
                                    break;
                                default:
                                    break;
                            }
                        }
                    } catch (ArrayIndexOutOfBoundsException e) {
                        // catch exception here and go with parsing
                        LOGGER.info("Error at line " + br.getLineNumber() + " of WEB.conf: " + e.getMessage());
                        LOGGER.debug(null, e);
                    }
                }
            }
        }
    } catch (FileNotFoundException e) {
        LOGGER.debug("Can't read web configuration file {}", e.getMessage());
    } catch (IOException e) {
        LOGGER.warn("Unexpected error in WEB.conf: " + e.getMessage());
        LOGGER.debug("", e);
    }
}
Also used : VirtualFolder(net.pms.dlna.virtual.VirtualFolder)

Example 9 with VirtualFolder

use of net.pms.dlna.virtual.VirtualFolder in project UniversalMediaServer by UniversalMediaServer.

the class RootFolder method createApertureAlbum.

private VirtualFolder createApertureAlbum(Map<?, ?> photoList, 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);
            }
        }
    }
    albumPhotos = (List<?>) album.get("KeyList");
    if (albumPhotos == null) {
        return vAlbum;
    }
    boolean firstPhoto = true;
    for (Object photoKey : albumPhotos) {
        Map<?, ?> photo = (Map<?, ?>) photoList.get(photoKey);
        if (firstPhoto) {
            Object x = photoList.get("ThumbPath");
            if (x != null) {
                vAlbum.setThumbnail(x.toString());
            }
            firstPhoto = false;
        }
        RealFile file = new RealFile(new File(photo.get("ImagePath").toString()));
        vAlbum.addChild(file);
    }
    return vAlbum;
}
Also used : VirtualFolder(net.pms.dlna.virtual.VirtualFolder)

Example 10 with VirtualFolder

use of net.pms.dlna.virtual.VirtualFolder in project UniversalMediaServer by UniversalMediaServer.

the class RootFolder method addAdminFolder.

private void addAdminFolder() {
    DLNAResource res = new VirtualFolder(Messages.getString("PMS.131"), null);
    DLNAResource vsf = getVideoSettingsFolder();
    if (vsf != null) {
        res.addChild(vsf);
    }
    res.addChild(new VirtualFolder(Messages.getString("NetworkTab.39"), null) {

        @Override
        public void discoverChildren() {
            final ArrayList<DownloadPlugins> plugins = DownloadPlugins.downloadList();
            for (final DownloadPlugins plugin : plugins) {
                addChild(new VirtualVideoAction(plugin.getName(), true) {

                    @Override
                    public boolean enable() {
                        try {
                            plugin.install(null);
                        } catch (Exception e) {
                        }
                        return true;
                    }
                });
            }
        }
    });
    if (configuration.getScriptDir() != null) {
        final File scriptDir = new File(configuration.getScriptDir());
        if (scriptDir.exists()) {
            res.addChild(new VirtualFolder(Messages.getString("PMS.132"), null) {

                @Override
                public void discoverChildren() {
                    File[] files = scriptDir.listFiles();
                    if (files != null) {
                        for (File file : files) {
                            String name = file.getName().replaceAll("_", " ");
                            int pos = name.lastIndexOf('.');
                            if (pos != -1) {
                                name = name.substring(0, pos);
                            }
                            final File f = file;
                            addChild(new VirtualVideoAction(name, true) {

                                @Override
                                public boolean enable() {
                                    try {
                                        ProcessBuilder pb = new ProcessBuilder(f.getAbsolutePath());
                                        pb.redirectErrorStream(true);
                                        Process pid = pb.start();
                                        // consume the error and output process streams
                                        StreamGobbler.consume(pid.getInputStream());
                                        pid.waitFor();
                                    } catch (IOException | InterruptedException e) {
                                    }
                                    return true;
                                }
                            });
                        }
                    }
                }
            });
        }
    }
    // Resume file management
    if (configuration.isResumeEnabled()) {
        res.addChild(new VirtualFolder(Messages.getString("PMS.135"), null) {

            @Override
            public void discoverChildren() {
                final File[] files = ResumeObj.resumeFiles();
                addChild(new VirtualVideoAction(Messages.getString("PMS.136"), true) {

                    @Override
                    public boolean enable() {
                        for (File f : files) {
                            f.delete();
                        }
                        getParent().getChildren().remove(this);
                        return false;
                    }
                });
                for (final File f : files) {
                    String name = FileUtil.getFileNameWithoutExtension(f.getName());
                    name = name.replaceAll(ResumeObj.CLEAN_REG, "");
                    addChild(new VirtualVideoAction(name, false) {

                        @Override
                        public boolean enable() {
                            f.delete();
                            getParent().getChildren().remove(this);
                            return false;
                        }
                    });
                }
            }
        });
    }
    // Reboot UMS
    res.addChild(new VirtualVideoAction(Messages.getString("PMS.149"), true) {

        @Override
        public boolean enable() {
            ProcessUtil.reboot();
            // Reboot failed if we get here
            return false;
        }
    });
    addChild(res);
}
Also used : VirtualFolder(net.pms.dlna.virtual.VirtualFolder) URISyntaxException(java.net.URISyntaxException) XmlParseException(xmlwise.XmlParseException) MalformedURLException(java.net.MalformedURLException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) VirtualVideoAction(net.pms.dlna.virtual.VirtualVideoAction) DownloadPlugins(net.pms.configuration.DownloadPlugins)

Aggregations

VirtualFolder (net.pms.dlna.virtual.VirtualFolder)10 URISyntaxException (java.net.URISyntaxException)4 ConfigurationException (org.apache.commons.configuration.ConfigurationException)4 XmlParseException (xmlwise.XmlParseException)4 MalformedURLException (java.net.MalformedURLException)3 URI (java.net.URI)3 VirtualVideoAction (net.pms.dlna.virtual.VirtualVideoAction)3 TranscodeVirtualFolder (net.pms.dlna.virtual.TranscodeVirtualFolder)2 URL (java.net.URL)1 DownloadPlugins (net.pms.configuration.DownloadPlugins)1 AdditionalResourceFolderListener (net.pms.external.AdditionalResourceFolderListener)1 ExternalListener (net.pms.external.ExternalListener)1