Sfoglia il codice sorgente

iZpl-reader V2.0 installed

git-svn-id: http://repo.nplusc.de/svn/iZink@181 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 11 anni fa
parent
commit
7288c7d799

+ 64 - 3
iZpl/src/de/nplusc/izc/iZpl/MultiPlayListItem.java

@@ -4,8 +4,10 @@
  */
 package de.nplusc.izc.iZpl;
 
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
+import java.util.Objects;
 
 /**
  *
@@ -16,17 +18,41 @@ public class MultiPlayListItem implements PlayListItem
     private List<String> path,title;
     private int playcount,countPlayed;
 
+    public MultiPlayListItem(){};
+    
+    
     public MultiPlayListItem(String[] path, String[] Title, int playcount)
     {
-        this.path = Arrays.asList(path);
-        this.title = Arrays.asList(path);
+                            //arrays.asList()-lists=readonly :(
+        this.path = new ArrayList<>(Arrays.asList(path));
+        this.title = new ArrayList<>(Arrays.asList(Title));
         this.playcount = playcount;
         countPlayed=0; //noch nie gespielt als default; bei reload wird anderweitig verglichen :P
     }
 
+    public List<String> getTitles()
+    {
+        return title;
+    }
+    public List<String> getPaths()
+    {
+        return path;
+    }
+    
+    public void setTitles(List<String> p)
+    {
+        title=p;
+    }
+    
+    public void setpaths(List<String> p)
+    {
+        path=p;
+    }
+    
+    
     public void addTitle(String ppath,String ptitle)
     {
-        path.add(ptitle);
+        path.add(ppath);
         title.add(ptitle);
     }
     
@@ -94,4 +120,39 @@ public class MultiPlayListItem implements PlayListItem
         }
         return ret.trim();
     }
+
+
+    @Override
+    public int hashCode()
+    {
+        int hash = 7;
+        hash = 47 * hash + Objects.hashCode(this.path);
+        hash = 47 * hash + Objects.hashCode(this.title);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final MultiPlayListItem other = (MultiPlayListItem) obj;
+        if (!Objects.equals(this.path, other.path))
+        {
+            return false;
+        }
+        if (!Objects.equals(this.title, other.title))
+        {
+            return false;
+        }
+        return true;
+    }
+    
+    
 }

+ 76 - 23
iZpl/src/de/nplusc/izc/iZpl/PLReader.java

@@ -29,7 +29,7 @@ public class PLReader
     * //Defaultet zu 1,0 falls nicht gefunden
     * #IZPL:INCLUDE|PrioMultiplier|Expand//INCLUDE sagt dass hier ne referenzierte IZPL liegt Expand sagt Liste kann aufgeteilt werden
     * /Pfad/zu/andererListe.iZpl //prioMultiplier bei include mutipliziert Multiopliers des Includes
-    * #IZPL:INCLUDE|PrioMultiplier|NoExpand //NoExpand sagt dass File Als ein Block behandelt werden muss (Includes innerhalb werden auch beachtet
+    * #IZPL:INCLUDE|PrioMultiplier|NoExpand //NoExpand sagt dass File Als ein Block behandelt werden muss (Includes innerhalb werden auch beachtet aber keine multiplizierungen eingebaut
     * /Pfad/zu/UnsplittbarerListe.iZpl
     */
     private static Yaml yp = new Yaml();
@@ -281,10 +281,40 @@ public class PLReader
         {
             for (String[] elements : tempo)
             {
+                String lfid=elements[0];
+                if(lfid==null||lfid.equals("null"))
+                {
+                   continue;
+                }
+                if(!lfid.substring(1,2).equals(":"))//absoluterPfad
+                {
+                    lfid=FileTK.getFilePath(path)+"\\"+lfid;
+                }
+                elements[0]=lfid;
+                
+                
                 String[] metadata=elements[2].substring(6).split("\\|");
+                if(metadata[0].equalsIgnoreCase("include"))
+                {
+                    System.out.println("incl;"+elements[0]);
+                    retval.addAll(readListAlternativeNoexpandAux(elements[0], rd-1));
+                }
+                else
+                {
+                    retval.add(elements);
+                }
             }
         }
-        return null;
+        
+        System.out.println("ArrayResult of reading in as NoExpa:"+path);
+        System.out.println("Depth:"+rd);
+        System.out.println("\n"+yp.dump(retval));//macht das log leichter parsbar in NPP mit Ansicht=yaml
+        System.out.println("ENd of Block:"+path);
+        System.out.println("###########################################################################");
+        System.out.println("---------------------------------------------------------------------------");
+        System.out.println("###########################################################################");
+        
+        return retval;
     }
     
     
@@ -295,7 +325,7 @@ public class PLReader
     {
         String[] playListRaw = FileTK.fileload(path);//temporär ne bestimmte hardcoden
         ArrayList<String[]> tempo=new ArrayList<>();
-        if(playListRaw.length>=2 && playListRaw[0].equalsIgnoreCase("EXTM3U")&&playListRaw[1].equalsIgnoreCase("#IZPL"))
+        if(playListRaw.length>=2 && playListRaw[0].equalsIgnoreCase("#EXTM3U")&&playListRaw[1].equalsIgnoreCase("#IZPL"))
         {
             String[] buffer = new String[3]; //0 path; 1=extm3u,2=izpl-data
             int cntr=0;
@@ -321,6 +351,7 @@ public class PLReader
                         cntr=0;
                         buffer[0]=line;               
                         tempo.add(buffer);
+                        buffer = new String[3];//<<ARSCHLOCH hatte dich vergessen ...
                         buffer[0]="";
                         buffer[1]="";
                         buffer[2]="#IZPL:1|0";
@@ -345,63 +376,75 @@ public class PLReader
         }
         
         List<String[]> tempo = readListAlternativeAuxPrepare(path);
+        System.out.println("##########################Raw List input##############################################");
+        System.out.println(yp.dump(tempo));
+        System.out.println("#####################End Raw List input###############################################");
+        
         if(tempo!=null)
         {
             //\\//\\//
             //0 pfad; 1=extinf;2=izpl;
             //verarbeiten.....
             HashMap<Integer,ArrayList<String[]>> groupprep = new HashMap<>();
-            groupprep.put(0,new ArrayList<String[]>());
+            //groupprep.put(0,new ArrayList<String[]>());
             for (String[] elements : tempo)
             {      
                 String lfid=elements[0];
+                if(lfid==null||lfid.equals("null"))
+                {
+                   continue;
+                }
                 if(!lfid.substring(1,2).equals(":"))//absoluterPfad
                 {
                     lfid=FileTK.getFilePath(path)+"\\"+lfid;
                 }
                 elements[0]=lfid;
                 String[] metadata=elements[2].substring(6).split("\\|");
-                if(metadata[1].equalsIgnoreCase("include"))
+                if(metadata[0].equalsIgnoreCase("include"))
                 {
                     System.out.println("Includebranch");                    
                     if(metadata[2].equalsIgnoreCase("EXPAND"))
                     {
-                        HashMap<String,PlayListItem> recurseret = readListAlternative(elements[0], rd-1, Integer.valueOf(metadata[1]));//nätig in beiden fällen
+                        HashMap<String,PlayListItem> recurseret = readListAlternative(elements[0], rd-1, Integer.valueOf(metadata[1].trim()));//nätig in beiden fällen
                         Set<String> keys= recurseret.keySet();
                         for (String itemkey : keys)
                         {
                             PlayListItem pli = recurseret.get(itemkey);
                             if(pli instanceof SinglePlayListItem)//multiitems instapasthru
                             {
-                                if(retval.containsKey(itemkey))
+                                if(retval.containsKey(pli+""))
                                 {
-                                    PlayListItem tpli = retval.get(itemkey);
+                                    PlayListItem tpli = retval.get(pli+"");
                                     tpli.setTargetPlaycount(tpli.getTargetPlaycount()+prioritybase*pli.getTargetPlaycount());
                                 }
                                 else
                                 {
-                                    retval.put(itemkey,pli);
+                                    retval.put(pli+"",pli);
                                 }
                             }
                             else
                             {
-                                retval.put(itemkey,pli);
+                                retval.put(pli+"",pli);
                             }    
                         }
                     }
                     else
                     {
-                        MultiPlayListItem pli = new MultiPlayListItem(new String[]{}, new String[]{}, Integer.valueOf(metadata[1])*prioritybase);
+                        MultiPlayListItem pli = new MultiPlayListItem(new String[]{}, new String[]{}, Integer.valueOf(metadata[1].trim())*prioritybase);
                         //target der liste :P
                         List<String[]> listraw = readListAlternativeNoexpandAux(elements[0], rd-1);
-                        
+                        for (String[] item : listraw)
+                        {
+                            pli.addTitle(item[0], item[1]);
+                        }
+                         retval.put(pli+"", pli);//multiItems sind nicht mit pfad referenziert...
                     }
                     
                 }
                 else
                 {
                     //1,0=fefault :P
-                    int gid = Integer.valueOf(metadata[1]);
+                    int gid = Integer.valueOf(metadata[1].trim());
                     if(gid>0)
                     {
                         if(!groupprep.containsKey(gid))
@@ -413,25 +456,27 @@ public class PLReader
                     }
                     else
                     {
-                        if(retval.containsKey(elements[0]))//summieren...
+                        PlayListItem it = new SinglePlayListItem(elements[0], elements[1], Integer.valueOf(metadata[0].trim())*prioritybase);
+                        if(retval.containsKey(it+""))//summieren...
                         {
-                            PlayListItem it = retval.get(elements[0]);
+                            it = retval.get(it+"");
                             int cpc = it.getTargetPlaycount();
-                            it.setTargetPlaycount(cpc+(prioritybase*Integer.valueOf(metadata[1])));//zusammenaddieren da unter dem =en path nur das selbe lied liegen kann also de-dupe
+                            it.setTargetPlaycount(cpc+(prioritybase*Integer.valueOf(metadata[0].trim())));//zusammenaddieren da unter dem =en path nur das selbe lied liegen kann also de-dupe
                         }
                         else
                         {
-                            PlayListItem it = new SinglePlayListItem(elements[0], elements[1], Integer.valueOf(metadata[1])*prioritybase);
-                            retval.put(elements[0],it);
+                            
+                            retval.put(it+"",it);
                         }
                     }
                 }
             }
             Set<Integer> keys = groupprep.keySet();
             for (Integer i:keys)
-            {                                                                                   //HAXX
-                MultiPlayListItem pli = new MultiPlayListItem(new String[]{}, new String[]{}, prioritybase*Integer.valueOf(tempo.get(0)[2].substring(6).split("\\|")[1]));
-                tempo=groupprep.get(i);
+            {     
+                tempo=groupprep.get(i);                                                                         //HAXX
+                MultiPlayListItem pli = new MultiPlayListItem(new String[]{}, new String[]{}, prioritybase*Integer.valueOf(tempo.get(0)[2].substring(6).split("\\|")[1].trim()));
+                
                 for (String[] elem : tempo)
                 {
                     String lfid=elem[0];
@@ -442,12 +487,20 @@ public class PLReader
                     elem[0]=lfid;
                     pli.addTitle(elem[0], elem[1]);
                 }
-                retval.put(pli+"", pli);//multiItems sind nicht mit pfad referenziert...
+                retval.put(pli+"", pli);//multiItems sind nicht mit pfad referenziert... außer NoexpandIncludes
                 
             }
         }
         
-        return null;
+        System.out.println("ArrayResult of reading in:"+path);
+        System.out.println("Depth:"+rd);
+        System.out.println("\n"+yp.dump(retval));//macht das log leichter parsbar in NPP mit Ansicht=yaml
+        System.out.println("ENd of Block:"+path);
+        System.out.println("###########################################################################");
+        System.out.println("---------------------------------------------------------------------------");
+        System.out.println("###########################################################################");
+        
+        return retval;
     }
     
     

+ 13 - 0
iZpl/src/de/nplusc/izc/iZpl/PLServer.java

@@ -5,7 +5,10 @@
 package de.nplusc.izc.iZpl;
 
 import com.sun.net.httpserver.HttpServer;
+import de.nplusc.izc.tools.baseTools.Messagers;
+import de.nplusc.izc.tools.baseTools.Tools;
 import java.io.IOException;
+import java.net.BindException;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 import java.net.Socket;
@@ -31,6 +34,11 @@ public class PLServer
             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();
@@ -48,6 +56,11 @@ public class PLServer
             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();

+ 42 - 5
iZpl/src/de/nplusc/izc/iZpl/SinglePlayListItem.java

@@ -4,6 +4,8 @@
  */
 package de.nplusc.izc.iZpl;
 
+import java.util.Objects;
+
 /**
  *
  * @author LH
@@ -11,13 +13,16 @@ package de.nplusc.izc.iZpl;
 public class SinglePlayListItem implements PlayListItem
 {
     private String path,Title;
-    private int playcount,countPlayed;
+    private int targetplaycount,countPlayed;
 
+    
+    public SinglePlayListItem(){};
+    
     public SinglePlayListItem(String path, String Title, int playcount)
     {
         this.path = path;
         this.Title = Title;
-        this.playcount = playcount;
+        this.targetplaycount = playcount;
         countPlayed=0; //noch nie gespielt als default; bei reload wird anderweitig verglichen :P
     }
 
@@ -43,12 +48,14 @@ public class SinglePlayListItem implements PlayListItem
 
     public int getTargetPlaycount()
     {
-        return playcount;
+        return targetplaycount;
     }
 
+
+
     public void setTargetPlaycount(int playcount)
     {
-        this.playcount = playcount;
+        this.targetplaycount = playcount;
     }
 
     public int getCountPlayed()
@@ -65,5 +72,35 @@ public class SinglePlayListItem implements PlayListItem
     {
         return path+"\n"+Title;
     }
-    
+        @Override
+    public int hashCode()
+    {
+        int hash = 3;
+        hash = 23 * hash + Objects.hashCode(this.path);
+        hash = 23 * hash + Objects.hashCode(this.Title);
+        return hash;
+    }
+
+    @Override
+    public boolean equals(Object obj)
+    {
+        if (obj == null)
+        {
+            return false;
+        }
+        if (getClass() != obj.getClass())
+        {
+            return false;
+        }
+        final SinglePlayListItem other = (SinglePlayListItem) obj;
+        if (!Objects.equals(this.path, other.path))
+        {
+            return false;
+        }
+        if (!Objects.equals(this.Title, other.Title))
+        {
+            return false;
+        }
+        return true;
+    }
 }

+ 26 - 0
iZpl/src/de/nplusc/izc/iZpl/TestClass.java

@@ -0,0 +1,26 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package de.nplusc.izc.iZpl;
+
+import de.nplusc.izc.tools.IOtools.FileTK;
+import java.util.HashMap;
+import java.util.Objects;
+import org.yaml.snakeyaml.Yaml;
+
+/**
+ *
+ * @author LH
+ */
+public class TestClass
+{
+    public static void main(final String args2[])
+    {
+        
+        
+        String plif = new Yaml().dump(PLReader.readListAlternative("D:\\mp3\\iZpl\\testpl\\rxe.izpl", 40, 1));
+       FileTK.writeFile(plif, "D:\\mp3\\iZpl\\testpl\\testout.iZdump");
+       HashMap<String,PlayListItem> xxx = (HashMap<String,PlayListItem>) new Yaml().load(plif);
+    }
+}