+ Follow This Topic
Results 1 to 3 of 3

Thread: MP3 Playlist to HTML

  1. #1
    King Zarathu's Avatar
    King Zarathu Guest

    MP3 Playlist to HTML

    So I made this program last night while I was talking with TDurden. I should've been doing my homework...but...yeah....

    [url]http://www.thesarcasm.com/Music.html[/url]

    Code:
    import java.util.*;
    import java.io.*;
    import org.farng.mp3.*;
    import org.farng.mp3.id3.*;
    import org.farng.mp3.lyrics3.*;
    
    public class MP3HTML
    {
    	
    	public static BufferedWriter out;
    													
    	public static void main(String[] args) throws IOException, TagException
    	{
    		Scanner in = new Scanner(new File("All.m3u"));
    		String newIn = "", artist = "", title = "";
    		int progress = 0, total = 0;
    		out = new BufferedWriter(
    									new PrintWriter(
    										new FileWriter(
    											new File("Music.html"))));
    		
    		MP3Class mp3;
    		
    		ID3v1 id3v1 = new ID3v1();
    		ID3v2_2 id3v2_2 = new ID3v2_2();
    		ID3v2_3 id3v2_3 = new ID3v2_3();
    		ID3v2_4 id3v2_4 = new ID3v2_4();
    		
    		writeHeader();
    		
    		while(in.hasNext()){in.nextLine(); total++;}
    		
    		in = new Scanner(new File("All.m3u"));
    		
    		while(in.hasNext())
    		{
    			mp3 = new MP3Class(in.nextLine());
    			
    			if(mp3.getType() == 1)
    			{
    				try {id3v1 = new ID3v1(new RandomAccessFile(mp3.getLocation(), "r"));} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    				try {writeSong(id3v1.getLeadArtist(), id3v1.getSongTitle());} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    			} else
    			if(mp3.getType() == 22)
    			{
    				try {id3v2_2 = new ID3v2_2(new RandomAccessFile(mp3.getLocation(), "r"));} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    				try {writeSong(id3v2_2.getLeadArtist(), id3v2_2.getSongTitle());} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    			} else
    			if(mp3.getType() == 23)
    			{
    				try {id3v2_3 = new ID3v2_3(new RandomAccessFile(mp3.getLocation(), "r"));} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    				try {writeSong(id3v2_3.getLeadArtist(), id3v2_3.getSongTitle());} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    			} else
    			if(mp3.getType() == 24)
    			{
    				try {id3v2_4 = new ID3v2_4(new RandomAccessFile(mp3.getLocation(), "r"));} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    				try {writeSong(id3v2_4.getLeadArtist(), id3v2_4.getSongTitle());} catch (Exception e) {writeSong("Broken Tag", "Broken Tag");}
    			}
    			
    			System.out.println(progress + "/" + total);
    			progress++;
    		}
    		
    		writeFooter();
    		
    		
    		out.close();
    	}
    	
    	public static void writeHeader() throws IOException
    	{
    		out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD Xhtml 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">");
    
    		out.write("<html>"); out.newLine();
    		out.write("\t<head>"); out.newLine();
    		out.write("\t\t<title>TheSarcasm.com - I rule</title>"); out.newLine();
    		out.write("\t\t<link rel=\"stylesheet\" href=\"style.css\" type=\"text/css\" media=\"screen\" />"); out.newLine();
    		out.write("\t</head>"); out.newLine();
    			out.newLine();
    		
    		out.write("<style type=\"text/css\">"); out.newLine();
    	  	out.write("*"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tpadding: 0;"); out.newLine();
    		out.write("\tmargin: 0;"); out.newLine();
    		out.write("}"); out.newLine();
    		out.write("body"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tbackground: #000000;"); out.newLine();
    		out.write("\ttext-align: center;"); out.newLine();
    		out.write("\tfont-size: 100%;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("div"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\ttext-align: left;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("a"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\ttext-decoration: none;"); out.newLine();
    		out.write("\tcolor: #00ffff;"); out.newLine();
    		out.write("\tfont: .6em Verdana,sans-serif;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("a:hover"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\ttext-decoration: underline;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		
    		out.write("#wrapper"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tmargin: 0 auto;"); out.newLine();
    		out.write("\twidth: 779px;"); out.newLine();
    		out.write("\tbackground-image: url(http://www.thesarcasm.com/images/body.jpg);"); out.newLine();
    		out.write("\tbackground-repeat: repeat-y;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#header"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tbackground: url(http://www.thesarcasm.com/images/head.jpg);"); out.newLine();
    		out.write("\theight: 198px;"); out.newLine();
    		out.write("\tbackground-repeat: repeat-y;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#main"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tfloat: left;"); out.newLine();
    		out.write("\twidth: 629px;"); out.newLine();
    		out.write("\tbackground: transparent;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#main p"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tfont: 0.7em Verdana,sans-serif;"); out.newLine();
    		out.write("\tcolor: #ffffff;"); out.newLine();
    		out.write("\tline-height: 1.7em;"); out.newLine();
    		out.write("\tmargin: .5em 100px .5em 100px;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#main a"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tcolor: #00ffff;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#main img"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tmargin-left: 10px;"); out.newLine();
    		out.write("\tpadding: 2px;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#sidebar"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tfloat: right;"); out.newLine();
    		out.write("\twidth: 150px;"); out.newLine();
    		out.write("\tpadding: 0 0 1em 0;"); out.newLine();
    		out.write("\tbackground: transparent;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#sidebar li"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tmargin: 0 .2 0 0em;"); out.newLine();
    		out.write("\tpadding: 2px 0 0 .5em;"); out.newLine();
    		out.write("\tlist-style-type: none;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		
    		out.write("#sidebar a"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\ttext-align: right;"); out.newLine();
    		out.write("\tcolor: #00ffff;"); out.newLine();
    		out.write("\tfont: .6em Verdana,sans-serif;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#sidebar p"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\ttext-align: left;"); out.newLine();
    		out.write("\tpadding: 2px 0 0 .0;"); out.newLine();
    		out.write("\tcolor: #ffffff;"); out.newLine();
    		out.write("\tfont: .8em Verdana,sans-serif;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		
    		out.write("#footer"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tclear: both;"); out.newLine();
    		out.write("\tmargin: 0 auto;"); out.newLine();
    		out.write("\tpadding: .5em;"); out.newLine();
    		out.write("\ttext-align: center;"); out.newLine();
    		out.write("\tbackground-image:  url(http://www.thesarcasm.com/images/foot.jpg);"); out.newLine();
    		out.write("\theight: 24px;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#footer a"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tfont: .6em Verdana,sans-serif;"); out.newLine();
    		out.write("\tcolor: #00ffff;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("#footer p"); out.newLine();
    		out.write("{"); out.newLine();
    		out.write("\tfont: .6em Verdana,sans-serif;"); out.newLine();
    		out.write("\tcolor: #ffffff;"); out.newLine();
    		out.write("}"); out.newLine();
    		
    		out.write("</style>"); out.newLine();
    		
    		out.write("\t<body>"); out.newLine();
    		out.write("\t\t<br /><br />"); out.newLine();
    		out.write("\t\t<div id=\"wrapper\">"); out.newLine();
    		out.write("\t\t<div id=\"header\">"); out.newLine();
    		out.write("\t\t\t<p align=\"center\"><br />"); out.newLine();
    		out.write("\t\t\t\t<img src=\"images/front.jpg\" />"); out.newLine();
    		out.write("\t\t\t</p>"); out.newLine();
    		out.write("\t\t</div>"); out.newLine();
    		out.write("\t\t<div id=\"main\"><br /><br />"); out.newLine();
    		out.write("\t\t\t<center>"); out.newLine();
    		out.write("\t\t\t\t<TABLE BORDER=\"1\">"); out.newLine();
    		out.write("\t\t\t\t<TR>"); out.newLine();
    		out.write("\t\t\t\t<TD ALIGN=\"center\"><p>Artist</p></TD>"); out.newLine();
    		out.write("\t\t\t\t<TD ALIGN=\"center\"><p>Title</p></TD>"); out.newLine();
    		out.write("\t\t\t\t</TR>"); out.newLine();
    				
    	}
    	
    	public static void writeSong(String artist, String title) throws IOException
    	{
    		out.write("\n");
    		
    		out.write("\t\t\t\t<TR>"); out.newLine();
    		out.write("\t\t\t\t<TD ALIGN=\"center\"><p>" + artist + "</p></TD>"); out.newLine();
    		out.write("\t\t\t\t<TD ALIGN=\"center\"><p>" + title + "</p></TD>"); out.newLine();
    		out.write("\t\t\t\t</TR>"); out.newLine();
    		
    	}
    	
    	public static void writeFooter() throws IOException
    	{
    		out.write("</TABLE>"); out.newLine();
    		out.write("</center>"); out.newLine();
    		out.write("<br /><br />"); out.newLine();
    		out.write("</div>"); out.newLine();
    		out.write("<div id=\"footer\">"); out.newLine();
    		out.write("<a href=\"http://www.thesarcasm.com\">A Cock In Everyone's Mouth</a><br />"); out.newLine();
    		out.write("<a href=\"http://www.whitepaperclip.com\">WPC Productions</a>"); out.newLine();
    		out.write("</DIV>"); out.newLine();
    		out.write("</div>"); out.newLine();
    		out.write("<br /><br />"); out.newLine();
    		out.write("</body>"); out.newLine();
    		out.write("</html>"); out.newLine();
    	}
    }

  2. #2
    King Zarathu's Avatar
    King Zarathu Guest
    Code:
    class MP3Class
    {
    	private static String MP3Location = "";
    	private static int idNum = 0;
    	
    	public static ID3v1 id3v1;
    	public static ID3v2_2 id3v2_2;
    	public static ID3v2_3 id3v2_3;
    	public static ID3v2_4 id3v2_4;
    	
    	public MP3Class(String loc) throws IOException, TagException
    	{
    		
    		try
    			{
    				id3v1 = new ID3v1(new RandomAccessFile(loc, "r"));
    				idNum = 1;
    			} catch (TagNotFoundException e) {
    				try
    				{
    					id3v2_2 = new ID3v2_2(new RandomAccessFile(loc, "r"));
    					idNum = 22;
    				} catch (TagNotFoundException e1) {
    					try
    					{
    						id3v2_3 = new ID3v2_3(new RandomAccessFile(loc, "r"));
    						idNum = 23;
    					} catch (TagNotFoundException e2) {
    						try
    						{
    							id3v2_4 = new ID3v2_4(new RandomAccessFile(loc, "r"));
    							idNum = 24;
    						} catch (TagNotFoundException e3) {}
    						
    					}
    					
    				}
    			}
    		
    		MP3Location = loc;
    			
    	}
    	
    	public void setLocation(String path)
    	{
    		MP3Location = path;
    	}
    	
    	public String getLocation()
    	{
    		return MP3Location;
    	}
    	
    	public int getType()
    	{
    		return idNum;
    	}
    	
    	public String toString()
    	{
    		return MP3Location;
    	}
    	
    }

  3. #3
    Illusional's Avatar
    Illusional is offline different state of mind
    Country:
    Users Country Flag
    "Hot Love Pancake(s)"
    Join Date
    Sep 2001
    Gender
    Male
    Posts
    16,389
    speaking of which, what program do you use to d/l music?

    raverboy
    ...this is just my perspective on the situation...

Similar Threads

  1. Kiechi's complete crunked playlist
    By Kiechi in forum Romance/Love Movies, Music & Books
    Replies: 23
    Last Post: 13-02-08, 12:55 PM
  2. Html
    By BlackRose in forum Off Topic Discussion
    Replies: 12
    Last Post: 09-06-05, 02:05 PM
  3. html anyone?
    By butterflylove in forum Off Topic Discussion
    Replies: 11
    Last Post: 11-02-05, 06:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •