Search in sources :

Example 1 with VirtualVideoAction

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

the class DLNAResource method addDynamicPls.

private void addDynamicPls(final DLNAResource child) {
    final DLNAResource dynPls = PMS.get().getDynamicPls();
    if (dynPls == child || child.getParent() == dynPls) {
        return;
    }
    if (child instanceof VirtualVideoAction) {
        // ignore these
        return;
    }
    if (dynamicPls == null) {
        dynamicPls = new VirtualFolder(Messages.getString("PMS.147"), null);
        addChildInternal(dynamicPls);
        dynamicPls.addChild(dynPls);
    }
    if (dynamicPls != null) {
        String str = Messages.getString("PluginTab.9") + " " + child.getDisplayName() + " " + Messages.getString("PMS.148");
        VirtualVideoAction vva = new VirtualVideoAction(str, true) {

            @Override
            public boolean enable() {
                PMS.get().getDynamicPls().add(child);
                return true;
            }
        };
        vva.setParent(this);
        dynamicPls.addChildInternal(vva);
    }
}
Also used : VirtualFolder(net.pms.dlna.virtual.VirtualFolder) TranscodeVirtualFolder(net.pms.dlna.virtual.TranscodeVirtualFolder) VirtualVideoAction(net.pms.dlna.virtual.VirtualVideoAction)

Example 2 with VirtualVideoAction

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

the class MediaMonitor method scanDir.

public void scanDir(File[] files, final DLNAResource res) {
    if (files != null) {
        final DLNAResource mm = this;
        res.addChild(new VirtualVideoAction(Messages.getString("PMS.150"), true) {

            @Override
            public boolean enable() {
                for (DLNAResource r : res.getChildren()) {
                    if (!(r instanceof RealFile)) {
                        continue;
                    }
                    RealFile rf = (RealFile) r;
                    MediaMonitor.setFullyPlayed(rf.getFile().getAbsolutePath(), true);
                }
                mm.setDiscovered(false);
                mm.getChildren().clear();
                return true;
            }
        });
        Set<String> fullyPlayedPaths = null;
        if (config.isHideEmptyFolders()) {
            fullyPlayedPaths = new HashSet<>();
            fullyPlayedEntriesLock.readLock().lock();
            try {
                for (Entry<String, Boolean> entry : fullyPlayedEntries.entrySet()) {
                    if (entry.getValue()) {
                        fullyPlayedPaths.add(entry.getKey());
                    }
                }
            } finally {
                fullyPlayedEntriesLock.readLock().unlock();
            }
        }
        for (File fileEntry : files) {
            if (fileEntry.isFile()) {
                if (isFullyPlayed(fileEntry.getAbsolutePath())) {
                    continue;
                }
                res.addChild(new RealFile(fileEntry));
            }
            if (fileEntry.isDirectory()) {
                boolean add = !config.isHideEmptyFolders();
                if (!add) {
                    add = FileUtil.isFolderRelevant(fileEntry, config, fullyPlayedPaths);
                }
                if (add) {
                    res.addChild(new MonitorEntry(fileEntry, this));
                }
            }
        }
    }
}
Also used : VirtualVideoAction(net.pms.dlna.virtual.VirtualVideoAction)

Example 3 with VirtualVideoAction

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

the class RemotePlayHandler method mkPage.

private String mkPage(String id, HttpExchange t) throws IOException {
    HashMap<String, Object> vars = new HashMap<>();
    vars.put("serverName", configuration.getServerDisplayName());
    LOGGER.debug("Make play page " + id);
    RootFolder root = parent.getRoot(RemoteUtil.userName(t), t);
    if (root == null) {
        LOGGER.debug("root not found");
        throw new IOException("Unknown root");
    }
    WebRender renderer = (WebRender) root.getDefaultRenderer();
    renderer.setBrowserInfo(RemoteUtil.getCookie("UMSINFO", t), t.getRequestHeaders().getFirst("User-agent"));
    // List<DLNAResource> res = root.getDLNAResources(id, false, 0, 0, renderer);
    DLNAResource r = root.getDLNAResource(id, renderer);
    if (r == null) {
        LOGGER.debug("Bad web play id: " + id);
        throw new IOException("Bad Id");
    }
    if (!r.isCodeValid(r)) {
        LOGGER.debug("coded object with invalid code");
        throw new IOException("Bad code");
    }
    if (r instanceof VirtualVideoAction) {
        // waste of resource to play dummy video
        if (((VirtualVideoAction) r).enable()) {
            renderer.notify(renderer.INFO, r.getName() + " enabled");
        } else {
            renderer.notify(renderer.INFO, r.getName() + " disabled");
        }
        return returnPage();
    }
    Format format = r.getFormat();
    boolean isImage = format.isImage();
    boolean isVideo = format.isVideo();
    boolean isAudio = format.isAudio();
    String query = t.getRequestURI().getQuery();
    boolean forceFlash = StringUtils.isNotEmpty(RemoteUtil.getQueryVars(query, "flash"));
    boolean forcehtml5 = StringUtils.isNotEmpty(RemoteUtil.getQueryVars(query, "html5"));
    boolean flowplayer = isVideo && (forceFlash || (!forcehtml5 && configuration.getWebFlash()));
    // hack here to ensure we got a root folder to use for recently played etc.
    root.getDefaultRenderer().setRootFolder(root);
    String id1 = URLEncoder.encode(id, "UTF-8");
    String name = StringEscapeUtils.escapeHtml(r.resumeName());
    String mime = root.getDefaultRenderer().getMimeType(r.mimeType(), r.getMedia());
    String mediaType = isVideo ? "video" : isAudio ? "audio" : isImage ? "image" : "";
    String auto = "autoplay";
    @SuppressWarnings("unused") String coverImage = "";
    if (isVideo) {
        if (mime.equals(FormatConfiguration.MIMETYPE_AUTO)) {
            if (r.getMedia() != null && r.getMedia().getMimeType() != null) {
                mime = r.getMedia().getMimeType();
            }
        }
        if (!flowplayer) {
            if (!RemoteUtil.directmime(mime) || RemoteUtil.transMp4(mime, r.getMedia()) || r.isResume()) {
                WebRender render = (WebRender) r.getDefaultRenderer();
                mime = render != null ? render.getVideoMimeType() : RemoteUtil.transMime();
            }
        }
    }
    vars.put("isVideo", isVideo);
    vars.put("name", name);
    vars.put("id1", id1);
    vars.put("autoContinue", configuration.getWebAutoCont(format));
    if (configuration.isDynamicPls()) {
        if (r.getParent() instanceof Playlist) {
            vars.put("plsOp", "del");
            vars.put("plsSign", "-");
            vars.put("plsAttr", RemoteUtil.getMsgString("Web.4", t));
        } else {
            vars.put("plsOp", "add");
            vars.put("plsSign", "+");
            vars.put("plsAttr", RemoteUtil.getMsgString("Web.5", t));
        }
    }
    addNextByType(r, vars);
    if (isImage) {
        // do this like this to simplify the code
        // skip all player crap since img tag works well
        int delay = configuration.getWebImgSlideDelay() * 1000;
        if (delay > 0 && configuration.getWebAutoCont(format)) {
            vars.put("delay", delay);
        }
    } else {
        vars.put("mediaType", mediaType);
        vars.put("auto", auto);
        vars.put("mime", mime);
        if (flowplayer) {
            if (RemoteUtil.directmime(mime) && !RemoteUtil.transMp4(mime, r.getMedia()) && !r.isResume() && !forceFlash) {
                vars.put("src", true);
            }
        } else {
            vars.put("width", renderer.getVideoWidth());
            vars.put("height", renderer.getVideoHeight());
        }
    }
    if (configuration.useWebControl()) {
        vars.put("push", true);
    }
    if (isVideo && configuration.getWebSubs()) {
        // only if subs are requested as <track> tags
        // otherwise we'll transcode them in
        boolean isFFmpegFontConfig = configuration.isFFmpegFontConfig();
        if (isFFmpegFontConfig) {
            // do not apply fontconfig to flowplayer subs
            configuration.setFFmpegFontConfig(false);
        }
        OutputParams p = new OutputParams(configuration);
        p.sid = r.getMediaSubtitle();
        Player.setAudioAndSubs(r.getName(), r.getMedia(), p);
        if (p.sid != null && p.sid.getType().isText()) {
            try {
                File subFile = SubtitleUtils.getSubtitles(r, r.getMedia(), p, configuration, SubtitleType.WEBVTT);
                LOGGER.debug("subFile " + subFile);
                if (subFile != null) {
                    vars.put("sub", parent.getResources().add(subFile));
                }
            } catch (Exception e) {
                LOGGER.debug("error when doing sub file " + e);
            }
        }
        // return back original fontconfig value
        configuration.setFFmpegFontConfig(isFFmpegFontConfig);
    }
    return parent.getResources().getTemplate(isImage ? "image.html" : flowplayer ? "flow.html" : "play.html").execute(vars);
}
Also used : WebRender(net.pms.configuration.WebRender) HashMap(java.util.HashMap) IOException(java.io.IOException) IOException(java.io.IOException) DLNAResource(net.pms.dlna.DLNAResource) Playlist(net.pms.dlna.Playlist) Format(net.pms.formats.Format) VirtualVideoAction(net.pms.dlna.virtual.VirtualVideoAction) RootFolder(net.pms.dlna.RootFolder) OutputParams(net.pms.io.OutputParams) File(java.io.File)

Example 4 with VirtualVideoAction

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

the class Playlist method discoverChildren.

@Override
public void discoverChildren() {
    if (list.size() > 0) {
        final Playlist self = this;
        // Save
        if (!isMode(AUTOSAVE)) {
            addChild(new VirtualVideoAction(Messages.getString("LooksFrame.9"), true) {

                @Override
                public boolean enable() {
                    self.save();
                    return true;
                }
            });
        }
        // Clear
        addChild(new VirtualVideoAction(Messages.getString("TracesTab.3"), true) {

            @Override
            public boolean enable() {
                self.clear();
                return true;
            }
        });
    }
    for (DLNAResource r : list) {
        // addchild might clear the masterparent
        // so fetch it first and readd
        ExternalListener master = r.getMasterParent();
        addChild(r);
        r.setMasterParent(master);
        if (r.isResume()) {
            // add this non resume after
            DLNAResource clone = r.clone();
            clone.setResume(null);
            addChild(clone);
            clone.setMasterParent(master);
        }
    }
}
Also used : VirtualVideoAction(net.pms.dlna.virtual.VirtualVideoAction) ExternalListener(net.pms.external.ExternalListener)

Example 5 with VirtualVideoAction

use of net.pms.dlna.virtual.VirtualVideoAction 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)

Aggregations

VirtualVideoAction (net.pms.dlna.virtual.VirtualVideoAction)7 VirtualFolder (net.pms.dlna.virtual.VirtualFolder)3 IOException (java.io.IOException)2 HashMap (java.util.HashMap)2 DLNAResource (net.pms.dlna.DLNAResource)2 Playlist (net.pms.dlna.Playlist)2 RootFolder (net.pms.dlna.RootFolder)2 ConfigurationException (org.apache.commons.configuration.ConfigurationException)2 Headers (com.sun.net.httpserver.Headers)1 File (java.io.File)1 MalformedURLException (java.net.MalformedURLException)1 URISyntaxException (java.net.URISyntaxException)1 ArrayList (java.util.ArrayList)1 DownloadPlugins (net.pms.configuration.DownloadPlugins)1 WebRender (net.pms.configuration.WebRender)1 CodeEnter (net.pms.dlna.CodeEnter)1 TranscodeVirtualFolder (net.pms.dlna.virtual.TranscodeVirtualFolder)1 ExternalListener (net.pms.external.ExternalListener)1 Format (net.pms.formats.Format)1 OutputParams (net.pms.io.OutputParams)1