Package itunes

Source Code of itunes.ItunesDumpMain

package itunes;
import itunes.ItunesXMLParser;
import common.Sender;
import common.TrackMetaData;

import java.lang.System;
import java.io.*;

public class ItunesDumpMain {
 
 
public static void main(String []args)
 
  String itunespath = "C:\\"+ System.getenv("HOMEPATH")+"\\My Documents\\My Music\\iTunes\\iTunes Music Library.xml";
 
 
  System.out.println(itunespath);
 

 
   try{
     /*
        File file  = new File("sysout.log");    //redirect stdout
        PrintStream printStream;
      printStream = new PrintStream(new FileOutputStream(file)); 
        System.setOut(printStream);
     */
        FileInputStream fstream = new FileInputStream(itunespath);
        DataInputStream in = new DataInputStream(fstream);
            BufferedReader br = new BufferedReader(new InputStreamReader(in));
        String strLine;
       
        String song="";
        boolean playedsong = false;
        boolean indata=false;
        int globalcount = 0;
        while ((strLine = br.readLine()) != null)   {
          ++globalcount;
        if (strLine.indexOf("<key>")!= -1 && indata==false)
        {
          if (strLine.substring(0, strLine.indexOf("<key>")+5).equals("\t\t<key>"))
          {
            if (!indata)
            {
              indata = true;
             
              //System.out.println(globalcount);
             
            }
          }
        }
        else if (strLine.indexOf("</dict>")!= -1)
        {
         
         
         
          if (strLine.substring(0, strLine.indexOf("</dict>")+7).equals("\t\t</dict>"))
          {
            if (indata)
            {
              indata = false;
             
              if (playedsong)
              {
              //  System.out.println(song);
                       
                             
                System.out.println("sending..");
               
                  TrackMetaData tmd = ItunesXMLParser.parseTrackMetaData(song);
                  Sender sender = Sender.getXMLSender();
                  sender.sendDataToSite(tmd);
               
                playedsong = false;
             
              }
              //System.out.println(globalcount);
             
            }
            song = "";
          }
        }
        else if (indata)
        {
          song = song + strLine;// +"\n";
          if (strLine.indexOf("\t\t\t<key>Play Count</key>")!= -1)
          {
            playedsong = true;
            System.out.println("new played song, line "+globalcount);
          }
           
         //  System.out.println (strLine+"   "+globalcount);
        }
        }
        in.close();
        }catch (Exception e){
          System.err.println("Error: " + e.getMessage());
        }
 
 
 
}

}
TOP

Related Classes of itunes.ItunesDumpMain

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.