Bläddra i källkod

added some logic for playlist parsing overrides

LH 6 år sedan
förälder
incheckning
28b75b51c0

+ 16 - 6
iZpl/src/main/java/de/nplusc/izc/iZpl/CommandLineParsing.java

@@ -66,7 +66,7 @@ public class CommandLineParsing
         Options options = new Options();
         OptionGroup modes = new OptionGroup();
         OptionGroup uimodes = new OptionGroup();
-        
+        String optionpath = null;
         
         //gopvsferbicuxmh
         //bcefghimoprsuvx
@@ -75,10 +75,16 @@ public class CommandLineParsing
                 .create("g"));
         uimodes.addOption(OptionBuilder.withLongOpt("oldgui")
                 .withDescription("enables External VLC Player UIMode. Starts program straight if --file or --resume is set")
-                .create("o"));
+                .create());
         options.addOption("p", "pregen", false, "Pregens a standalone playlist with the randomisation included. Use togehter only with --file");
         //options.addOption("v", "verbose", false, "Enables verbose logging");
         
+                options.addOption(OptionBuilder.withLongOpt("optionfile")
+                .withDescription("uses the given options yml for playlist loading.")
+                .hasArg()
+                .withArgName("OptionFile")
+                .create("o"));
+        
         options.addOption(OptionBuilder.withLongOpt("verbose")
                 .withDescription("Enables verbose logging. Optionally sets verbosity level")
                 .hasOptionalArg()
@@ -208,7 +214,10 @@ public class CommandLineParsing
             quickQuit();
         }
         
-
+        if(cl.hasOption("optionfile"))
+        {
+            optionpath = cl.getOptionValue("optionfile");
+        }
         
         if (cl.hasOption("resume"))
         {
@@ -307,9 +316,10 @@ public class CommandLineParsing
         {
             allowPluginLoad=true;
         }
-        return new CommandLineStatus(filemode, statefile, verboseMode, verboseLevel,burnDisc, file_path, burnDisc, forcePregen, featurePluginMode,
-                featurePluginID, pluginParameter, loadConfigMode, menumode, firstrunmode, updateInit, 
-                allowPluginLoad,skinParameterSet,selectedSkinPath,uimodestate,streamport>0,streamport);
+        return new CommandLineStatus(filemode, statefile, verboseMode, verboseLevel,burnDisc, file_path,
+                burnDisc, forcePregen, featurePluginMode, featurePluginID, pluginParameter, loadConfigMode,
+                menumode, firstrunmode, updateInit, allowPluginLoad, skinParameterSet, selectedSkinPath,
+                uimodestate, streamport>0, streamport, optionpath);
     }
 
     private CommandLineParsing()

+ 5 - 2
iZpl/src/main/java/de/nplusc/izc/iZpl/CommandLineStatus.java

@@ -50,6 +50,7 @@ public class CommandLineStatus
     public final int uimodestate;
     public final boolean streaming;
     public final int streamport;
+    public final String optionpath;
     
     
     
@@ -57,7 +58,7 @@ public class CommandLineStatus
             String file_path, boolean burnDisc, boolean forcePregen, boolean featurePluginMode, 
             String featurePluginID, 
             String pluginParameter, boolean loadConfigMode, boolean menumode, boolean firstrunmode, boolean updateInit, boolean allowPluginLoad,boolean skinParameterSet,
-            String selectedSkinPath,int uimodestate,boolean streaming,int streamport)
+            String selectedSkinPath,int uimodestate,boolean streaming,int streamport, String optionpath)
     {
         this.filemode = filemode;
         this.statefile = statefile;
@@ -80,6 +81,7 @@ public class CommandLineStatus
         this.uimodestate=uimodestate;
         this.streaming=streaming;
         this.streamport=streamport;
+        this.optionpath = optionpath;
     }
     
     
@@ -87,7 +89,8 @@ public class CommandLineStatus
     public CommandLineStatus changeUseGUI(boolean pGUI)
     {
         return new CommandLineStatus(filemode, statefile, verboseMode,verboseLevel, pGUI, file_path, burnDisc, forcePregen, featurePluginMode,
-                featurePluginID, pluginParameter, loadConfigMode, menumode, firstrunmode, updateInit, allowPluginLoad,skinParameterSet,selectedSkinPath,uimodestate,streaming,streamport);
+                featurePluginID, pluginParameter, loadConfigMode, menumode, firstrunmode, updateInit, allowPluginLoad, skinParameterSet,
+                selectedSkinPath, uimodestate, streaming, streamport, optionpath);
     }
     
     

+ 46 - 8
iZpl/src/main/java/de/nplusc/izc/iZpl/Main.java

@@ -42,6 +42,7 @@ import java.io.FileWriter;
 import java.io.IOException;
 import java.util.Base64;
 import java.util.Date;
+import java.util.HashMap;
 import java.util.function.BiConsumer;
 import javax.imageio.ImageIO;
 import javax.swing.JTextArea;
@@ -86,7 +87,7 @@ public class Main extends javax.swing.JFrame
     private static PluginManager p = new PluginManager();
     private static Logger l;
     
-    private static boolean loadedVLC = false;
+    private static boolean programLoaded = false;
     private static PLServer ps = null;
     private static boolean issueDetected = false;
     
@@ -251,7 +252,7 @@ public class Main extends javax.swing.JFrame
             verboseLevel=stts.verboseLevel;
         }
         stts=new CommandLineStatus(filemode, statefile, vm, verboseLevel,true, file_path, burnDisc, forcePregen, 
-                featurePluginMode, featurePluginID, null, loadConfigMode, menumode, false,false, allowPluginLoad,false,null,UIMODE_NONE,false,0);
+                featurePluginMode, featurePluginID, null, loadConfigMode, menumode, false,false, allowPluginLoad,false,null,UIMODE_NONE,false,0,null);
         mainProcessing();
     }
     
@@ -421,7 +422,7 @@ public class Main extends javax.swing.JFrame
                 {
                     try
                     {
-                        while (!loadedVLC)
+                        while (!programLoaded)
                         {
                             Thread.sleep(150);
                         }
@@ -488,7 +489,40 @@ public class Main extends javax.swing.JFrame
         }
         try
         {
-            l.trace("fpl|" + stts.forcePregen + "|shitmp|" + isShittyPlayer + "|a1|" + stts.file_path + "|vp|" + vlcpath);
+            l.trace("fpl|" + stts.forcePregen + "|shitmp|" + isShittyPlayer + "|a1|" + stts.file_path + "|vp|" + vlcpath +"|optionspath|"+stts.optionpath);
+            HashMap<String,String> options = new HashMap<>();
+            if(stts.optionpath!=null)
+            {
+                File f = new File(stts.optionpath);
+                if(f.exists())
+                {
+                    try
+                    {
+                        FileReader r = new FileReader(f);
+                        options = (HashMap<String, String>) new Yaml().load(r);
+                    }
+                    catch(IOException e)
+                    {
+                        l.error("Invalid Options file {}. IO Error!",stts.optionpath);
+                        quickQuit();
+                    }
+                    catch(ClassCastException e)
+                    {
+                        l.error("Invalid Options file {}. wrong format!",stts.optionpath);
+                        quickQuit();
+                    }
+
+                }
+                else
+                {
+                    l.error("Invalid Options file {}. File does not exist!",stts.optionpath);
+                    quickQuit();
+                }
+            }
+            else
+            {
+                l.trace("No options to parse");
+            }
             if (
                     (stts.filemode && !(stts.forcePregen || isShittyPlayer))                      ||
                     (stts.featurePluginMode&&p.getSelectedFeaturePlugin().requiresLoadedPlayList()))
@@ -496,7 +530,7 @@ public class Main extends javax.swing.JFrame
                 l.trace("usegui=" + stts.useGUI);
                 l.trace("featurePlugin=" + stts.featurePluginMode);
                 
-                ps = new PLServer(/*"D:\\mp3\\iZpl\\rxe.izpl"/*/stts.file_path/**/, !(stts.useGUI||stts.featurePluginMode));//DBG_CD3
+                ps = new PLServer(/*"D:\\mp3\\iZpl\\rxe.izpl"/*/stts.file_path/**/, !(stts.useGUI||stts.featurePluginMode), options);//DBG_CD3
                 if (issueDetected)
                 {
                     quickQuit();
@@ -517,8 +551,12 @@ public class Main extends javax.swing.JFrame
             //http://localhost:9263/lst.m3u
             if (isShittyPlayer || stts.forcePregen)
             {
+
+                
                 PlProcessorV2 ppp = new PlProcessorV2();
+                ppp.setOptions(options);
                 ppp.InitializeOnPath(stts.file_path);
+
                 if (issueDetected)
                 {
                     quickQuit();
@@ -557,19 +595,19 @@ public class Main extends javax.swing.JFrame
                         p.getSelectedUIPlugin().initializeUI();
                         p.getSelectedUIPlugin().setVisible(true);
                     });
-                    loadedVLC = true;
+                    programLoaded = true;
                 }
                 else
                 {
                     if(stts.featurePluginMode)
                     {
                         p.getSelectedFeaturePlugin().parseParameter(stts.pluginParameter);
-                    loadedVLC = true;
+                    programLoaded = true;
                     }
                     else
                     {
                         boolean crashed = false;
-                        loadedVLC = true;
+                        programLoaded = true;
                         do
                         {
                             crashed = Tools.runCmdStreamable(null, IoBuilder.forLogger("External").buildPrintStream(), false, vlcpath, "--extraintf=cad",/* qt4"--extraintf=http:logger","--verbose=2","--file-logging","--logfile=vlc-log.txt",*/ "http://localhost:9263/rcvr/lst.m3u");//http://localhost:9263/lst.m3u");

+ 115 - 111
iZpl/src/main/java/de/nplusc/izc/iZpl/PLServer.java

@@ -1,111 +1,115 @@
-/*
- * Copyright (C) 2015 iZc
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- */
-package de.nplusc.izc.iZpl;
-
-import com.sun.net.httpserver.HttpServer;
-import de.nplusc.izc.tools.baseTools.Messagers;
-import java.io.IOException;
-import java.net.BindException;
-import java.net.InetSocketAddress;
-import org.apache.logging.log4j.LogManager;
-import org.apache.logging.log4j.Logger;
-
-/**
- *
- * @author LH
- */
-public class PLServer
-{
-    private static final Logger l = LogManager.getLogger();
-    public static PlProcessorV2 ppp=null;
-    
-    public PlProcessorV2 getPlProcessorV2()
-    {
-        return ppp;
-    }
-    
-    
-    public PLServer(String plPath)
-    {
-        this(plPath, true);
-    }
-    
-    public PLServer(String plPath,boolean serverOn)
-    {
-        try
-        {
-            
-            
-            ppp = new PlProcessorV2();
-            ppp.InitializeOnPath(plPath);
-            if(serverOn)
-            {
-                l.info("Serving");
-                HttpServer server = HttpServer.create(new InetSocketAddress("localhost",9263), 0);//,InetAddress.getByName("localhost"));
-                server.createContext("/", ppp);//nimmt jeden beliebigen namen an
-                server.createContext("/reload",new ReloadMgr(ppp));
-                server.createContext("/rcvr",new ReInitializer());
-                server.createContext("/edit",new EditorLoader());
-                server.setExecutor(null); // creates a default executor
-                server.start();
-            }
-        }
-        catch(BindException xxx)
-        {
-            Messagers.SingleLineMsg("iZpl bereits gestartt; keine 2 instanzen möglich", "OKAY");
-            System.exit(9263);
-        }
-        catch (IOException ex)
-        {
-            ex.printStackTrace();
-        }
-    }
-    
-    public PLServer(PlProcessorV2 pp)
-    {
-        this(pp, true);
-    }
-    
-    public PLServer(PlProcessorV2 pp,boolean serverOn)
-    {
-        try
-        {
-            
-            
-            ppp=pp;
-            if(serverOn)
-            {
-                HttpServer server = HttpServer.create(new InetSocketAddress("localhost",9263), 0);//,InetAddress.getByName("localhost"));
-                server.createContext("/", pp);//nimmt jeden beliebigen namen an
-                server.createContext("/reload",new ReloadMgr(ppp));
-                server.createContext("/rcvr",new ReInitializer());
-                server.createContext("/edit",new EditorLoader());
-                server.setExecutor(null); // creates a default executor
-                server.start();
-            }
-        }
-        catch(BindException xxx)
-        {
-            Messagers.SingleLineMsg("iZpl bereits gestartt; keine 2 instanzen möglich", "OKAY");
-            System.exit(9263);
-        }
-        catch (IOException ex)
-        {
-            ex.printStackTrace();
-        }
-    }
-}
+/*
+ * Copyright (C) 2015 iZc
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program.  If not, see <http://www.gnu.org/licenses/>.
+ */
+package de.nplusc.izc.iZpl;
+
+import com.sun.net.httpserver.HttpServer;
+import de.nplusc.izc.tools.baseTools.Messagers;
+import java.io.IOException;
+import java.net.BindException;
+import java.net.InetSocketAddress;
+import java.util.HashMap;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+/**
+ *
+ * @author LH
+ */
+public class PLServer
+{
+    private static final Logger l = LogManager.getLogger();
+    public static PlProcessorV2 ppp=null;
+    
+    public PlProcessorV2 getPlProcessorV2()
+    {
+        return ppp;
+    }
+    
+    
+    public PLServer(String plPath)
+    {
+        this(plPath, true, new HashMap<String,String>());
+    }
+    
+    public PLServer(String plPath,boolean serverOn,HashMap<String,String> options)
+    {
+        try
+        {
+            
+            
+            ppp = new PlProcessorV2();
+            ppp.setOptions(options);
+            ppp.InitializeOnPath(plPath);
+            if(serverOn)
+            {
+                l.info("Serving");
+                HttpServer server = HttpServer.create(new InetSocketAddress("localhost",9263), 0);//,InetAddress.getByName("localhost"));
+                server.createContext("/", ppp);//nimmt jeden beliebigen namen an
+                server.createContext("/reload",new ReloadMgr(ppp));
+                server.createContext("/rcvr",new ReInitializer());
+                server.createContext("/edit",new EditorLoader());
+                server.setExecutor(null); // creates a default executor
+                server.start();
+            }
+        }
+        catch(BindException xxx)
+        {
+            l.fatal("ERROR, Port already taken");
+            Messagers.SingleLineMsg("iZpl bereits gestartt; keine 2 instanzen möglich", "OKAY");
+            System.exit(9263);
+        }
+        catch (IOException ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+    
+    public PLServer(PlProcessorV2 pp)
+    {
+        this(pp, true);
+    }
+    
+    public PLServer(PlProcessorV2 pp,boolean serverOn)
+    {
+        try
+        {
+            
+            
+            ppp=pp;
+            if(serverOn)
+            {
+                HttpServer server = HttpServer.create(new InetSocketAddress("localhost",9263), 0);//,InetAddress.getByName("localhost"));
+                server.createContext("/", pp);//nimmt jeden beliebigen namen an
+                server.createContext("/reload",new ReloadMgr(ppp));
+                server.createContext("/rcvr",new ReInitializer());
+                server.createContext("/edit",new EditorLoader());
+                server.setExecutor(null); // creates a default executor
+                server.start();
+            }
+        }
+        catch(BindException xxx)
+        {
+            l.fatal("ERROR, Port already taken");
+            Messagers.SingleLineMsg("iZpl bereits gestartt; keine 2 instanzen möglich", "OKAY");
+            System.exit(9263);
+        }
+        catch (IOException ex)
+        {
+            ex.printStackTrace();
+        }
+    }
+}

+ 37 - 3
iZpl/src/main/java/de/nplusc/izc/iZpl/PlProcessorV2.java

@@ -55,6 +55,7 @@ public class PlProcessorV2 implements HttpHandler
     private List<PlayListItem> forceList;
     private List<PlayListItem> history; 
     private final HashMap<String,WatchKey> registeredFolders;
+    private HashMap<String,String> options;
     private WatchService observer;
     private final Object lock;
     
@@ -63,6 +64,7 @@ public class PlProcessorV2 implements HttpHandler
         lock = new Object();
         history = new ArrayList<>();
         registeredFolders = new HashMap<>();
+        options = new HashMap<>();
         try
         {
             observer = FileSystems.getDefault().newWatchService();
@@ -72,9 +74,7 @@ public class PlProcessorV2 implements HttpHandler
             l.warn("Unable to observe Folders");
         }
     }
-    
-    
-    
+
     /* public PlProcessor(String PlPath)
     {
     }*/
@@ -183,6 +183,18 @@ public class PlProcessorV2 implements HttpHandler
                 Main.quickQuit();
                 return;
             }
+            int clampPlayCount = 0;
+            if(options.containsKey("PLAYCOUNTLIMIT"))
+            {
+                try
+                {
+                    clampPlayCount = Integer.valueOf(options.get("PLAYCOUNTLIMIT"));
+                }
+                catch(NumberFormatException lickme)
+                {
+                    l.warn("Option PLAYCOUNTLIMIT is not a valid integer");
+                }
+            }
             if(!reload)
             {
                 poolTemp=new HashMap<>();
@@ -198,6 +210,11 @@ public class PlProcessorV2 implements HttpHandler
                         PlayListItem u2d=poolTemp.get(itemID);
                         u2d.setTargetPlaycount(u2d.getTargetPlaycount()+item.getTargetPlaycount());
                     }
+                    if(clampPlayCount>0)
+                    {
+                        PlayListItem u2d=poolTemp.get(itemID);
+                        u2d.setTargetPlaycount(clampPlayCount);
+                    }
                 }
             }
             else
@@ -214,7 +231,14 @@ public class PlProcessorV2 implements HttpHandler
                         PlayListItem u2d=poolTemp.get(itemID);
                         u2d.setTargetPlaycount(u2d.getTargetPlaycount()+item.getTargetPlaycount());
                     }
+                    
+                    if(clampPlayCount>0)
+                    {
+                        PlayListItem u2d=poolTemp.get(itemID);
+                        u2d.setTargetPlaycount(clampPlayCount);
+                    }
                 }
+                
                 Set<String> keys = pool.keySet();
                 for (String key : keys)
                 {
@@ -369,6 +393,16 @@ public class PlProcessorV2 implements HttpHandler
     {
         this.history = history;
     }
+       
+    public HashMap<String, String> getOptions()
+    {
+        return options;
+    }
+
+    public void setOptions(HashMap<String, String> options)
+    {
+        this.options = options;
+    }
     
     private void registerChangedFolders(String folder)
     {