Kaynağa Gözat

3rd set of prepares of iZpl-2.0 (added most parts of the readIn-Code)

git-svn-id: http://repo.nplusc.de/svn/iZink@180 8b19561d-0d00-6744-8ac1-9afc8f58a8aa
masterX244 11 yıl önce
ebeveyn
işleme
5dfa005168

+ 30 - 12
iZpl/src/de/nplusc/izc/iZpl/MultiPlayListItem.java

@@ -13,45 +13,63 @@ import java.util.List;
  */
 public class MultiPlayListItem implements PlayListItem
 {
-    private List<String> path,Title;
+    private List<String> path,title;
     private int playcount,countPlayed;
 
     public MultiPlayListItem(String[] path, String[] Title, int playcount)
     {
         this.path = Arrays.asList(path);
-        this.Title = Arrays.asList(path);
+        this.title = Arrays.asList(path);
         this.playcount = playcount;
         countPlayed=0; //noch nie gespielt als default; bei reload wird anderweitig verglichen :P
     }
 
+    public void addTitle(String ppath,String ptitle)
+    {
+        path.add(ptitle);
+        title.add(ptitle);
+    }
+    
+    public void removeElement(int i)
+    {
+        path.remove(i);
+        title.remove(i);
+    }
+    
+    
     public String getPath(int i)
     {
         return path.get(i);
     }
 
-    public void setPath(String path, int i)
+    
+    public int getElemCount()
     {
-        this.path.remove(i);
-        this.path.add(i, path);
+        return path.size();
     }
+   /* public void setPath(String path, int i)
+    {
+        this.
+        this.path.add(i, path);
+    }*/
 
     public String getTitle(int i)
     {
-        return Title.get(i);
+        return title.get(i);
     }
 
-    public void setTitle(String Title, int i)
+    /*public void setTitle(String Title, int i)
     {
-        this.Title.remove(i);
+        this.
         this.Title.add(i,Title);
-    }
+    }*/
 
-    public int getPlaycount()
+    public int getTargetPlaycount()
     {
         return playcount;
     }
 
-    public void setPlaycount(int playcount)
+    public void setTargetPlaycount(int playcount)
     {
         this.playcount = playcount;
     }
@@ -71,7 +89,7 @@ public class MultiPlayListItem implements PlayListItem
         String ret = "";
         for (int i = 0; i < path.size(); i++)
         {
-            ret+=path.get(i)+"\n"+Title.get(i)+"\n";
+            ret+=path.get(i)+"\n"+title.get(i)+"\n";
             
         }
         return ret.trim();

+ 173 - 3
iZpl/src/de/nplusc/izc/iZpl/PLReader.java

@@ -267,15 +267,185 @@ public class PLReader
 
         return mergedLists;
     }
+   
     
+    private static List<String[]> readListAlternativeNoexpandAux(String path,int rd)
+    {
+        List<String[]> retval = new ArrayList<>();
+        if(rd<0)//zählt runter um beliebigen startwert z erlauben :P
+        {
+            return retval;//leere hashmap :P
+        }
+        List<String[]> tempo = readListAlternativeAuxPrepare(path);
+        if(tempo!=null)
+        {
+            for (String[] elements : tempo)
+            {
+                String[] metadata=elements[2].substring(6).split("\\|");
+            }
+        }
+        return null;
+    }
     
     
-    public static HashMap<String,PlayListItem> readListAlternative(String path, int rd,int prioritybase)
+    
+    
+    
+    private static List<String[]> readListAlternativeAuxPrepare(String path)
     {
         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"))
+        {
+            String[] buffer = new String[3]; //0 path; 1=extm3u,2=izpl-data
+            int cntr=0;
+            // erste zwo zeilen überspringen...
+            // dann datei ummodeln...
+            for (int i = 2; i < playListRaw.length; i++)
+            {
+                System.out.println(i);
+                String line = playListRaw[i];
+                if(cntr==0&&line.startsWith("#EXTINF:"))
+                {
+                    buffer[1]=line;
+                    cntr++;
+                }
+                else
+                {
+                    if((cntr==1||cntr==0)&&line.startsWith("#IZPL:"))
+                    {
+                        buffer[2]=line;cntr++;
+                    }
+                    else
+                    {
+                        cntr=0;
+                        buffer[0]=line;               
+                        tempo.add(buffer);
+                        buffer[0]="";
+                        buffer[1]="";
+                        buffer[2]="#IZPL:1|0";
+                    }
+                }
+            }
+        }
+        else
+        {
+            tempo=null;
+        }
+        return tempo;
+    }
+    
+    
+    public static HashMap<String,PlayListItem> readListAlternative(String path, int rd,int prioritybase)
+    {
+        HashMap<String,PlayListItem> retval = new HashMap<>();
+        if(rd<0)//zählt runter um beliebigen startwert z erlauben :P
+        {
+            return retval;//leere hashmap :P
+        }
         
-        
-        
+        List<String[]> tempo = readListAlternativeAuxPrepare(path);
+        if(tempo!=null)
+        {
+            //\\//\\//
+            //0 pfad; 1=extinf;2=izpl;
+            //verarbeiten.....
+            HashMap<Integer,ArrayList<String[]>> groupprep = new HashMap<>();
+            groupprep.put(0,new ArrayList<String[]>());
+            for (String[] elements : tempo)
+            {      
+                String lfid=elements[0];
+                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"))
+                {
+                    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
+                        Set<String> keys= recurseret.keySet();
+                        for (String itemkey : keys)
+                        {
+                            PlayListItem pli = recurseret.get(itemkey);
+                            if(pli instanceof SinglePlayListItem)//multiitems instapasthru
+                            {
+                                if(retval.containsKey(itemkey))
+                                {
+                                    PlayListItem tpli = retval.get(itemkey);
+                                    tpli.setTargetPlaycount(tpli.getTargetPlaycount()+prioritybase*pli.getTargetPlaycount());
+                                }
+                                else
+                                {
+                                    retval.put(itemkey,pli);
+                                }
+                            }
+                            else
+                            {
+                                retval.put(itemkey,pli);
+                            }    
+                        }
+                    }
+                    else
+                    {
+                        MultiPlayListItem pli = new MultiPlayListItem(new String[]{}, new String[]{}, Integer.valueOf(metadata[1])*prioritybase);
+                        //target der liste :P
+                        List<String[]> listraw = readListAlternativeNoexpandAux(elements[0], rd-1);
+                        
+                    }
+                    
+                }
+                else
+                {
+                    //1,0=fefault :P
+                    int gid = Integer.valueOf(metadata[1]);
+                    if(gid>0)
+                    {
+                        if(!groupprep.containsKey(gid))
+                        {
+                            groupprep.put(gid,new ArrayList<String[]>());
+                        }
+                        List<String[]> groupcontent = groupprep.get(gid);
+                        groupcontent.add(elements);//kein dupecheck da liste auch widerholungen enthalten kann; dupecheck nur bei einzel da dort aufsummiert wird :P
+                    }
+                    else
+                    {
+                        if(retval.containsKey(elements[0]))//summieren...
+                        {
+                            PlayListItem it = retval.get(elements[0]);
+                            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
+                        }
+                        else
+                        {
+                            PlayListItem it = new SinglePlayListItem(elements[0], elements[1], Integer.valueOf(metadata[1])*prioritybase);
+                            retval.put(elements[0],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);
+                for (String[] elem : tempo)
+                {
+                    String lfid=elem[0];
+                    if(!lfid.substring(1,2).equals(":"))//absoluterPfad
+                    {
+                        lfid=FileTK.getFilePath(path)+"\\"+lfid;
+                    }
+                    elem[0]=lfid;
+                    pli.addTitle(elem[0], elem[1]);
+                }
+                retval.put(pli+"", pli);//multiItems sind nicht mit pfad referenziert...
+                
+            }
+        }
         
         return null;
     }

+ 2 - 2
iZpl/src/de/nplusc/izc/iZpl/PlayListItem.java

@@ -11,8 +11,8 @@ package de.nplusc.izc.iZpl;
 public interface PlayListItem
 {
     public String getM3UElement();// erzeugt den M3U-Code zum aujsgeben an den VauEllCeh-er
-    public int getPlaycount(); 
-    public void setPlaycount(int playcount);
+    public int getTargetPlaycount(); 
+    public void setTargetPlaycount(int playcount);
     public int getCountPlayed();
     public void setCountPlayed(int countPlayed);
 }

+ 2 - 2
iZpl/src/de/nplusc/izc/iZpl/SinglePlayListItem.java

@@ -41,12 +41,12 @@ public class SinglePlayListItem implements PlayListItem
         this.Title = Title;
     }
 
-    public int getPlaycount()
+    public int getTargetPlaycount()
     {
         return playcount;
     }
 
-    public void setPlaycount(int playcount)
+    public void setTargetPlaycount(int playcount)
     {
         this.playcount = playcount;
     }