public void Updaterecord(string filename) { string tagstring = ""; if (ID3v2Tag.DoesTagExist(filename)) { tagstring = "/V2"; if (ID3v1Tag.DoesTagExist(filename)) { tagstring = "V1" + tagstring; } var id3 = new ID3v2Tag(filename); var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber, id3.Genre, filename, tagstring); ModifyRecord(mytrack); } if (ID3v1Tag.DoesTagExist(filename) && tagstring == "") { tagstring = "V1"; var id3 = new ID3v1Tag(filename); var mytrack = new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], filename, tagstring); ModifyRecord(mytrack); } if (tagstring == "No Tag") { var mytrack = new Track("", "", "", "", "", "", filename, "No Tag"); ModifyRecord(mytrack); } }
private void btnRemoveID3v2_Click(object sender, EventArgs e) { if (string.IsNullOrEmpty(m_Filename)) { MessageBox.Show("No file loaded", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } else { DialogResult result = MessageBox.Show(string.Format("Remove ID3v2 tag from '{0}'?", Path.GetFileName(m_Filename)), "", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (result == DialogResult.Yes) { bool success = ID3v2Tag.RemoveTag(m_Filename); if (success) { MessageBox.Show("ID3v2 tag successfully removed", "", MessageBoxButtons.OK, MessageBoxIcon.Information); } else { MessageBox.Show("ID3v2 tag not found", "", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } btnRemoveID3v2.Enabled = ID3v2Tag.DoesTagExist(m_Filename); ucID3v2.LoadFile(m_Filename); }
public ID3Helper(string filename) { id3info = new UltraID3(); id3info.Read(filename); id3info.ID3v1Tag.Clear(); id3v2tag = id3info.ID3v2Tag; }
private void addImageToolStripMenuItem_Click(object sender, EventArgs e) { FRMImage addimage = new FRMImage(); ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; var trackxml = new XMLutils(appPath + "\\trackxml.xml"); addimage.Artist = filename[0].SubItems[4].Text; addimage.Album = filename[0].SubItems[5].Text; if (addimage.ShowDialog(this) == DialogResult.OK) { foreach (ListViewItem item in filename) { string fname = item.SubItems[1].Text + "\\" + item.SubItems[0].Text; var id3v2 = new ID3v2Tag(fname); var mytrack = new Track(); mytrack.Filename = fname; mytrack.Artist = id3v2.Artist; mytrack.Title = id3v2.Title; mytrack.Album = id3v2.Album; mytrack.Genre = id3v2.Genre; mytrack.Trackno = id3v2.TrackNumber.ToString(); mytrack.Year = id3v2.Year; if (addimage.Getimage() != null) { mytrack.coverimage = addimage.Getimage(); } Miscutils.Savev2tag(mytrack); //ReloadlistviewV2(fname); } } }
public void UltraID3Test() { UltraID3 ultraID3 = new UltraID3(); ultraID3.Read(@"e:\Music\Antenne Bayern Radio\Mirror Dawn.mp3"); testContextInstance.WriteLine(ultraID3.Artist); testContextInstance.WriteLine(ultraID3.Genre); //ultraID3.Genre = "Rock"; //ultraID3.Write(); MPEGFrameInfo mpegFrameInfo = ultraID3.FirstMPEGFrameInfo; if (ultraID3.ID3v1Tag.ExistsInFile) { } ID3v2Tag id3v2Tag = ultraID3.ID3v2Tag; ID3FrameCollection frames = id3v2Tag.Frames; for (int i = 0; i < frames.Count; i++) { ID3v2Frame frame = frames[i]; } id3v2Tag.Genre = "Chillout"; ultraID3.Write(); }
public static void Commercial(ID3v2TagVersion tagVersion, bool useLogo) { if (tagVersion == ID3v2TagVersion.ID3v22) { throw new NotSupportedException(); } IID3v2Tag id3 = new ID3v2Tag(); ICommercial aud = id3.CommercialInfoList.AddNew(); using (MemoryStream ms = new MemoryStream()) { ms.WriteByte(0); // text encoding Write(ms, Encoding.ASCII.GetBytes("usd10.00/cad15.00")); ms.WriteByte(0); // terminate Write(ms, Encoding.ASCII.GetBytes("20070610")); Write(ms, Encoding.ASCII.GetBytes("www.google.com")); ms.WriteByte(0); // terminate ms.WriteByte((byte)ReceivedAs.FileOverTheInternet); Write(ms, Encoding.ASCII.GetBytes("name of seller")); ms.WriteByte(0); // terminate Write(ms, Encoding.ASCII.GetBytes("description")); ms.WriteByte(0); // terminate if (useLogo) { Write(ms, Encoding.ASCII.GetBytes("image/jpeg")); ms.WriteByte(0); // terminate Write(ms, new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 }); } TestFrame(aud, tagVersion, ms.ToArray()); } }
private void CreateAudioFile(string artist, string album, string song) { var outputDirectoryPath = Path.Combine(OutputPath, artist, album); var outputFilePath = Path.Combine(outputDirectoryPath, song + ".mp3"); if (File.Exists(outputFilePath)) { return; } if (!Directory.Exists(outputDirectoryPath)) { Directory.CreateDirectory(outputDirectoryPath); } //if (File.Exists(outputFilePath)) //{ // File.Delete(outputFilePath); //} File.Copy(SourceFile, outputFilePath); var tag = new ID3v2Tag(outputFilePath); tag.Artist = artist; tag.Album = album; tag.AlbumArtist = artist; tag.Title = song; tag.Save(outputFilePath); }
/* * xx xx xx Frame identifier * xx xx xx Frame size excluding frame header * Frame content * Note: Unsynchronisation is done on Tag level, no Compression or Encryption schema defined. */ private static Frame DecodeID3v2_2Frame(Stream s, ID3v2Tag tag) { Frame frame; byte[] frameHeader; byte[] frameContent; string frameID; int frameSize; const int FrameHeaderSize = 6; frameHeader = new byte[FrameHeaderSize]; Util.ReadFully(s, frameHeader); frameID = StringDecoder.DecodeLatin1String(frameHeader, 0, 3); CheckFrameID(frameID, 3); frameSize = NumberConverter.ReadInt32(frameHeader, 3, 3, false); CheckSize(frameSize, s); frameContent = new byte[frameSize]; Util.ReadFully(s, frameContent); frame = FrameFactory.GetFrame(FrameFactory.ID3v2_2IdToID3v2_3Id(frameID)); frame.Flags = FrameFlags.None; frame.DecodeContent(frameContent, tag); return frame; }
private void poptextboxV2(string fdir) { TXTfilename.Text = fdir; pictureBox.Image = null; LABimage.Text = ""; if (ID3v2Tag.DoesTagExist(fdir)) { RDOver2.Checked = true; var id3v2 = new ID3v2Tag(fdir); CMBartist.Text = id3v2.Artist; CMBtitle.Text = id3v2.Title; CMBalbum.Text = id3v2.Album; CMBgenre.Text = id3v2.Genre; CMBtrack.Text = id3v2.TrackNumber; CMByear.Text = id3v2.Year; CMBcomment.Text = id3v2.CommentsList.ToString(); if (id3v2.CommentsList.Count > 0) { CMBcomment.Text = id3v2.CommentsList[0].Value; } if (id3v2.PictureList.Count > 0) { pictureBox.Image = id3v2.PictureList[0].Picture; LABimage.Text = id3v2.PictureList[0].Description.ToString() + "\r\n" + id3v2.PictureList[0].Picture.Size.ToString() + "\r\n" + id3v2.PictureList[0].PictureExtension.ToString(); } } }
private void musicListStore_SelectedIndexChanged(object sender, EventArgs e) { ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; string temp = ""; cleartextbox(); pictureBox.Image = null; LABimage.Text = ""; try { foreach (ListViewItem item in filename) { if (item.SubItems.Count > 1) { temp += item.SubItems[1].Text + "\\" + item.SubItems[0].Text; } } if (File.Exists(temp)) { if (ID3v2Tag.DoesTagExist(temp)) { poptextboxV2(temp); } else if (ID3v1Tag.DoesTagExist(temp)) { poptextboxV1(temp); } } }//end of try catch (Exception ex) { MessageBox.Show("Error " + ex.Message); } }
public static bool SaveTrack(Track track) { var tags = new ID3v2Tag(track.Filename) { Genre = track.Genre.Replace(NoValue, ""), Album = track.Album.Replace(NoValue, ""), TrackNumber = track.TrackNumber.ToString(), LengthMilliseconds = Convert.ToInt32(track.FullLength * 1000M), BPM = track.Bpm.ToString("0.00"), InitialKey = track.Key }; if (track.Artist == track.AlbumArtist) { tags.Artist = track.Artist.Replace(NoValue, ""); tags.Title = track.Title.Replace(NoValue, ""); } else { tags.Artist = track.AlbumArtist.Replace(NoValue, ""); tags.Title = track.Artist.Replace(NoValue, "") + " / " + track.Title.Replace(NoValue, ""); } try { tags.Save(track.Filename); } catch { return(false); } track.OriginalDescription = track.Description; return(true); }
/// <summary> /// Initializes a new instance of the <see cref="Mp3FileInfo"/> class. /// </summary> public Mp3FileInfo(string fileName) { // Save the name of the file. mFileName = fileName; // Parse the file using the tag library. mTag = new ID3v2Tag(fileName); // TODO: Doesn't throw an exception for corrupt or non-MP3 files!!! }
public byte[] EncodeContent(ID3v2Tag tag) { if (tag == null) { throw new ArgumentNullException("tag"); } return EncodeContentCore(tag); }
/* * xx xx xx xx Frame identifier * xx xx xx xx Frame size excluding frame header * xx xx Frame flags * additinal header bytes(group identifier, encryption, compression) * Frame content * Note: Unsynchronisation is done on Tag level, Compression and Encryption on Frame level. */ private static void EncodeID3v2_3Frame(Stream s, Frame frame, ID3v2Tag tag) { byte flagByteHi, flagByteLo, encryptionSymbol = 0; byte[] data = frame.EncodeContent(tag); int additionalBytes = 0, originalSize = data.Length; /* generate frame flags */ flagByteHi = 0; if ((frame.Flags & FrameFlags.PreserveTagAltered) == 0) { /* discard frame if tag altered is 1! */ flagByteHi |= 0x80; } if ((frame.Flags & FrameFlags.PreserveFileAltered) == 0) { /* discard frame if file altered is 1! */ flagByteHi |= 0x40; } if ((frame.Flags & FrameFlags.ReadOnly) == FrameFlags.ReadOnly) { flagByteHi |= 0x20; } flagByteLo = 0; if ((frame.Flags & FrameFlags.Compress) == FrameFlags.Compress) { /* set bit 0x80 in flag and append 4 bytes of uncompressed size after header */ flagByteLo |= 0x80; additionalBytes += 4; data = CompressData(data); } if ((frame.Flags & FrameFlags.Encrypt) == FrameFlags.Encrypt) { /* set bit 0x40 in flag and append 1 byte indicating encryption method after header */ flagByteLo |= 0x40; additionalBytes++; data = EncryptData(data, frame, out encryptionSymbol); } if (frame.GroupIdentifier != Frame.GroupIdNotSet) { flagByteLo |= 0x20; additionalBytes++; } /* Write Header */ StringEncoder.WriteLatin1String(s, frame.FrameId, 4); NumberConverter.WriteInt(data.Length + additionalBytes, s, 4, false); s.WriteByte(flagByteHi); s.WriteByte(flagByteLo); /* Write additional information */ if ((frame.Flags & FrameFlags.Compress) == FrameFlags.Compress) { NumberConverter.WriteInt(originalSize, s, 4, false); } if ((frame.Flags & FrameFlags.Encrypt) == FrameFlags.Encrypt) { s.WriteByte(encryptionSymbol); } if (frame.GroupIdentifier != Frame.GroupIdNotSet) { s.WriteByte((byte)frame.GroupIdentifier); } /* write data */ s.Write(data, 0, data.Length); }
public EditID3v2Tag(ID3v2Tag parent) { this.Parent = parent; for (int i = 0; i < parent.Frames.Count; i++) { base.InsertItem(i, parent.Frames[i]); } }
public MpegAudioFile(BinaryReader reader) { this.id3v2Tag = new ID3v2Tag(reader); this.mpegAudioFrames = ReadFrames(reader).ToArray(); if (reader.BaseStream.Position < reader.BaseStream.Length) { throw new InvalidDataException("Found data after MPEG frames."); } }
public void DecodeContent(byte[] data, ID3v2Tag tag) { if (data == null) { throw new ArgumentNullException("data"); } if (tag == null) { throw new ArgumentNullException("tag"); } DecodeContentCore(data, tag); }
private void LoadFile(string path) { m_Filename = path; ucID3v2.LoadFile(m_Filename); ucID3v1.LoadFile(m_Filename); btnSave.Enabled = true; btnRemoveID3v2.Enabled = ID3v2Tag.DoesTagExist(m_Filename); btnRemoveID3v1.Enabled = ID3v1Tag.DoesTagExist(m_Filename); }
/* * xx xx xx Frame identifier * xx xx xx Frame size excluding frame header * Frame content * Note: Unsynchronisation is done on Tag level, no Compression or Encryption schema defined. */ private static void EncodeID3v2_2Frame(Stream s, Frame frame, ID3v2Tag tag) { string id; byte[] data; id = FrameFactory.ID3v2_3IdToID3v2_2Id(frame.FrameId); data = frame.EncodeContent(tag); StringEncoder.WriteLatin1String(s, id, 3); NumberConverter.WriteInt(data.Length, s, 3, false); s.Write(data, 0, data.Length); }
public MpegAudioFile(ID3v2Tag id3v2Tag, IEnumerable <MpegAudioFrame> mpegAudioFrames) { if (id3v2Tag == null) { throw new ArgumentNullException("id3v2Tag"); } if (mpegAudioFrames == null) { throw new ArgumentNullException("mpegAudioFrames"); } this.id3v2Tag = id3v2Tag; this.mpegAudioFrames = mpegAudioFrames; }
public AudioFile(byte[] content) { this.content = content; var tag = new ID3v2Tag(new MemoryStream(content)); if (tag.PictureList.Count != 0 && tag.PictureList.First().MimeType == PngMimeType) { image = tag.PictureList.First().PictureData; } identity = tag.TagFields().Any(x => x == "") ? UnknownIdentity : string.Join("_", tag.TagFields()); }
public static Track Getv2tags(string fname) { var mytrack = new Track("", "", "", "", "", "", "", ""); if (File.Exists(fname)) { var id3 = new ID3v2Tag(fname); mytrack.Album = id3.Album; mytrack.Artist = id3.Artist; mytrack.Title = id3.Title; mytrack.Trackno = id3.TrackNumber.ToString(); mytrack.Year = id3.Year; } return(mytrack); }
public static void AudioEncryption(ID3v2TagVersion tagVersion) { IID3v2Tag id3 = new ID3v2Tag(); IAudioEncryption aud = id3.AudioEncryptionList.AddNew(); byte[] data = { 0x61, 0x62, 0x63, 0x00, // "abc" 0x00, 0x10, // PreviewStart 0x10, 0x00, // PreviewLength 0x01, 0x02, 0x03, 0x04, 0x05 // Encryption data }; TestFrame(aud, tagVersion, data); }
public void DemoBasicUsageForID3v2() { // Create a new ID3v2 tag. ID3v2 works mostly like ID3v1 from this // perspective, although there are a few enhancements we can use. ID3v2Tag v2Tag = new ID3v2Tag(); // no length restrictions with v2 v2Tag.Album = "An album with a really long name that wouldn't fit into a ID3v1 tag"; v2Tag.Genre = "A genre of my own creation!"; // not restricted to pre-defined genres with v2 // Write our new tag out to a file as ID3v2.3 (for example; v2.2 // and v2.4 would work too, although ID3v2.4 support is scare out // in the real world) v2Tag.WriteTag("basic.tag", ID3Versions.V2_3); // Read the tag back from the file. v2Tag = null; if (!ID3v2Tag.HasTag("basic.tag")) { Console.WriteLine("Hmmmm....something didn't go right here."); } else { v2Tag = ID3v2Tag.ReadTag("basic.tag"); // Some usage possibilities: Console.WriteLine("Album: " + v2Tag.Album); // Make a change and write it back out to the file. v2Tag.Comments = "New comments"; v2Tag.WriteTag("basic.tag", ID3Versions.V2_3); // Show that the change worked. v2Tag = ID3v2Tag.ReadTag("basic.tag"); if (v2Tag.HasComments) { Console.WriteLine("The comments we just added: " + v2Tag.Comments); } else { Console.WriteLine("Hmmmm....something didn't go right here."); } // Some other stuff: ID3Versions version = ID3v2Tag.LookForTag("basic.tag"); Console.WriteLine("ID3 tag found, version: " + version.ToString()); } }
internal static Frame DecodeFrame(Stream s, ID3v2Tag tag) { switch (tag.Version) { case ID3v2Version.ID3v2_2: return DecodeID3v2_2Frame(s, tag); case ID3v2Version.ID3v2_3: return DecodeID3v2_3Frame(s, tag); case ID3v2Version.ID3v2_4: return DecodeID3v2_4Frame(s, tag); default: throw new InvalidEnumArgumentException("tag.Version", (int)tag.Version, typeof(ID3v2Version)); } }
private void ScanDirectory(object basePathObject) { int totalFiles = 0; BindingList <Track> trackList = new BindingList <Track>(); try { string basePath = (string)basePathObject; DirectoryInfo di = new DirectoryInfo(basePath); FileInfo[] fileList = di.GetFiles("*.mp3", SearchOption.AllDirectories); EnableCancelButton(); totalFiles = fileList.Length; for (int i = 0; i < totalFiles; i++) { if (m_CancelScanning) { totalFiles = i; break; } IID3v2Tag id3 = new ID3v2Tag(fileList[i].FullName); trackList.Add(new Track { Artist = id3.Artist, Title = id3.Title, Album = id3.Album, Year = id3.Year, Genre = id3.Genre, FileName = fileList[i].Name }); if ((i % 100) == 0) { UpdateProgress(i * 100 / totalFiles); } } } finally { EndRecursiveScanning(totalFiles, trackList); } }
public bool setTitle(string n) { bool ret = true; try { IID3v2Tag fileInfo = new ID3v2Tag(getFullPath()); fileInfo.Title = n; fileInfo.Save(getFullPath()); this.title = n; } catch { Console.WriteLine("did not save Title to ID3 tag\n" + getFullPath() + "\nif file is open, close it and try again"); ret = false; } return(ret); }
public bool setBPM(string n) { bool ret = true; try { IID3v2Tag fileInfo = new ID3v2Tag(getFullPath()); fileInfo.BPM = n; fileInfo.Save(getFullPath()); this.BPM = Int32.Parse(n); } catch { Console.WriteLine("did not save BPM to ID3 tag\n" + getFullPath() + "\n* if file is open, close it and try again\n* check that you enterd an integer"); ret = false; } return(ret); }
internal static void EncodeFrame(Stream s, Frame frame, ID3v2Tag tag) { switch (tag.Version) { case ID3v2Version.ID3v2_2: EncodeID3v2_2Frame(s, frame, tag); break; case ID3v2Version.ID3v2_3: EncodeID3v2_3Frame(s, frame, tag); break; case ID3v2Version.ID3v2_4: EncodeID3v2_4Frame(s, frame, tag); break; default: throw new InvalidEnumArgumentException("tag.Version", (int)tag.Version, typeof(ID3v2Version)); } }
private string Getnewtrack(string fname) { string ntn = COMBrename.Text; Track mytrack = new Track("", "", "", "", "", "", "", ""); string extn = Path.GetExtension(fname); if (ID3v1Tag.DoesTagExist(fname)) { mytrack = Miscutils.Getv1tags(fname); } else if (ID3v2Tag.DoesTagExist(fname)) { mytrack = Miscutils.Getv2tags(fname); } if (ntn.Contains("%TRACKNUMBER%")) { ntn = ntn.Replace("%TRACKNUMBER%", Miscutils.PaddedNumber(mytrack.Trackno)); } if (ntn.Contains("%ARTIST%")) { ntn = ntn.Replace("%ARTIST%", mytrack.Artist); } if (ntn.Contains("%ALBUM%")) { ntn = ntn.Replace("%ALBUM%", mytrack.Album); } if (ntn.Contains("%TITLE%")) { ntn = ntn.Replace("%TITLE%", mytrack.Title); } if (ntn.Contains("%FILENAME%")) { ntn = ntn.Replace("%FILENAME%", Path.GetFileNameWithoutExtension(fname)); } ntn = Miscutils.stripchar(ntn); if (TXTrepbefore.Text != "") { ntn = ntn.Replace(TXTrepbefore.Text, TXTrepafter.Text); } return(ntn + extn); }
internal static byte[] EncodeTag(ID3v2Tag tag) { using (MemoryStream ms = new MemoryStream(8096)) { switch (tag.Version) { case ID3v2Version.ID3v2_2: EncodeID3v2_2Tag(ms, tag); break; case ID3v2Version.ID3v2_3: EncodeID3v2_3Tag(ms, tag); break; case ID3v2Version.ID3v2_4: EncodeID3v2_4Tag(ms, tag); break; } return ms.ToArray(); } }
public static Boolean Savev2tag(Track mytrack) { if (!File.Exists(mytrack.Filename)) { MessageBox.Show("File Does not exist " + mytrack.Filename); return(false); } var trackxml = new XMLutils(appPath + "\\trackxml.xml"); removeID3v2(mytrack.Filename); var id3 = new ID3v2Tag(mytrack.Filename); if (!String.IsNullOrEmpty(mytrack.Filename) && File.Exists(mytrack.Filename)) { id3.Album = mytrack.Album; id3.Artist = mytrack.Artist; id3.Title = mytrack.Title; id3.TrackNumber = mytrack.Trackno; id3.Year = mytrack.Year; id3.Genre = mytrack.Genre; if (mytrack.coverimage != null) { id3.PictureList.Clear(); IAttachedPicture picture = id3.PictureList.AddNew(); picture.PictureData = ConvertBitMapToByteArray(mytrack.coverimage); picture.PictureType = PictureType.CoverFront; } id3.Save(mytrack.Filename); trackxml.ModifyRecord(mytrack); } if (ID3v2Tag.DoesTagExist(mytrack.Filename)) { trackxml.Updaterecord(mytrack.Filename); return(true); } else { return(false); } }
public static Boolean removeID3v2(string fname) { Boolean success = false; var trackxml = new XMLutils(appPath + "\\trackxml.xml"); if (!String.IsNullOrEmpty(fname) && File.Exists(fname)) { var id3 = new ID3v2Tag(fname); if (id3.PictureList.Count > 0) { id3.PictureList.Clear(); } success = ID3v2Tag.RemoveTag(fname); } if (success) { trackxml.Updaterecord(fname); } return(success); }
private void BTNcopy_Click(object sender, EventArgs e) { if (musicListStore.SelectedItems.Count > 0) { var copywin = new FRMcopy(); string temp = ""; ListView.SelectedListViewItemCollection filename = this.musicListStore.SelectedItems; copywin.GetGenre = musicListStore.SelectedItems[0].SubItems[8].Text; if (copywin.ShowDialog(this) == DialogResult.OK) { if (copywin.CopyV1) { foreach (ListViewItem item in filename) { temp = item.SubItems[1].Text + "\\" + item.SubItems[0].Text; if (File.Exists(temp) & ID3v1Tag.DoesTagExist(temp)) { var id3 = new ID3v1Tag(temp); Miscutils.Savev2tag(new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), GenreHelper.GenreByIndex[id3.GenreIndex], temp, "V1/V2")); ReloadlistviewV2(item); } } } if (copywin.CopyV2) { foreach (ListViewItem item in filename) { temp = item.SubItems[1].Text + "\\" + item.SubItems[0].Text; if (File.Exists(temp) & ID3v2Tag.DoesTagExist(temp)) { var id3 = new ID3v2Tag(temp); string gen = copywin.GetGenre; Miscutils.Savev1tag(new Track(id3.Artist, id3.Title, id3.Album, id3.Year, id3.TrackNumber.ToString(), gen, temp, "V1/V2")); ReloadlistviewV1(item); } } } } }//end musicstore setected }
private static long ComputePaddingSize(long curSize, ID3v2Tag tag) { long paddingLen; if (tag.PaddingMode == PaddingMode.PadToSize) { paddingLen = tag.PaddingSize - curSize; } else if (tag.PaddingMode == PaddingMode.PadFixAmount) { paddingLen = tag.PaddingSize; } else { paddingLen = 0; } if ((tag.Flags & ID3v2TagFlags.Footer) == ID3v2TagFlags.Footer) { paddingLen -= 10; } if (paddingLen < 0) { paddingLen = 0; } return paddingLen; }
/* * ID3 Tag Identifier * 02 00 2 bytes Version information * xx Tag flags * xx xx xx xx Tag size excluding header as sync safe integer * {Frames} * [Padding] included in tag size * * Note: Unsync is applied on tag level; compression, encryption, footer, * ExtendedHeader and experimental are not allowed. * */ private static void EncodeID3v2_2Tag(Stream s, ID3v2Tag tag) { StringEncoder.WriteLatin1String(s, "ID3", 3); s.WriteByte(0x02); s.WriteByte(0x00); /* write flag byte */ if ((tag.Flags & ID3v2TagFlags.Unsync) == ID3v2TagFlags.Unsync) { s.WriteByte((byte)0x80); } else { s.WriteByte((byte)0x00); } /* skip tag size */ s.Position += 4L; WriteContentToStream(s, tag); s.SetLength(s.Length + ComputePaddingSize(s.Length, tag)); /* update tag size */ s.Position = 6L; NumberConverter.WriteInt(s.Length - 10L, s, 4, true); }
public void ReloadlistviewV1(ListViewItem item) { string tagstring = "No Tag"; if (ID3v2Tag.DoesTagExist(item.SubItems[1].Text + "\\" + item.SubItems[0].Text)) { tagstring = "/V2"; } if (ID3v1Tag.DoesTagExist(item.SubItems[1].Text + "\\" + item.SubItems[0].Text)) { var id3 = new ID3v1Tag(item.SubItems[1].Text + "\\" + item.SubItems[0].Text); item.SubItems[2].Text = "V1" + tagstring; item.SubItems[3].Text = id3.Title; item.SubItems[4].Text = id3.Artist; item.SubItems[5].Text = id3.Album; item.SubItems[7].Text = id3.Year; item.SubItems[6].Text = id3.TrackNumber.ToString(); item.SubItems[8].Text = GenreHelper.GenreByIndex[id3.GenreIndex]; // Miscutils.Updaterecord(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, id3.Album, // id3.Artist, id3.GenreIndex.ToString(), id3.Title, id3.TrackNumber.ToString(), id3.Year); } else { item.SubItems[2].Text = tagstring; item.SubItems[3].Text = ""; item.SubItems[4].Text = ""; item.SubItems[5].Text = ""; item.SubItems[7].Text = ""; item.SubItems[6].Text = ""; item.SubItems[8].Text = ""; if (tagstring == "No Tag") { // Miscutils.Updaterecord(item.SubItems[1].Text + "\\" + item.SubItems[0].Text, item.SubItems[1].Text, // "No Tag", "", "", "", ""); } } }
private void OnLoadFile(string fileName) { FullFileName = fileName; ShortFileName = Path.GetFileName(fileName); ID3v2 = new ID3v2Tag(fileName); AudioFile = IdSharp.AudioInfo.AudioFile.Create(fileName, true); if (ID3v2.PictureList == null || ID3v2.PictureList.Count == 0) { PictureCollection = new ObservableCollection <Picture>(); } else { var pictureCollection = new ObservableCollection <Picture>(); foreach (var apic in ID3v2.PictureList) { pictureCollection.Add(new Picture(apic)); } PictureCollection = pictureCollection; } // TODO: Comments /*Comment = null; * if (_id3v2.CommentsList.Count > 0) * { * Comment = _id3v2.CommentsList[0].Value; * }*/ //PlayLength = audioFile.TotalSeconds; //Bitrate = audioFile.Bitrate; DescriptiveLameTagReader lameTagReader = new DescriptiveLameTagReader(fileName); EncoderPreset = string.Format("{0} {1}", lameTagReader.LameTagInfoEncoder, lameTagReader.UsePresetGuess == UsePresetGuess.NotNeeded ? lameTagReader.Preset : lameTagReader.PresetGuess); CanSave = true; }
public static void EncryptionMethod(ID3v2TagVersion tagVersion, bool useData) { if (tagVersion == ID3v2TagVersion.ID3v22) { throw new NotSupportedException(); } IID3v2Tag id3 = new ID3v2Tag(); IEncryptionMethod aud = id3.EncryptionMethodList.AddNew(); using (MemoryStream ms = new MemoryStream()) { Write(ms, Encoding.ASCII.GetBytes("http://owneridentifier.org")); ms.WriteByte(0); // terminate ms.WriteByte(0x95); // method symbol if (useData) { Write(ms, new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04 }); } TestFrame(aud, tagVersion, ms.ToArray()); } }
/// <summary> /// Sets the track album cover. /// </summary> /// <param name="track">The track.</param> /// <param name="image">The image.</param> public static void SetTrackAlbumCover(Track track, Image image) { if (track == null) { return; } if (image == null) { return; } if (!ID3v2Tag.DoesTagExist(track.Filename)) { return; } var tags = new ID3v2Tag(track.Filename); if (tags.PictureList.Count > 0) { tags.PictureList.Clear(); } var picture = tags.PictureList.AddNew(); if (picture != null) { picture.PictureType = PictureType.CoverFront; picture.MimeType = "image/jpeg"; using (var stream = new MemoryStream()) { ImageHelper.SaveJpg(stream, image); picture.PictureData = stream.ToArray(); } } tags.Save(track.Filename); }
private void ReadTagsFromFile() { if (Status != ItemStatus.Complete) { return; } if (!CompleteDestination.EndsWith(".mp3", StringComparison.CurrentCultureIgnoreCase)) { return; } try { ID3Tag tag = ID3v2Tag.ReadTag(CompleteDestination); if (tag == null) { tag = ID3v1Tag.ReadTag(CompleteDestination); if (tag == null) { tag = new ID3v2Tag(); } } TrackTitleTag = tag.Title; AlbumTag = tag.Album; ArtistTag = tag.Artist; GenreTag = tag.Genre; _tagsSet = true; } catch (Exception ex) { Trace.TraceError("Error: unable to read ID3 Tag for file: " + CompleteDestination + ". " + ex.Message); } }
private static void WriteContentToStream(Stream s, ID3v2Tag tag) { if ((tag.Flags & ID3v2TagFlags.Unsync) == ID3v2TagFlags.Unsync) { UnsyncFilterStream unsyncFilterStream = new UnsyncFilterStream(s, UnsyncMode.Write, true); foreach (Frame f in tag.Frames) { FrameEncoder.EncodeFrame(unsyncFilterStream, f, tag); } unsyncFilterStream.ApplyFinalization(); } else { foreach (Frame f in tag.Frames) { FrameEncoder.EncodeFrame(s, f, tag); } } }
private static byte[] GetFrameRawData(ID3v2Tag tag) { using (MemoryStream ms = new MemoryStream(1024)) { foreach (Frame f in tag.Frames) { FrameEncoder.EncodeFrame(ms, f, tag); } return ms.ToArray(); } }
/* * Tagheader * [Extended header] * {Frames} * [Padding] included in tag size * * Note: Unsync is applied on tag level; footer is not allowed. * */ private static ID3v2Tag DecodeID3v2_3Tag(Stream s, byte flag, int tagSize, ReadMode mode) { byte[] tagContent; int offset = 0; ID3v2Tag tag; tag = new ID3v2Tag(); tag.Version = ID3v2Version.ID3v2_3; tag.ExtendedHeader = null; tag.Flags = ID3v2TagFlags.None; tagContent = new byte[tagSize]; Util.ReadFully(s, tagContent); /* handle tag flags */ if ((flag & 0x80) != 0) { tag.Flags |= ID3v2TagFlags.Unsync; tagContent = Util.RemoveUnsynchronization(tagContent); } if ((flag & 0x40) != 0) { tag.ExtendedHeader = new ExtendedHeader(); offset = DecodeID3v2_3ExtendedHeader(tagContent, tag.ExtendedHeader); } if ((flag & 0x20) != 0) { tag.Flags |= ID3v2TagFlags.Experimental; } if ((flag & 0x1F) != 0) { /* undefined flags set */ throw new ID3TagException("Undefined flags set."); } ReadFrames(tagContent, offset, tag, mode); return tag; }
/* * ID3 Tag identifier * 04 00 2 bytes version * xx Tag flags * xx xx xx xx Tag size excluding header and footer as syncsafe int * [Extended header] * {Frames} * [Padding] * [Footer] */ private static void EncodeID3v2_4Tag(Stream s, ID3v2Tag tag) { byte flagByte = 0; long paddingLen, size; const long TagHeaderSize = 10L; if ((tag.Flags & ID3v2TagFlags.Unsync) == ID3v2TagFlags.Unsync) { flagByte |= 0x80; } if (tag.ExtendedHeader != null) { flagByte |= 0x40; } if ((tag.Flags & ID3v2TagFlags.Experimental) == ID3v2TagFlags.Experimental) { flagByte |= 0x20; } if ((tag.Flags & ID3v2TagFlags.Footer) == ID3v2TagFlags.Footer) { flagByte |= 0x10; } StringEncoder.WriteLatin1String(s, "ID3", 3); s.WriteByte(0x04); s.WriteByte(0x00); s.WriteByte(flagByte); /* skip size */ s.Position += 4; if (tag.ExtendedHeader != null) { byte[] frameData = GetFrameRawData(tag); long crc = -1L; if ((tag.ExtendedHeader.Flags & ExtendedHeaderFlags.CrcPresent) == ExtendedHeaderFlags.CrcPresent) { /* CRC is calculated on frame data and padding */ Crc32 crcCalc = new Crc32(); crcCalc.UpdateCrc(frameData); crcCalc.UpdateCrcWithZero(ComputePaddingSize(frameData.Length + TagHeaderSize, tag)); crc = crcCalc.Crc; } EncodeID3v2_4ExtendedHeader(s, tag.ExtendedHeader, crc); s.Write(frameData, 0, frameData.Length); } else { foreach (Frame f in tag.Frames) { FrameEncoder.EncodeFrame(s, f, tag); } } paddingLen = ComputePaddingSize(s.Length, tag); s.SetLength(s.Length + paddingLen); size = s.Length - TagHeaderSize; if ((tag.Flags & ID3v2TagFlags.Footer) == ID3v2TagFlags.Footer) { s.Position = s.Length - 1L; StringEncoder.WriteLatin1String(s, "3DI", 3); s.WriteByte(0x04); s.WriteByte(0x00); s.WriteByte(flagByte); NumberConverter.WriteInt(size, s, 4, true); } s.Position = 6L; NumberConverter.WriteInt(size, s, 4, true); }
/* * ID3 Tag Identifier * 03 00 2 bytes Version information * xx Tag flags * xx xx xx xx Tag size excluding header but including extended header as sync safe integer * [Extended header] * {Frames} * [Padding] included in tag size * * Note: Unsync is applied on tag level; footer is not allowed. * */ private static void EncodeID3v2_3Tag(Stream s, ID3v2Tag tag) { long paddingLen; byte flags = 0; const long TagHeaderSize = 10L; const long ExtHeaderSizeWithCrc = 14L; const long ExtHeaderSizeWithoutCrc = 10L; /* generate flag byte */ if ((tag.Flags & ID3v2TagFlags.Unsync) == ID3v2TagFlags.Unsync) { flags |= 0x80; } if (tag.ExtendedHeader != null) { flags |= 0x40; } if ((tag.Flags & ID3v2TagFlags.Experimental) == ID3v2TagFlags.Experimental) { flags |= 0x20; } /* write tag header */ StringEncoder.WriteLatin1String(s, "ID3", 3); s.WriteByte(0x03); s.WriteByte(0x00); s.WriteByte(flags); /* skip size */ s.Position += 4; if (tag.ExtendedHeader != null) { long crc; byte[] frameData = GetFrameRawData(tag); if ((tag.ExtendedHeader.Flags & ExtendedHeaderFlags.CrcPresent) == ExtendedHeaderFlags.CrcPresent) { crc = Crc32.ComputeCrc(frameData); paddingLen = ComputePaddingSize(frameData.Length + TagHeaderSize + ExtHeaderSizeWithCrc, tag); } else { crc = -1L; paddingLen = ComputePaddingSize(frameData.Length + TagHeaderSize + ExtHeaderSizeWithoutCrc, tag); } if ((tag.Flags & ID3v2TagFlags.Unsync) == ID3v2TagFlags.Unsync) { UnsyncFilterStream unsyncFilterStream = new UnsyncFilterStream(s, UnsyncMode.Write, true); EncodeID3v2_3ExtendedHeader(unsyncFilterStream, tag.ExtendedHeader, paddingLen, crc); unsyncFilterStream.Write(frameData, 0, frameData.Length); unsyncFilterStream.ApplyFinalization(); } else { EncodeID3v2_3ExtendedHeader(s, tag.ExtendedHeader, paddingLen, crc); s.Write(frameData, 0, frameData.Length); } } else { /* no extended header */ WriteContentToStream(s, tag); paddingLen = ComputePaddingSize(s.Length, tag); } /* update tag size */ s.SetLength(s.Length + paddingLen); s.Position = 6; NumberConverter.WriteInt(s.Length - TagHeaderSize, s, 4, true); }
private static void Writev2Tag(Stream s, ID3v2Tag id3v2tag) { byte[] encodedTag; byte[] tagHeader = new byte[ID3v2TagDecoder.TagHeaderSize]; bool streamHasID3v2Tag; int id3v2TagSize; s.Seek(0, SeekOrigin.Begin); s.Read(tagHeader, 0, ID3v2TagDecoder.TagHeaderSize); streamHasID3v2Tag = ID3v2TagDecoder.HasID3v2Tag(tagHeader); id3v2TagSize = ID3v2TagDecoder.GetID3v2TagSize(tagHeader); if (id3v2tag != null) { /* write tag to stream; check if there is already one. */ encodedTag = ID3v2TagEncoder.EncodeTag(id3v2tag); if (streamHasID3v2Tag) { /* stream already contains a tag; check if new tag fits into old one */ if (encodedTag.Length == id3v2TagSize) { s.Seek(0, SeekOrigin.Begin); } else { /* delete the old tag and leave enough space for the new one */ StreamCopy(s, id3v2TagSize, encodedTag.Length); } } else { /* stream does not contain a tag; make space for the new one */ StreamCopy(s, 0, encodedTag.Length); } s.Write(encodedTag, 0, encodedTag.Length); } else { /* delete tag in stream if there is one */ if (streamHasID3v2Tag) { StreamCopy(s, id3v2TagSize, 0); } } }
public void Load(Stream s, ReadMode mode) { if (s == null) { throw new ArgumentNullException("s"); } if (!s.CanRead) { throw new ArgumentException("Cannot read from Stream.", "s"); } if (!Enum.IsDefined(typeof(ReadMode), mode)) { throw new InvalidEnumArgumentException("mode", (int)mode, typeof(ReadMode)); } try { id3v2Tag = ID3v2TagDecoder.DecodeTag(s, mode); } catch { if (mode == ReadMode.ThrowOnError) { throw; } id3v2Tag = null; } if (s.CanSeek && s.Length >= ID3v1Tag.TagLength) { s.Seek(-ID3v1Tag.TagLength, SeekOrigin.End); try { id3v1Tag = ID3v1TagDecoder.DecodeTag(s); } catch { if (mode == ReadMode.ThrowOnError) { throw; } id3v1Tag = null; } } else { id3v1Tag = null; } }
public ID3Helper(ID3v2Tag tags) { id3v2tag = tags; }
protected abstract byte[] EncodeContentCore(ID3v2Tag tag);
/* * Tag header * {Frames} * [padding] * * Note: unsync is applied on tag level(after header); no ext. header or compression */ private static ID3v2Tag DecodeID3v2_2Tag(Stream s, byte tagFlag, int tagSize, ReadMode mode) { byte[] tagContent; ID3v2Tag tag; tag = new ID3v2Tag(); tag.Version = ID3v2Version.ID3v2_2; tag.ExtendedHeader = null; tag.Flags = ID3v2TagFlags.None; tagContent = new byte[tagSize]; Util.ReadFully(s, tagContent); /* handle tag flags */ if ((tagFlag & 0x80) != 0) { tag.Flags |= ID3v2TagFlags.Unsync; tagContent = Util.RemoveUnsynchronization(tagContent); } if ((tagFlag & 0x40) != 0) { throw new ID3ParseException("Compression bit set although no compression schema defined in 2.2."); } if ((tagFlag & 0x3F) != 0) { /* some other undefined flags set */ throw new ID3ParseException("Undefined tag flag(s) set."); } ReadFrames(tagContent, 0, tag, mode); return tag; }
/* * Tagheader * [Extended header] * {Frames} * [Padding] * [Footer] * * Note footer is not included in size; unsync is done on frame level */ private static ID3v2Tag DecodeID3v2_4Tag(Stream s, byte flag, int tagSize, ReadMode mode) { byte[] tagContent; int offset = 0; ID3v2Tag tag; tag = new ID3v2Tag(); tag.Version = ID3v2Version.ID3v2_4; tag.ExtendedHeader = null; tag.Flags = ID3v2TagFlags.None; tagContent = new byte[tagSize]; Util.ReadFully(s, tagContent); if ((flag & 0x80) != 0) { /* all frames are really unsychronized */ tag.Flags = ID3v2TagFlags.Unsync; } if ((flag & 0x40) != 0) { tag.ExtendedHeader = new ExtendedHeader(); offset = DecodeID3v2_4ExtendedHeader(tagContent, tag.ExtendedHeader); } if ((flag & 0x20) != 0) { tag.Flags |= ID3v2TagFlags.Experimental; } if ((flag & 0x10) != 0) { tag.Flags |= ID3v2TagFlags.Footer; const int footerSize = 10; byte[] footer = new byte[footerSize]; Util.ReadFully(s, footer); if (footer[0] != '3' || footer[1] != 'D' || footer[2] != 'I' || footer[3] != 0x04 || footer[4] != 0x00 || footer[5] != flag || (int)NumberConverter.ReadInt32(footer, 6, 4, true) != tagSize) { throw new ID3ParseException("Error while parsing footer."); } } if ((flag & 0x0F) != 0) { throw new ID3ParseException("Undefined flag(s) set"); } ReadFrames(tagContent, offset, tag, mode); return tag; }
private static void ReadFrames(byte[] tagContent, int offset, ID3v2Tag tag, ReadMode mode) { MemoryStream s = new MemoryStream(tagContent, offset, tagContent.Length - offset, false); while (offset + s.Position < tagContent.Length && tagContent[offset + s.Position] != 0x00) { try { tag.Frames.Add(FrameDecoder.DecodeFrame(s, tag)); } catch { if (mode == ReadMode.ThrowOnError) { throw; } } } s.Close(); }
/* * xx xx xx xx Frame identifier * xx xx xx xx Frame size excluding frame header as sync safe integer * xx xx Frame flags * additinal header bytes(group identifier, encryption, compression, data length indicator) * Frame content * Note: Unsynchronisation, Compression and Encryption is done on Frame level. */ private static Frame DecodeID3v2_4Frame(Stream s, ID3v2Tag tag) { Frame frame; byte[] frameHeader; byte[] frameContent; string frameID; int frameSize, dataLengthIndicator = -1; bool unsyncApplied = false; byte encryptionMethodSymbol = 0; const int TagHeaderSize = 10; frameHeader = new byte[TagHeaderSize]; Util.ReadFully(s, frameHeader); frameID = StringDecoder.DecodeLatin1String(frameHeader, 0, 4); CheckFrameID(frameID, 4); frameSize = NumberConverter.ReadInt32(frameHeader, 4, 4, true); CheckSize(frameSize, s); frame = FrameFactory.GetFrame(frameID); frame.Flags = FrameFlags.None; /* two flag bytes 8 and 9 */ if ((frameHeader[8] & 0x40) == 0) { frame.Flags |= FrameFlags.PreserveTagAltered; } if ((frameHeader[8] & 0x20) == 0) { frame.Flags |= FrameFlags.PreserveFileAltered; } if ((frameHeader[8] & 0x10) != 0) { frame.Flags |= FrameFlags.ReadOnly; } if ((frameHeader[8] & 0x8F) != 0) { throw new ID3ParseException("Undefined frame flag(s) set."); } if ((frameHeader[9] & 0x40) != 0) { /* read group identifier byte after header */ frame.GroupIdentifier = Util.ReadByte(s); frameSize--; } if ((frameHeader[9] & 0x08) != 0) { /* data length indicator must be set. */ frame.Flags |= FrameFlags.Compress; } if ((frameHeader[9] & 0x04) != 0) { /* 1 byte will be added after header */ frame.Flags |= FrameFlags.Encrypt; encryptionMethodSymbol = Util.ReadByte(s); frameSize--; } if ((frameHeader[9] & 0x02) != 0) { unsyncApplied = true;/* indicates that unsync was applied to this frame */ tag.Flags |= ID3v2TagFlags.Unsync; /* indicates that at least one frame in the tag is unsynchronized. */ } if ((frameHeader[9] & 0x01) != 0) { /* data length indicator added, 4 bytes syncsafe int */ dataLengthIndicator = NumberConverter.ReadInt32(s, 4, true); frameSize -= 4; } if ((frameHeader[9] & 0xB0) != 0) { throw new ID3ParseException("Undefined frame flag(s) set."); } frameContent = new byte[frameSize]; Util.ReadFully(s, frameContent); if (unsyncApplied) { frameContent = Util.RemoveUnsynchronization(frameContent); } if ((frame.Flags & FrameFlags.Encrypt) == FrameFlags.Encrypt) { frameContent = DecryptData(frameContent, encryptionMethodSymbol); } if ((frame.Flags & FrameFlags.Compress) == FrameFlags.Compress) { if (dataLengthIndicator == -1) { throw new ID3ParseException("Frame is compressed but data length indicator bit is not set."); } frameContent = DecompressData(frameContent, dataLengthIndicator); } frame.DecodeContent(frameContent, tag); return frame; }
/* * xx xx xx xx Frame identifier * xx xx xx xx Frame size excluding frame header * xx xx Frame flags * additinal header bytes(group identifier, encryption, compression) * Frame content * Note: Unsynchronisation is done on Tag level, Compression and Encryption on Frame level. */ private static Frame DecodeID3v2_3Frame(Stream s, ID3v2Tag tag) { Frame frame; byte[] frameHeader; byte[] frameContent; string frameID; byte encryptionMethodSymbol = 0; int frameSize, uncompressedSize = 0; const int FrameHeaderSize = 10; frameHeader = new byte[FrameHeaderSize]; Util.ReadFully(s, frameHeader); frameID = StringDecoder.DecodeLatin1String(frameHeader, 0, 4); CheckFrameID(frameID, 4); frameSize = NumberConverter.ReadInt32(frameHeader, 4, 4, false); CheckSize(frameSize, s); frame = FrameFactory.GetFrame(frameID); frame.Flags = FrameFlags.None; /* two flag bytes 8 and 9 */ if ((frameHeader[8] & 0x80) == 0) { frame.Flags |= FrameFlags.PreserveTagAltered; } if ((frameHeader[8] & 0x40) == 0) { frame.Flags |= FrameFlags.PreserveFileAltered; } if ((frameHeader[8] & 0x20) != 0) { frame.Flags |= FrameFlags.ReadOnly; } if ((frameHeader[8] & 0x1F) != 0) { throw new ID3ParseException("Undefined frame flag(s) set."); } if ((frameHeader[9] & 0x80) != 0) { /* 4 bytes will be added after header */ frame.Flags |= FrameFlags.Compress; uncompressedSize = NumberConverter.ReadInt32(s, 4, false); frameSize -= 4; } if ((frameHeader[9] & 0x40) != 0) { /* one byte will be added after header */ frame.Flags |= FrameFlags.Encrypt; encryptionMethodSymbol = Util.ReadByte(s); frameSize--; throw new NotImplementedException("Encryption is not yet implemented."); } if ((frameHeader[9] & 0x20) != 0) { /* read group identifier byte after header */ frame.GroupIdentifier = Util.ReadByte(s); frameSize--; } if ((frameHeader[9] & 0x1F) != 0) { throw new ID3TagException("Undefined frame flag(s) set."); } frameContent = new byte[frameSize]; Util.ReadFully(s, frameContent); if ((frame.Flags & FrameFlags.Encrypt) == FrameFlags.Encrypt) { frameContent = DecryptData(frameContent, encryptionMethodSymbol); } if ((frame.Flags & FrameFlags.Compress) == FrameFlags.Compress) { frameContent = DecompressData(frameContent, uncompressedSize); } frame.DecodeContent(frameContent, tag); return frame; }
/* * xx xx xx xx Frame identifier * xx xx xx xx Frame size excluding frame header as sync safe integer * xx xx Frame flags * additinal header bytes(group identifier, encryption, compression, data length indicator) * Frame content * Note: Unsynchronisation, Compression and Encryption is done on Frame level. */ private static void EncodeID3v2_4Frame(Stream s, Frame frame, ID3v2Tag tag) { bool setDataLengthIndicator = false; byte flagByteHi, flagByteLo, encryptionSymbol = 0; byte[] data = frame.EncodeContent(tag); int additionalBytes = 0, originalSize = data.Length; /* build the flag bytes */ flagByteHi = 0; if ((frame.Flags & FrameFlags.PreserveTagAltered) == 0) { flagByteHi |= 0x40; } if ((frame.Flags & FrameFlags.PreserveFileAltered) == 0) { flagByteHi |= 0x20; } if ((frame.Flags & FrameFlags.ReadOnly) == FrameFlags.ReadOnly) { flagByteHi |= 0x20; } flagByteLo = 0; if (frame.GroupIdentifier != Frame.GroupIdNotSet) { /* add one byte after header(group identifier) */ flagByteLo |= 0x40; additionalBytes++; } if ((frame.Flags & FrameFlags.Compress) == FrameFlags.Compress) { flagByteLo |= 0x08; setDataLengthIndicator = true; data = CompressData(data); } if ((frame.Flags & FrameFlags.Encrypt) == FrameFlags.Encrypt) { flagByteLo |= 0x04; additionalBytes++; setDataLengthIndicator = true; data = EncryptData(data, frame, out encryptionSymbol); } if ((tag.Flags & ID3v2TagFlags.Unsync) == ID3v2TagFlags.Unsync) { flagByteLo |= 0x02; setDataLengthIndicator = true; data = Util.ApplyUnsynchronization(data); } if (setDataLengthIndicator) { flagByteLo |= 0x01; additionalBytes += 4; } /* write frame header */ StringEncoder.WriteLatin1String(s, frame.FrameId, 4); NumberConverter.WriteInt(data.Length + additionalBytes, s, 4, true); s.WriteByte(flagByteHi); s.WriteByte(flagByteLo); /* write attached data */ if (frame.GroupIdentifier != Frame.GroupIdNotSet) { s.WriteByte((byte)frame.GroupIdentifier); } if ((frame.Flags & FrameFlags.Encrypt) == FrameFlags.Encrypt) { s.WriteByte(encryptionSymbol); } if (setDataLengthIndicator) { NumberConverter.WriteInt(originalSize, s, 4, true); } s.Write(data, 0, data.Length); }
public bool Equals(ID3v2Tag obj) { return obj.Struct == this.Struct; }
protected abstract void DecodeContentCore(byte[] rawData, ID3v2Tag tag);