Pārlūkot izejas kodu

Internal workings on iZpl for Metadata in the header of the file. also
QuickStuff additions

LH 9 gadi atpakaļ
vecāks
revīzija
2b3b0f20a9

+ 0 - 4
QuickStuff/src/main/java/FFBookMarksToPathFile/Converter.java

@@ -96,8 +96,4 @@ public class Converter
             out.append(pathPrefix).append(etr).append("\n");
         }
     }
-    
-    
-    
-    //"D:\\loa\\000003\\books.txt"
 }

+ 186 - 0
QuickStuff/src/main/java/PV/UI.java

@@ -0,0 +1,186 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package PV;
+
+import de.nplusc.izc.tools.IOtools.DBWriter;
+import de.nplusc.izc.tools.IOtools.FileTK;
+import javax.swing.table.DefaultTableModel;
+
+/**
+ *
+ * @author LH
+ */
+public class UI extends javax.swing.JFrame
+{
+
+    /**
+     * Creates new form UI
+     */
+    public UI()
+    {
+        initComponents();
+        
+        String fp = "D:\\loa\\000004\\in.sqlite";
+        String fp2="D:\\loa\\000004\\out.txt";
+        DBWriter dbw = new DBWriter("", fp, "", "", DBWriter.DBTYPE_SQLite);
+        //String[][] items = dbw.queryTable("SELECT url , id FROM moz_places");
+        String[][] idmap = dbw.queryTable("SELECT place_id , visit_date from moz_historyvisits  ORDER BY visit_date");
+       // List<String> l = new ArrayList<>();
+        StringBuilder sb = new StringBuilder();
+         int i=0;
+         int j=0;
+         int k=0;
+         boolean c = false;
+      //   if(idmap.length>50000){c=true;
+      //   System.out.println("chunkered");
+      //   }
+        for (String[] ue : idmap)
+        {
+            String date = (new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss").format(new java.util.Date (Long.valueOf(ue[1])/1000)));
+            String datafield=dbw.querySingleCell("SELECT url FROM moz_places where id = "+ue[0]);
+            
+            //if(datafield.contains("trafficholder.com"))
+            {
+            
+            ((DefaultTableModel)tblT.getModel()).setValueAt(datafield, i, 0);
+            ((DefaultTableModel)tblT.getModel()).setValueAt(date, i, 1);
+            ((DefaultTableModel)tblT.getModel()).addRow(new String[]{""});
+            i++;
+            
+            sb.append(date).append("|").append(datafield).append("\n");
+            }
+            j++;
+            System.out.println(j+"/"+idmap.length);
+        /*    if(c)
+            {
+                if(i%50000==0&&i!=0)
+                {
+                    FileTK.writeFile(sb.toString(), fp2+"chunk_"+k);
+                    sb=new StringBuffer();
+                    k++;
+                }
+            }
+            */
+        }
+        
+       if(!c)
+       {
+           FileTK.writeFile(sb.toString(), fp2);
+       }
+        //dbw.closeConn();
+    }
+
+    /**
+     * This method is called from within the constructor to
+     * initialize the form.
+     * WARNING: Do NOT modify this code. The content of this method is
+     * always regenerated by the Form Editor.
+     */
+    @SuppressWarnings("unchecked")
+    // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
+    private void initComponents()
+    {
+
+        jScrollPane1 = new javax.swing.JScrollPane();
+        tblT = new javax.swing.JTable();
+
+        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
+
+        tblT.setModel(new javax.swing.table.DefaultTableModel(
+            new Object [][]
+            {
+                {null, null}
+            },
+            new String []
+            {
+                "URL", "Zeitpunkt"
+            }
+        )
+        {
+            Class[] types = new Class []
+            {
+                java.lang.String.class, java.lang.String.class
+            };
+
+            public Class getColumnClass(int columnIndex)
+            {
+                return types [columnIndex];
+            }
+        });
+        jScrollPane1.setViewportView(tblT);
+
+        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
+        getContentPane().setLayout(layout);
+        layout.setHorizontalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addGap(30, 30, 30)
+                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 816, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(102, Short.MAX_VALUE))
+        );
+        layout.setVerticalGroup(
+            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
+            .addGroup(layout.createSequentialGroup()
+                .addContainerGap()
+                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 530, javax.swing.GroupLayout.PREFERRED_SIZE)
+                .addContainerGap(27, Short.MAX_VALUE))
+        );
+
+        pack();
+    }// </editor-fold>                        
+
+    /**
+     * @param args the command line arguments
+     */
+    public static void main(String args[])
+    {
+        /* Set the Nimbus look and feel */
+        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
+        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
+         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
+         */
+        try
+        {
+            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels())
+            {
+                if ("Nimbus".equals(info.getName()))
+                {
+                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
+                    break;
+                }
+            }
+        }
+        catch (ClassNotFoundException ex)
+        {
+            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        catch (InstantiationException ex)
+        {
+            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        catch (IllegalAccessException ex)
+        {
+            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        catch (javax.swing.UnsupportedLookAndFeelException ex)
+        {
+            java.util.logging.Logger.getLogger(UI.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
+        }
+        //</editor-fold>
+
+        /* Create and display the form */
+        java.awt.EventQueue.invokeLater(new Runnable()
+        {
+            public void run()
+            {
+                new UI().setVisible(true);
+            }
+        });
+    }
+    // Variables declaration - do not modify                     
+    private javax.swing.JScrollPane jScrollPane1;
+    private javax.swing.JTable tblT;
+    // End of variables declaration                   
+}

+ 1 - 1
iZpl/src/main/java/de/nplusc/izc/iZpl/API/IZPLApi.java

@@ -182,7 +182,7 @@ public class IZPLApi
     {
         try
         {
-            return PLFileIO.readSingleList(path);
+            return PLFileIO.readSingleList(path).getData();
         }
         catch (InvalidPlayListFileException ex)
         {

+ 19 - 0
izpl-shared/src/main/java/de/nplusc/izc/iZpl/API/shared/InvalidPlayListFileException.java

@@ -23,5 +23,24 @@ package de.nplusc.izc.iZpl.API.shared;
  */
 public class InvalidPlayListFileException extends Exception
 {
+
+    public InvalidPlayListFileException()
+    {
+    }
+
+    public InvalidPlayListFileException(String message)
+    {
+        super(message);
+    }
+
+    public InvalidPlayListFileException(String message, Throwable cause)
+    {
+        super(message, cause);
+    }
+
+    public InvalidPlayListFileException(Throwable cause)
+    {
+        super(cause);
+    }
     
 }

+ 46 - 0
izpl-shared/src/main/java/de/nplusc/izc/iZpl/API/shared/RawPlayListFile.java

@@ -0,0 +1,46 @@
+/*
+ * 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.API.shared;
+
+import java.util.List;
+
+/**
+ *
+ * @author iZc <nplusc.de>
+ */
+public class RawPlayListFile
+{
+    private String rootPath;
+    private List<SinglePlayListItem> data;
+
+    public RawPlayListFile(String rootPath, List<SinglePlayListItem> data)
+    {
+        this.rootPath = rootPath;
+        this.data = data;
+    }
+
+    public String getRootPath()
+    {
+        return rootPath;
+    }
+
+    public List<SinglePlayListItem> getData()
+    {
+        return data;
+    }
+    
+}

+ 38 - 11
izpl-shared/src/main/java/de/nplusc/izc/iZpl/Utils/shared/PLFileIO.java

@@ -21,8 +21,8 @@ import de.nplusc.izc.iZpl.API.shared.InvalidPlayListFileException;
 import de.nplusc.izc.iZpl.API.shared.MultiPlayListItem;
 import de.nplusc.izc.iZpl.API.shared.PlayListFile;
 import de.nplusc.izc.iZpl.API.shared.PlayListItem;
+import de.nplusc.izc.iZpl.API.shared.RawPlayListFile;
 import de.nplusc.izc.iZpl.API.shared.SinglePlayListItem;
-//import de.nplusc.izc.iZpl.Main;
 import java.io.BufferedReader;
 import java.io.File;
 import java.io.FileReader;
@@ -45,7 +45,8 @@ public class PLFileIO
     //Formatdefinition //basiert aufne verpackte #extm3u
     /*
     * #EXTM3U
-    * #iZPl
+    * #IZPL
+    * #IZPH:Fieldname|value
     * #EXTINFO.......//Die VLC-Daten
     * #IZPL:PrioMultiplier|GroupID (IDS !=0 sind Verbunden. 0er immer einzeln)
     * /Pfad/zu/File1.mp3
@@ -59,12 +60,13 @@ public class PLFileIO
     
     //private static Yaml y = new Yaml();
     private static final Logger l = LogManager.getLogger();
-    public static List<SinglePlayListItem> readSingleList(String path) throws InvalidPlayListFileException
+    public static RawPlayListFile readSingleList(String path) throws InvalidPlayListFileException
     {
         String plbd = new File(path).getParent()+File.separator;
         l.trace("Location:{}",new File(path).getAbsolutePath());
         try
         {
+            String rootDir="";
             boolean syntaxError=false;
             FileReader fra = new FileReader(path);
             BufferedReader fr = new BufferedReader(fra);
@@ -72,15 +74,40 @@ public class PLFileIO
             if(!(fr.readLine().equalsIgnoreCase("#EXTM3U")))
             {
                 l.error("Not a valid izpl or M3u-file");
-                return new ArrayList<>();
+                return new RawPlayListFile("", new ArrayList<SinglePlayListItem>());
             }
-            if(!fr.readLine().startsWith("#IZPL"))
+            String ln = fr.readLine();
+            int lne=3;
+            if(!ln.startsWith("#IZPL"))
             {
                 l.info("plain M3u detected");
+                lne=2;
             }
-            int lne=3;
+            else//IZPL header processing
+            {
+                ln=fr.readLine();
+                while(ln!=null&&(ln.startsWith("#IZPH")||ln.trim().equals("")))
+                {
+                    if(!ln.trim().equals(""))
+                    {
+                        String section = ln.split(":")[1];
+                        section=section.toLowerCase();
+                        switch(section)
+                        {
+                            case "basedir":
+                                rootDir=section.substring(section.indexOf("|"));
+                                break;
+                            default:
+                                l.info("Unknown Header field ({}) detected at line: {}",section,lne);
+                                break;
+                        }
+                    }
+                    lne++;
+                }
+            }
+ 
             ArrayList<SinglePlayListItem> returndata = new ArrayList<>();
-            String ln = fr.readLine();
+            
             boolean extinf=false;
             SinglePlayListItem itm = new SinglePlayListItem();
             while(ln!=null)
@@ -213,11 +240,11 @@ public class PLFileIO
                 throw new InvalidPlayListFileException();
             }
             fr.close();
-            return returndata;
+            return new RawPlayListFile(rootDir,returndata);
         }
         catch (IOException ex)
         {
-            return new ArrayList<>();
+            return new RawPlayListFile("", new ArrayList<SinglePlayListItem>());
         }
     }
     
@@ -233,7 +260,7 @@ public class PLFileIO
     HashMap<Integer,MultiPlayListItem> groups = new HashMap<>();
     List<PlayListItem> result = new ArrayList<>();
 
-        List<SinglePlayListItem> rootList = readSingleList(path);
+        List<SinglePlayListItem> rootList = readSingleList(path).getData();
         try{
             Class yaml = Class.forName("org.yaml.snakeyaml.Yaml");
             Object y = yaml.getConstructor().newInstance();
@@ -295,7 +322,7 @@ public class PLFileIO
             return null;
         }
         rd--;
-        List<SinglePlayListItem> raw = readSingleList(path);
+        List<SinglePlayListItem> raw = readSingleList(path).getData();
         for (SinglePlayListItem spi : raw)
         {
             if(spi.isIncludeElement())