Results 1 to 5 of 5

Thread: iTunes Playlist Converter

  1. #1
    Constant Bitrate
    Join Date
    Sep 2005
    Posts
    121

    iTunes Playlist Converter

    YOU NEED .NET 1.1 for the Converter
    Tested with iTunes 6.0.1.3 - Let me know if it doesnt work.

    I couldnt work out how to properly make Centrafuse playlists, so i wrote this to convert my iTunes playlists to Centrafuse playlists.

    Usage:

    Right click on your Playlist in iTunes, and select Export. Export the file to XML format.

    Run convert.exe with your file that your exported.

    Eg: convert.exe myplaylist.xml

    this will produce myplaylist.mpl which you can insert in your Centrafuse playlist folder. (C:\Program Files\Flux Media\Centrafuse\playlists)

    I've included the code so you can see it contains no viruses :P

    I hope its useful, it was made just for me, so ignore the quirks

    Code:
    using System;
    using System.Xml;
    using System.Collections;
    using System.Reflection;
    using System.IO;
    
    namespace iTunesPlaylistTOCentrafuse
    {
    	class Class1
    	{
    		/// <summary>
    		/// The main entry point for the application.
    		/// </summary>
    		[STAThread]
    		static void Main(string[] args)
    		{
    			Console.WriteLine("----------------------------------------");
    			Console.WriteLine("iTunes to Centrafuse Playlist Converter.");
    			Console.WriteLine("(C) Konnichiwa (JCarter) 2005");
    			Console.WriteLine("----------------------------------------");
    			Console.WriteLine(string.Empty);
    
    			if(args.Length != 1 || args[0] == "/?")
    			{
    				Console.WriteLine("Usage: convert.exe InputFilename [inputfile.xml]");
    				return;
    			}
    
    			Console.WriteLine("Opening iTunes Playlist...");
    			string inputFilename = args[0];
    			XmlTextReader reader = new XmlTextReader(inputFilename);
    			ArrayList songList = new ArrayList();
    			Console.WriteLine("Reading songs...");
    			try
    			{
    				while(reader.Read())
    				{
    					XmlNodeType t = reader.NodeType;
    					if(reader.NodeType == XmlNodeType.Text)
    					{
    						if(reader.Value == "Track ID")
    						{
    							songList.Add(ExtractSong(reader));
    						}
    						else if(reader.Value == "Playlists")
    						{
    							break;
    						}
    					}
    				}
    			}
    			catch
    			{
    				Console.WriteLine("Failed reading iTunes playlist.");
    				return;
    			}
    			Console.WriteLine("Read {0} songs.", songList.Count);
    
    			string outputFilename = System.IO.Path.GetFileNameWithoutExtension(inputFilename);
    			outputFilename += ".mpl";
    
    			Console.WriteLine("Writing songs...");
    			try
    			{
    			using(FileStream writer = new FileStream(outputFilename, FileMode.Create))
    			{
    				writer.WriteByte(0xFF);
    				writer.WriteByte(0xFE);
    				for(int i = 0; i < songList.Count; i++)
    				{
    					Song song = (Song)songList[i];
    					string location = song.Location;
    					location = location.Replace("%20", " ");
    					location = location.Replace("file://localhost/", "");
    					string line = song.Artist + " - " + song.Name + "|" + location;
    					byte[] unicodeLine = System.Text.UnicodeEncoding.Unicode.GetBytes(line);
    					writer.Write(unicodeLine, 0, unicodeLine.Length);
    					if(i != songList.Count - 1)
    					{
    						byte[] returnChars = System.Text.UnicodeEncoding.Unicode.GetBytes("\r\n");
    						writer.Write(returnChars, 0, returnChars.Length);
    					}
    				}
    			}
    			}
    			catch
    			{
    				Console.WriteLine("Failed writing Centrafuse playlist.");
    				return;
    			}
    			Console.WriteLine("Wrote {0} songs.", songList.Count);
    			Console.WriteLine("Finished.");
    		}
    
    		private static Song ExtractSong(XmlTextReader reader)
    		{
    			FieldInfo[] fieldInfo = typeof(Song).GetFields();
    			Song song = new Song();
    			while(reader.Read())
    			{
    				if(reader.NodeType == XmlNodeType.EndElement)
    				{
    					if(reader.Name == "dict")
    					{
    						Console.WriteLine("Read: " + song.Artist + " - " + song.Name);
    						return song;
    					}
    				}
    				if(reader.NodeType == XmlNodeType.Text)
    				{
    					string key = reader.Value.Replace(" ", "");
    					Skip(reader);
    					string val = reader.Value;
    					for(int i = 0; i < fieldInfo.Length; i++)
    					{
    						if(fieldInfo[i].Name == key)
    						{
    							fieldInfo[i].SetValue(song, val);
    							break;
    						}
    					}
    				}
    			}
    			return song;
    		}
    
    		private static void Skip(XmlTextReader reader)
    		{
    			reader.Read();
    			reader.Read();
    			reader.Read();
    		}
    
    		private class Song
    		{
    			public string TrackID;
    			public string Name;
    			public string Artist;
    			public string Album;
    			public string Genre;
    			public string Kind;
    			public string Size;
    			public string TotalTime;
    			public string TrackNumber;
    			public string TrackCount;
    			public string Year;
    			public string DateModified;
    			public string DateAdded;
    			public string BitRate;
    			public string SampleRate;
    			public string Season;
    			public string PersistentID;
    			public string TrackType;
    			public string Location;
    			public string FileFolderCount;
    			public string LibraryFolderCount;
    		}
    	}
    }
    Attached Files Attached Files

  2. #2
    Constant Bitrate
    Join Date
    Nov 2004
    Location
    Philippines
    Posts
    119
    At the top of my head question: This would require the mp3 files will be physically stored in the same folder as iTunes' library and Centrafuse's? Great idea! Will definitely be useful to me!

    Next version would be nice if it could automatically read existing iTunes playlists and then automatically generate a centrafuse version, all within centrafuse... That's just me though

  3. #3
    Maximum Bitrate buurin's Avatar
    Join Date
    Sep 2005
    Location
    Seattle, WA
    Posts
    463
    I quickly glances through the iTunes COM documentation and didnt see any mention of 'export' functionality therefore doing this from code may be tricky.

    The iTunes APIs are missing a lot of stuff.

    I wish they exposed some kind of advanced querying (i.e. I want to find all albums with more than 5 songs).. but beyond that they are missing basic functionality such as exporting, and finding songs by genre.
    B Smoov
    Project Status: 90% Complete

    Next Step: TIVO for Radio

    Ampie Case :: MII10000 Mobo :: M1-ATX PSU :: 512MB RAM :: 2.5" HD, 60GB, 5400rpm, 16MB Buffer :: DWW-700H :: Centrafuse

  4. #4
    Constant Bitrate
    Join Date
    Sep 2005
    Posts
    121
    yeah, i did want to just have an option that would keep my iTunes playlists in sync with Centrafuse, but i cant get to iTunes playlists via the API.

  5. #5
    Low Bitrate
    Auto Apps:loading...
    Ogold007's Avatar
    Join Date
    May 2006
    Location
    Los Angeles
    Posts
    84
    I doubt anyone is still watching this thread but I created a plugin for Centrafuse to play iTunes, Winamp playlists. You can get it from here:

    http://forums.fluxmedia.net/plugin-d...tunes-etc.html

Similar Threads

  1. Itunes com api - can't control the browser
    By kykeon in forum Software & Software Development
    Replies: 10
    Last Post: 04-11-2006, 12:24 AM
  2. itunes music store and u2 ipod and voucher...
    By SAScooby in forum Off Topic
    Replies: 1
    Last Post: 10-15-2005, 01:41 PM
  3. Playlist and save bugs
    By tolisn in forum RR Bug Tracker
    Replies: 6
    Last Post: 04-04-2005, 11:16 PM
  4. Itunes Playlist?
    By Cerztrueheart in forum FrodoPlayer
    Replies: 2
    Last Post: 03-30-2005, 04:40 PM
  5. playlist necessary? (philosophical)
    By crippy in forum Software & Software Development
    Replies: 22
    Last Post: 10-16-2003, 02:39 PM

Bookmarks

Posting Permissions

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