using System; using System.Xml; using System.Collections; namespace RatingMover { /// /// Summary description for Class1. /// class RatingMoverApp { Hashtable ratings = new Hashtable(); int ratingsMatched = 0; /// /// The main entry point for the application. /// [STAThread] static void Main(string[] args) { RatingMoverApp app = new RatingMoverApp(); app.Run(); } string GetNodeText(XmlNode node, string name) { XmlNode n = node.SelectSingleNode(name); if (n == null) return ""; return n.InnerText; } void Run() { try { XmlDocument iTunesDoc = new XmlDocument(); iTunesDoc.Load("c:\\iTunes Music Library.xml"); XmlDocument wmpDoc = new XmlDocument(); wmpDoc.Load("r:\\music\\wmpdb.xml"); // Build a map of track names to ratings in the source doc XmlNodeList wmpTracks = wmpDoc.SelectNodes("/Library/Track"); Console.WriteLine("Found {0} tracks.", wmpTracks.Count); foreach (XmlNode wmpNode in wmpTracks) { string artist = GetNodeText(wmpNode, "Artist"); string album = GetNodeText(wmpNode, "AlbumTitle"); string title = GetNodeText(wmpNode, "Title"); if (artist.Length > 0 && album.Length > 0 && title.Length > 0) { string ratingString = GetNodeText(wmpNode, "UserRating"); if (ratingString.Length > 0) { int rating = Int32.Parse(ratingString); XmlNode sourceNode = wmpNode.SelectSingleNode("SourceURL"); string key = string.Format("{0}:{1}:{2}", artist, album, title); switch (rating) { case 0: rating = 20; break; case 25: rating = 40; break; case 50: rating = 60; break; case 75: rating = 80; break; } ratings[key] = rating; } } } // Apply those to the destination XmlNodeList root = iTunesDoc.SelectNodes("/plist/dict/dict/dict"); foreach (XmlNode trackNode in root) { ProcessTrack(trackNode); } Console.WriteLine("Matched " + ratingsMatched); iTunesDoc.Save("c:\\iTunes Music Library (with Ratings).xml"); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } } // Passed a node from the play list // // Track ID35 // NameEverybody's Got A Story // ArtistAmanda Marshall // ComposerAmanda Marshall/Billy Mann/The Molecules // AlbumEverybody's Got A Story // GenreRock // KindMPEG audio file // Size6231020 // Total Time252055 // Track Number1 // Year2002 // Date Modified2005-01-17T16:03:26Z // Date Added2005-02-26T06:55:12Z // Bit Rate197 // Sample Rate44100 // Commentswww.allofmp3.com // Track TypeFile // Locationfile://localhost/Users/stevex/Music/iTunes/iTunes%20Music/Amanda%20Marshall/Everybody's%20Got%20A%20Story/01%20Everybody's%20Got%20A%20Story.mp3 // File Folder Count4 // Library Folder Count1 // void ProcessTrack(XmlNode trackNode) { string album = ""; string artist = ""; string title = ""; int ratingIdx = -1; for (int i=0; i