/// <summary> /// Add a new MediaItem to the database. /// </summary> /// <param name="mi">The Item to add to the database</param> public void add(MediaItem mi) { if (mi.Type == MediaItem.types.MP3) { musicTable.Rows.Add(new object[] { mi.TrackID, mi.Title, mi.Artist, mi.Album, mi.Filename, mi.Year, mi.Genre, mi.Length, mi }); } }
private void parseMhod(MediaItem media) { byte[] buff = new byte[4]; long position = strDB.Position; debug("Found mhod"); seek(8); //skip over mhod to total length strDB.Read(buff, 0, 4); //read total length long totalLength = System.BitConverter.ToUInt32(buff, 0); debug("Size of this mhod is " + totalLength); strDB.Read(buff, 0, 4); //now at position 20 of this mhod long type = System.BitConverter.ToUInt32(buff, 0); if ((type == (long)Types.Album) || (type == (long)Types.Artist) || (type == (long)Types.Genre) || (type == (long)Types.Location) || (type == (long)Types.Title)) //artist, album, title, filename { debug("Read type : " + type); seek(12); strDB.Read(buff, 0, 4); //read length of string long strLen = System.BitConverter.ToUInt32(buff, 0); debug("String length is " + strLen); seek(8); //now at position 40 of mhod (actual string) byte[] str = new byte[strLen]; strDB.Read(str, 0, str.Length); String theString = new UnicodeEncoding().GetString(str); switch (type) { case (long)Types.Title: media.Title = theString; break; case (long)Types.Album: media.Album = theString; break; case (long)Types.Artist: media.Artist = theString; break; case (long)Types.Location: media.Filename = iPodDrive + theString.Replace(':', '\\'); break; case (long)Types.Genre: media.Genre = theString; break; default: break; } } strDB.Seek(position, SeekOrigin.Begin); strDB.Seek(totalLength, SeekOrigin.Current); }
private void parseMhit() { long position; byte[] buffer = new byte[4]; //most stuff in iTunesDB is done in 4s.. position = strDB.Position; //save our current position strDB.Read(buffer, 0, 4); //read header length - we are now at position 8 long header = System.BitConverter.ToUInt32(buffer, 0); debug("Header length is: " + header); seek(4); //skip over total length of mhit - now at position 12 strDB.Read(buffer, 0, 4); //read number of mhods (strings) long numMhods = System.BitConverter.ToUInt32(buffer, 0); debug("Number of mhods: " + numMhods); seek(28); //skip over various fields - now at position 44 debug("Reading track number"); strDB.Read(buffer, 0, 4); //read track number - now at position 48 long trackNum = System.BitConverter.ToUInt32(buffer, 0); debug("Reading year"); seek(4); //seek to year (position 52 of mhit) strDB.Read(buffer, 0, 4); int year = (int) System.BitConverter.ToUInt32(buffer, 0); seek(152); //seek to track type (position 208 of mhit) strDB.Read(buffer, 0, 4); //read track type MediaItem.types trackType = (MediaItem.types)System.BitConverter.ToUInt32(buffer, 0); MediaItem mi = new MediaItem(trackType, trackNum); mi.Year = year; //skip to start of mhods - a mhod is a certain piece of information about the track strDB.Seek(position, SeekOrigin.Begin); //seek back to where the 'header' is - this is the start of the mhods. strDB.Seek(header - 4, SeekOrigin.Current); debug("Parsing mhods.."); for (int i = 0; i < numMhods; i++) { this.parseMhod(mi); } mediaDB.add(mi); //add item to database debug(mi.ToString()); }
/// <summary> /// Parse a filename using the 'regexp' given in FrmSave. /// </summary> /// <param name="mi">MediaItem to parse</param> /// <param name="formatstr">formatString containing the 'regexp'</param> /// <returns></returns> private string parseFileName(MediaItem mi, string formatstr) { string filename = formatstr; filename = filename.Replace("%a", mi.Artist); filename = filename.Replace("%A", mi.Album); filename = filename.Replace("%t", Convert.ToString(mi.Title)); filename = filename.Replace("%y", Convert.ToString(mi.Year)); filename = filename.Replace("%n", Convert.ToString(mi.TrackID)); filename = filename.Replace("%N", mi.TrackID < 10 ? "0" + Convert.ToString(mi.TrackID) : Convert.ToString(mi.TrackID)); filename = filename.Replace("%g", mi.Genre); filename = replaceInvalidChars(filename); return filename; }