Patch: support for embedded lyrics in Mp3 files



Hi all,

I thought it would be cool you were able to type a line of a song into beagle and have it find the song for you.

Many of my Mp3 files contain embedded lyrics using the Lyrics3 extension to ID3v1, so I've added some code to the entagged-sharp library to strip this information and added a line to the audio filter so beagle can grab it.

It only works for Mp3 using the Lyrics3 v2 extension to ID3v1 so far, but if people are interested I could extend it to other filetypes and ID3 formats.

One last thing - this was covered in a bug report at http://www.gnomebangalore.org/pipermail/beagle/2005-February/000103.html though I couldn't find a corresponding entry in the bugzilla.

Cheers,

Tom
Index: Filters/FilterMusic.cs
===================================================================
RCS file: /cvs/gnome/beagle/Filters/FilterMusic.cs,v
retrieving revision 1.17
diff -u -r1.17 FilterMusic.cs
--- Filters/FilterMusic.cs	7 May 2006 09:15:56 -0000	1.17
+++ Filters/FilterMusic.cs	3 Aug 2006 10:08:43 -0000
@@ -38,7 +38,7 @@
 		public FilterMusic ()
 		{
 			// 1: Added duration and bitrate property
-			SetVersion (1);
+			SetVersion (2);
 			
 			// APE / Monkeys Audio
 			AddSupportedFlavor (FilterFlavor.NewFromExtension (".ape"));
@@ -115,6 +115,9 @@
 
 			foreach (string genre in tag.Genres)
 				AddProperty (Beagle.Property.NewKeyword ("fixme:genre", genre));
+
+			foreach (string lyrics in tag.Tag.Get ("LYR")) // Currently only gets Lyric3 v2 tags from Mp3 files.
+				AddProperty (Beagle.Property.New ("fixme:lyrics", lyrics));
 
 			AddProperty (Beagle.Property.NewUnsearched ("fixme:duration", tag.Duration));
 			AddProperty (Beagle.Property.NewUnsearched ("fixme:bitrate", tag.Bitrate));
Index: Filters/entagged-sharp/Mp3/Util/Id3v1TagReader.cs
===================================================================
RCS file: /cvs/gnome/beagle/Filters/entagged-sharp/Mp3/Util/Id3v1TagReader.cs,v
retrieving revision 1.3
diff -u -r1.3 Id3v1TagReader.cs
--- Filters/entagged-sharp/Mp3/Util/Id3v1TagReader.cs	15 Mar 2006 20:17:33 -0000	1.3
+++ Filters/entagged-sharp/Mp3/Util/Id3v1TagReader.cs	3 Aug 2006 10:08:44 -0000
@@ -23,6 +23,7 @@
  *  DEALINGS IN THE SOFTWARE.
  */
 
+using System;
 using System.IO;
 using System.Text;
 using Entagged.Audioformats.Exceptions;
@@ -61,6 +62,58 @@
 			byte genreByte = (byte) mp3Stream.ReadByte();
 			mp3Stream.Seek(0, SeekOrigin.Begin);
 			tag.AddGenre(TagGenres.Get(genreByte));
+			
+			// Lyrics2.00
+			mp3Stream.Seek( -143 , SeekOrigin.End);
+			b = new byte[18];			
+
+			mp3Stream.Read( b, 0, 18 );
+			
+			tagS = Encoding.ASCII.GetString(b);
+			
+			//Check whether the file contains a Lyrics3 v2----------------------
+			if (tagS.IndexOf("LYRICS200") > 0 ) {	
+
+				b[6] = 0; // Why is this here?
+				
+				int lyricsSize = Convert.ToInt32(tagS.Substring(0, tagS.Length - 12));
+				
+				mp3Stream.Seek(-18 - lyricsSize, SeekOrigin.Current);
+				mp3Stream.Read( b, 0, 11 );
+				
+				tagS = Encoding.ASCII.GetString(b);
+				
+				if (tagS.IndexOf("LYRICSBEGIN") == 0) {
+				
+					int bytesToRead = lyricsSize - 11;
+					byte[] b2 = new byte[bytesToRead];
+						
+					bool stampsUsed = false;
+					
+					mp3Stream.Read(b2, 0, bytesToRead);
+					tagS = Encoding.ASCII.GetString(b2);
+					
+					int posn = 0;
+					int size = 0;
+					string data;
+				
+					while (posn < bytesToRead) {
+				
+					size = Convert.ToInt32(tagS.Substring(posn+3, 5));
+					data = tagS.Substring(posn+3+5, size);
+				
+					if (tagS.IndexOf("IND") == posn)
+						if (data.Substring(0,1) == "1")
+							stampsUsed = true;
+					
+					if (tagS.IndexOf("LYR") == posn)
+						tag.Add("LYR", data);
+					
+					posn = posn + size + 8;
+				
+					}		
+				}	
+			}
 
 			return true;
 		}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]