public void WritingTwoArtistsShouldResultInTwoArtistsRead() { string origFile = Path.Combine("Data", "testfile5.flac"); string newFile = Path.Combine("Data", "testfile5_temp.flac"); FileHelper.GetNewFile(origFile, newFile); using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac"))) { var vorbisComment = new VorbisComment(); vorbisComment["ARTIST"] = new VorbisCommentValues(new string[] { "Artist A", "Artist B" }); file.Metadata.Add(vorbisComment); file.Save(); } using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac"))) { Assert.IsNotNull(file.VorbisComment); var artistValues = file.VorbisComment["ARTIST"]; Assert.AreEqual(2, artistValues.Count); Assert.AreEqual("Artist A", artistValues[0]); Assert.AreEqual("Artist B", artistValues[1]); } }
public void OpenFlacFileAndCheckVorbisComment() { using (FlacFile file = new FlacFile(@"Data\testfile1.flac")) { //Assert.IsTrue(file.Metadata.Count > 0, "No metadata blocks were found for the test file, this is not correct!"); foreach (MetadataBlock block in file.Metadata) { if (block.Header.Type == MetadataBlockHeader.MetadataBlockType.VorbisComment) { VorbisComment info = (VorbisComment)block; Assert.AreEqual("Ziggystar", info["ARTIST"].Value); Assert.AreEqual("Ziggystar", info.Artist.Value); Assert.AreEqual("Roland jx3p demo", info["TITLE"].Value); Assert.AreEqual("Roland jx3p demo", info.Title.Value); Assert.AreEqual("Wiki Commons", info["ALBUM"].Value); Assert.AreEqual("Wiki Commons", info.Album.Value); Assert.AreEqual("2005", info["DATE"].Value); Assert.AreEqual("2005", info.Date.Value); Assert.AreEqual("01", info["TRACKNUMBER"].Value); Assert.AreEqual("01", info.TrackNumber.Value); Assert.AreEqual("Electronic", info["GENRE"].Value); Assert.AreEqual("Electronic", info.Genre.Value); Assert.IsFalse(info.ContainsField("UNEXISTINGKEY")); } } } }
public void CueSheetVorbisCommentShouldBeInProperty() { var cueSheetPath = Path.Combine("Data", "cuesheet.txt"); var cueSheetData = File.ReadAllText(cueSheetPath); string origFile = Path.Combine("Data", "testfile5.flac"); string newFile = Path.Combine("Data", "testfile5_temp.flac"); FileHelper.GetNewFile(origFile, newFile); using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac"))) { var vorbisComment = new VorbisComment(); vorbisComment["CUESHEET"] = new VorbisCommentValues(cueSheetData); file.Metadata.Add(vorbisComment); file.Save(); } using (FlacFile file = new FlacFile(Path.Combine("Data", "testfile5_temp.flac"))) { var cueSheetDataFromFile = file.VorbisComment.CueSheet; Assert.AreEqual(cueSheetData, cueSheetDataFromFile.Value); } }
OggPacket RebuildCommentPacket() { var comment = new VorbisComment(); var packet = new OggPacket(); comment.HeaderOut(packet); return(packet); }
public void RemoveMethodShouldRemoveTag() { var vorbisComment = new VorbisComment(); vorbisComment["ARTIST"] = new VorbisCommentValues("Aaron"); vorbisComment.Remove("ARTIST"); Assert.IsTrue(vorbisComment.Artist.Count == 0, "Tag was not removed."); }
public void AddMethodShouldAddSingleValueTag() { var vorbisComment = new VorbisComment(); vorbisComment.Add("ARTIST", "Aaron"); Assert.AreEqual(1, vorbisComment.Artist.Count); Assert.AreEqual("Aaron", vorbisComment.Artist.Value); }
public void AddMethodShouldAddMultipleValues() { var vorbisComment = new VorbisComment(); vorbisComment.Add("ARTIST", new string[] { "Aaron", "Lenoir" }); Assert.AreEqual(2, vorbisComment.Artist.Count); Assert.AreEqual("Aaron", vorbisComment.Artist[0]); Assert.AreEqual("Lenoir", vorbisComment.Artist[1]); }
public void ReplaceMethodShouldReplaceAllValues() { var vorbisComment = new VorbisComment(); vorbisComment.Add("ARTIST", new string[] { "Aaron", "Lenoir" }); vorbisComment.Replace("ARTIST", "Test"); Assert.AreEqual(1, vorbisComment.Artist.Count); Assert.AreEqual("Test", vorbisComment.Artist[0]); }
public static void AddTagIfNotNull(VorbisComment comments, string key, params string[] values) { if (values == null || values.Any(string.IsNullOrWhiteSpace)) { return; } comments[key] = new VorbisCommentValues(values); }
public void RemoveMethodShouldRemoveTagWithSpecificValue() { var vorbisComment = new VorbisComment(); vorbisComment["ARTIST"] = new VorbisCommentValues("Aaron"); vorbisComment.Remove("ARTIST", "Lenoir"); Assert.IsTrue(vorbisComment.Artist.Count == 1, "Tag was removed when it shouldn't have been."); vorbisComment.Remove("ARTIST", "Aaron"); Assert.IsTrue(vorbisComment.Artist.Count == 0, "Tag was not removed."); }
/// <summary> /// saves vorbis ogg or flac tag information to file /// </summary> /// <param name="taglibFile"></param> public void SaveVorbisTag(VorbisComment taglibFile) { if (taglibFile != null) { //string fName = file.FileName; //AudioFileReader prev = file; if (flacReader != null) { //float curVol = file.Volume; wavePlayer.Stop(); string prevFile = this.fileName; this.flacReader.Close(); this.flacReader.Dispose(); this.flacReader = null; try { taglibFile.SaveMetadata(); } catch (UnauthorizedAccessException) { } catch (Exception) { } this.flacReader = new FlacReader(prevFile); wavePlayer.Init(this.flacReader); //SetVolume(curVol); } else if (vorbisReader != null) { wavePlayer.Stop(); string prevFile = this.fileName; this.vorbisReader.Close(); this.vorbisReader.Dispose(); this.vorbisReader = null; try { taglibFile.SaveMetadata(); } catch (UnauthorizedAccessException) { } catch (Exception) { } this.vorbisReader = new VorbisWaveReader(prevFile); wavePlayer.Init(this.vorbisReader); //SetVolume(curVol); } } }
public void AddMethodShouldAppendNewValue() { var vorbisComment = new VorbisComment(); vorbisComment.Add("ARTIST", "Aaron"); vorbisComment.Add("ARTIST", "Lenoir"); Assert.AreEqual(2, vorbisComment.Artist.Count); Assert.AreEqual("Aaron", vorbisComment.Artist.Value); Assert.AreEqual("Aaron", vorbisComment.Artist[0]); Assert.AreEqual("Lenoir", vorbisComment.Artist[1]); }
private void Parse() { while (true) { var type = Reader.ReadByte(); var last = (type & 0x80) == 0x80; if (last) { break; } var length = BitConverterExtension.ToInt24(Reader.ReadBytes(3), 0); switch ((MetadataBlockType)type) { case MetadataBlockType.STREAMINFO: { StreamInfo = StreamInfo.FromByteArray(Reader.ReadBytes(length)); break; } case MetadataBlockType.SEEKTABLE: { Reader.ReadBytes(length); break; } case MetadataBlockType.PICTURE: { var picture = Picture.FromByteArray(Reader.ReadBytes(length)); Pictures[picture.PictureType] = picture; break; } case MetadataBlockType.VORBIS_COMMENT: { VorbisComment = VorbisComment.FromByteArray(Reader.ReadBytes(length)); break; } default: { // Discard Reader.ReadBytes(length); break; } } } if (VorbisComment == null) { VorbisComment = new VorbisComment(); } Frame = Reader.ReadBytes((int)(InMemoryByteArray.Length - InMemoryByteArray.Position)); }
VorbisInfo CreateVorbisInfo(Sample sample, OggPacket setup_packet) { var info = new VorbisInfo { Channels = sample.Channels, Rate = sample.SampleRate, }; info.CodecSetup.BlockSizes[0] = 0x100; info.CodecSetup.BlockSizes[1] = 0x800; var comment = new VorbisComment { Vendor = VorbisComment.EncodeVendorString }; info.SynthesisHeaderin(comment, setup_packet); return(info); }
public void CreateVorbisComment() { string artist = "Some Artist"; string albumName = "Test Album"; string customTag = "PROJECT"; string customTagValue = "FlacLibSharp"; string customTag2 = "Author"; string customTag2Value = "Aaron"; string title = "Test Track"; string title2 = "Title modified"; string titleTag = "Title"; FileHelper.GetNewFile(origFile, newFile); using (FlacFile flac = new FlacFile(newFile)) { VorbisComment vorbisComment = new VorbisComment(); vorbisComment.Album.Value = albumName; vorbisComment.Artist.Value = artist; vorbisComment[customTag].Value = customTagValue; vorbisComment[customTag2].Value = customTag2Value; vorbisComment.Title.Value = title; vorbisComment[titleTag].Value = title2; flac.Metadata.Add(vorbisComment); flac.Save(); } using (FlacFile flac = new FlacFile(newFile)) { VorbisComment vorbisComment = flac.VorbisComment; Assert.AreEqual <string>(albumName, vorbisComment.Album.Value); Assert.AreEqual <string>(artist, vorbisComment.Artist.Value); Assert.AreEqual <string>(customTagValue, vorbisComment[customTag].Value); Assert.AreEqual <string>(customTag2Value, vorbisComment[customTag2.ToUpper()].Value); Assert.AreEqual <string>(title2, vorbisComment.Title.Value); Assert.AreEqual <string>(title2, vorbisComment[titleTag].Value); } }
public async Task SaveAsync(Stream destination) { var writeTo = new MemoryStream(); using (var writer = new BinaryWriter(writeTo)) { writer.Write(Encoding.ASCII.GetBytes("fLaC")); writer.Write((byte)MetadataBlockType.STREAMINFO); var stream = StreamInfo.ToByteArray(); writer.Write(BitConverter.GetBytes(BitConverterExtension.ConvertEndian24(stream.Length)), 0, 3); writer.Write(stream); foreach (var picture in Pictures) { stream = picture.Value.ToByteArray(); writer.Write((byte)MetadataBlockType.PICTURE); writer.Write(BitConverter.GetBytes(BitConverterExtension.ConvertEndian24(stream.Length)), 0, 3); writer.Write(stream); } stream = VorbisComment.ToByteArray(); writer.Write((byte)MetadataBlockType.VORBIS_COMMENT); writer.Write(BitConverter.GetBytes(BitConverterExtension.ConvertEndian24(stream.Length)), 0, 3); writer.Write(stream); writer.Write((byte)0x81); writer.Write(Frame); await writeTo.FlushAsync(); writeTo.Position = 0; await writeTo.CopyToAsync(destination); } }
static void Main(string[] args) { string fileName = GetFileName(args); if (fileName == null) { return; } Console.WriteLine(); Console.WriteLine(string.Format("File: {0}", fileName)); Console.WriteLine(); IAudioFile audioFile = AudioFile.Create(fileName, true); Console.WriteLine("Audio Info"); Console.WriteLine(); Console.WriteLine(string.Format("Type: {0}", EnumUtils.GetDescription(audioFile.FileType))); Console.WriteLine(string.Format("Length: {0}:{1:00}", (int)audioFile.TotalSeconds / 60, (int)audioFile.TotalSeconds % 60)); Console.WriteLine(string.Format("Bitrate: {0:#,0} kbps", (int)audioFile.Bitrate)); Console.WriteLine(string.Format("Frequency: {0:#,0} Hz", audioFile.Frequency)); Console.WriteLine(string.Format("Channels: {0}", audioFile.Channels)); Console.WriteLine(); if (ID3v2Tag.DoesTagExist(fileName)) { IID3v2Tag id3v2 = new ID3v2Tag(fileName); Console.WriteLine(EnumUtils.GetDescription(id3v2.Header.TagVersion)); Console.WriteLine(); Console.WriteLine(string.Format("Artist: {0}", id3v2.Artist)); Console.WriteLine(string.Format("Title: {0}", id3v2.Title)); Console.WriteLine(string.Format("Album: {0}", id3v2.Album)); Console.WriteLine(string.Format("Year: {0}", id3v2.Year)); Console.WriteLine(string.Format("Track: {0}", id3v2.TrackNumber)); Console.WriteLine(string.Format("Genre: {0}", id3v2.Genre)); Console.WriteLine(string.Format("Pictures: {0}", id3v2.PictureList.Count)); Console.WriteLine(string.Format("Comments: {0}", id3v2.CommentsList.Count)); Console.WriteLine(); // Example of saving an ID3v2 tag // // id3v2.Title = "New song title"; // id3v2.Save(fileName); } if (ID3v1Tag.DoesTagExist(fileName)) { IID3v1Tag id3v1 = new ID3v1Tag(fileName); Console.WriteLine(EnumUtils.GetDescription(id3v1.TagVersion)); Console.WriteLine(); Console.WriteLine(string.Format("Artist: {0}", id3v1.Artist)); Console.WriteLine(string.Format("Title: {0}", id3v1.Title)); Console.WriteLine(string.Format("Album: {0}", id3v1.Album)); Console.WriteLine(string.Format("Year: {0}", id3v1.Year)); Console.WriteLine(string.Format("Comment: {0}", id3v1.Comment)); Console.WriteLine(string.Format("Track: {0}", id3v1.TrackNumber)); Console.WriteLine(string.Format("Genre: {0}", GenreHelper.GenreByIndex[id3v1.GenreIndex])); Console.WriteLine(); // Example of saving an ID3v1 tag // // id3v1.Title = "New song title"; // id3v1.Save(fileName); } if (audioFile.FileType == AudioFileType.Flac) { VorbisComment vorbis = new VorbisComment(fileName); Console.WriteLine("Vorbis Comment"); Console.WriteLine(); Console.WriteLine(string.Format("Artist: {0}", vorbis.Artist)); Console.WriteLine(string.Format("Title: {0}", vorbis.Title)); Console.WriteLine(string.Format("Album: {0}", vorbis.Album)); Console.WriteLine(string.Format("Year: {0}", vorbis.Year)); Console.WriteLine(string.Format("Comment: {0}", vorbis.Comment)); Console.WriteLine(string.Format("Track: {0}", vorbis.TrackNumber)); Console.WriteLine(string.Format("Genre: {0}", vorbis.Genre)); Console.WriteLine(string.Format("Vendor: {0}", vorbis.Vendor)); Console.WriteLine(); // Example of saving a Vorbis Comment // // vorbis.Title = "New song title"; // vorbis.Save(fileName); } }
// just in case i find a way to get the album cover working in taglib /*private bool WriteFlacMetadata() * { * using (TagLib.File file = TagLib.File.Create(_filepath, "taglib/flac", ReadStyle.Average)) * { * var tags = (TagLib.Ogg.XiphComment) file.GetTag(TagTypes.Xiph); * * if (_trackInfo.TrackTags != null) * { * tags.Title = _trackInfo.TrackTags.Title; * tags.Performers = _trackInfo.TrackTags.Artists.Select(x => x.Name).ToArray(); * tags.Composers = _trackInfo.TrackTags.Contributors.Composers; * tags.SetField("LENGTH", _trackInfo.TrackTags.Length); * tags.SetField("ISRC", _trackInfo.TrackTags.Isrc); * tags.SetField("EXPLICIT", _trackInfo.TrackTags.ExplicitLyrics ?? "0"); * tags.SetField("REPLAYGAIN_TRACK_GAIN", _trackInfo.TrackTags.Gain); * tags.SetField("PRODUCER", _trackInfo.TrackTags.Contributors.Producers); * tags.SetField("ENGINEER", _trackInfo.TrackTags.Contributors.Engineers); * tags.SetField("MIXER", _trackInfo.TrackTags.Contributors.Mixers); * tags.SetField("WRITER", _trackInfo.TrackTags.Contributors.Writers); * tags.SetField("AUTHOR", _trackInfo.TrackTags.Contributors.Authors); * tags.SetField("PUBLISHER", _trackInfo.TrackTags.Contributors.Publishers); * * * if (_trackInfo.TrackTags.TrackNumber != null && * uint.TryParse(_trackInfo.TrackTags.TrackNumber, out uint trackNumber)) * { * tags.Track = trackNumber; * } * * if (_trackInfo.TrackTags.DiscNumber != null && * uint.TryParse(_trackInfo.TrackTags.DiscNumber, out uint discNumber)) * { * tags.Disc = discNumber; * } * * if (_trackInfo.TrackTags.Bpm != null && * uint.TryParse(_trackInfo.TrackTags.Bpm, out uint bpm)) * { * tags.BeatsPerMinute = bpm; * } * } * * if (_albumInfo.AlbumTags != null) * { * tags.Album = _albumInfo.AlbumTags.Title; * tags.AlbumArtists = _albumInfo.AlbumTags.Artists.Select(x => x.Name).ToArray(); * tags.Genres = _albumInfo.AlbumTags.Genres.GenreData.Select(x => x.Name).ToArray(); * * string year = _albumInfo.AlbumTags.ReleaseDate; * * if (!string.IsNullOrWhiteSpace(year)) * { * string[] yearSplit = year.Split("-"); * * if (yearSplit[0].Length == 4 && uint.TryParse(yearSplit[0], out uint yearParsed)) * { * tags.Year = yearParsed; * } * } * * tags.Copyright = _albumInfo.AlbumTags.Copyright; * tags.SetField("MEDIA", "Digital Media"); * tags.SetField("ORIGINALDATE", _albumInfo.AlbumTags.ReleaseDate); * tags.SetField("UPC", _albumInfo.AlbumTags.Upc); * tags.SetField("LABEL", _albumInfo.AlbumTags.Label); * * if (_albumInfo.AlbumTags.NumberOfTracks != null && * uint.TryParse(_albumInfo.AlbumTags.NumberOfTracks, out uint numberOfTracks)) * { * tags.TrackCount = numberOfTracks; * } * * if (_albumInfo.AlbumTags.NumberOfDiscs != null && * uint.TryParse(_albumInfo.AlbumTags.NumberOfDiscs, out uint numberOfDiscs)) * { * tags.DiscCount = numberOfDiscs; * } * } * * if (_trackInfo.Lyrics != null) * { * tags.Lyrics = _trackInfo.Lyrics.UnSyncedLyrics; * WriteLyricsFile(); * } * * try * { * file.Save(); * } * catch (IOException ex) * { * Console.WriteLine(ex.Message); * return false; * } * } * * // this takes 800-900ms... why can't you just work taglib * using (var file = new FlacFile(_filepath)) * { * if (_coverBytes.Length > 0) * { * var coverArt = new FlacLibSharp.Picture() * { * Description = "Cover", * ColorDepth = 8, * Data = _coverBytes, * Height = 1400, * Width = 1400, * MIMEType = MediaTypeNames.Image.Jpeg, * PictureType = FlacLibSharp.PictureType.CoverFront * }; * * file.Metadata.Add(coverArt); * } * * try * { * file.Save(); * } * catch (Exception ex) * { * Console.WriteLine(ex.Message); * return false; * } * } * * return true; * }*/ private bool WriteFlacMetadata() { using (var file = new FlacFile(_filepath)) { var comments = new VorbisComment(); if (_coverBytes.Length > 0) { var coverArt = new FlacLibSharp.Picture { Description = "Cover", ColorDepth = 8, Data = _coverBytes, Height = 1400, Width = 1400, MIMEType = MediaTypeNames.Image.Jpeg, PictureType = FlacLibSharp.PictureType.CoverFront }; file.Metadata.Add(coverArt); } comments["Media"] = new VorbisCommentValues("Digital Media"); if (_albumInfo?.AlbumTags != null) { comments.Album = new VorbisCommentValues(_albumInfo.AlbumTags.Title ?? ""); if (_albumInfo.AlbumTags?.Genres?.GenreData != null) { comments.Genre = new VorbisCommentValues(_albumInfo.AlbumTags.Genres.GenreData.Select(x => x.Name)); } string year = _albumInfo.AlbumTags.ReleaseDate ?? ""; if (!string.IsNullOrWhiteSpace(year)) { var yearSplit = year.Split("-"); if (yearSplit[0].Length == 4) { year = yearSplit[0]; } } if (_albumInfo.AlbumTags.Type == "Compilation" || _albumInfo.AlbumTags.Type == "Playlist") { comments["COMPILATION"] = new VorbisCommentValues("1"); } comments.Date = new VorbisCommentValues(year ?? ""); comments["ORIGINALDATE"] = new VorbisCommentValues(_albumInfo.AlbumTags.ReleaseDate ?? ""); comments["TRACKTOTAL"] = new VorbisCommentValues(_albumInfo.AlbumTags.NumberOfTracks ?? ""); comments["DISCTOTAL"] = new VorbisCommentValues(_albumInfo.AlbumTags.NumberOfDiscs ?? ""); comments["COPYRIGHT"] = new VorbisCommentValues(_albumInfo.AlbumTags.Copyright ?? ""); comments["UPC"] = new VorbisCommentValues(_albumInfo.AlbumTags.Upc ?? ""); comments["LABEL"] = new VorbisCommentValues(_albumInfo.AlbumTags.Label ?? ""); comments["ALBUMARTIST"] = new VorbisCommentValues(_albumInfo.AlbumTags.Artists.Select(x => x.Name)); } if (_trackInfo?.TrackTags != null) { comments.Title = new VorbisCommentValues(_trackInfo.TrackTags.Title ?? ""); comments.Artist = new VorbisCommentValues(_trackInfo.TrackTags.Artists.Select(x => x.Name)); comments["DISCNUMBER"] = new VorbisCommentValues(_trackInfo.TrackTags.DiscNumber ?? ""); comments["TRACKNUMBER"] = new VorbisCommentValues(_trackInfo.TrackTags.TrackNumber ?? ""); comments["BPM"] = new VorbisCommentValues(_trackInfo.TrackTags.Bpm ?? ""); comments["LENGTH"] = new VorbisCommentValues(_trackInfo.TrackTags.Length ?? ""); comments["ISRC"] = new VorbisCommentValues(_trackInfo.TrackTags.Isrc ?? ""); comments["EXPLICIT"] = new VorbisCommentValues(_trackInfo.TrackTags.ExplicitLyrics ?? "0"); comments["REPLAYGAIN_TRACK_GAIN"] = new VorbisCommentValues(_trackInfo.TrackTags.Gain ?? ""); MetadataHelpers.AddTagIfNotNull(comments, "COMPOSER", _trackInfo.TrackTags.Contributors.Composers); MetadataHelpers.AddTagIfNotNull(comments, "PUBLISHER", _trackInfo.TrackTags.Contributors.Publishers); MetadataHelpers.AddTagIfNotNull(comments, "PRODUCER", _trackInfo.TrackTags.Contributors.Producers); MetadataHelpers.AddTagIfNotNull(comments, "ENGINEER", _trackInfo.TrackTags.Contributors.Engineers); MetadataHelpers.AddTagIfNotNull(comments, "WRITER", _trackInfo.TrackTags.Contributors.Writers); MetadataHelpers.AddTagIfNotNull(comments, "MIXER", _trackInfo.TrackTags.Contributors.Mixers); MetadataHelpers.AddTagIfNotNull(comments, "AUTHOR", _trackInfo.TrackTags.Contributors.Authors); } if (_trackInfo?.Lyrics != null) { comments["Lyrics"] = new VorbisCommentValues(_trackInfo.Lyrics.UnSyncedLyrics ?? ""); WriteLyricsFile(); } file.Metadata.Add(comments); try { file.Save(); } catch (Exception ex) { Console.WriteLine(ex.Message); return(false); } } return(true); }
/// <summary> /// Tries to parse all the metadata blocks available in the file. /// </summary> protected void ReadMetadata() { bool foundStreamInfo = false; MetadataBlock lastMetaDataBlock = null; do { lastMetaDataBlock = MetadataBlock.Create(this.dataStream); this.Metadata.Add(lastMetaDataBlock); switch(lastMetaDataBlock.Header.Type) { case MetadataBlockHeader.MetadataBlockType.StreamInfo: foundStreamInfo = true; this.streamInfo = (StreamInfo)lastMetaDataBlock; break; case MetadataBlockHeader.MetadataBlockType.Application: this.applicationInfo = (ApplicationInfo)lastMetaDataBlock; break; case MetadataBlockHeader.MetadataBlockType.CueSheet: this.cueSheet = (CueSheet)lastMetaDataBlock; break; case MetadataBlockHeader.MetadataBlockType.Seektable: this.seekTable = (SeekTable)lastMetaDataBlock; break; case MetadataBlockHeader.MetadataBlockType.VorbisComment: this.vorbisComment = (VorbisComment)lastMetaDataBlock; break; case MetadataBlockHeader.MetadataBlockType.Padding: this.padding = (Padding)lastMetaDataBlock; break; } } while (!lastMetaDataBlock.Header.IsLastMetaDataBlock); if (!foundStreamInfo) throw new Exceptions.FlacLibSharpStreamInfoMissing(); // Remember where the frame data starts frameStart = this.dataStream.Position; }
/// <summary> /// loads information from Vorbis tag /// </summary> private void LoadVorbisInformation() { try { if (fileName.EndsWith(".flac")) { vbTagger = new FlacTagger(fileName); } if (fileName.EndsWith(".ogg")) { vbTagger = new OggTagger(fileName); } } catch (Exception) { Debug.WriteLine("UNSUPPORTED FILE: " + fileName); } txtTitle.Text = (vbTagger.Title == null) ? "" : vbTagger.Title; txtArtist.Text = (vbTagger.Artist == null) ? "" : vbTagger.Artist; string strGenre = (vbTagger.Genre == null) ? "" : vbTagger.Genre; Dictionary <string, string> genres = new Dictionary <string, string>(); genres.Add("0", ""); int cnt = 1; foreach (string gInfo in Genres.GetGenres()) { genres.Add(cnt.ToString(), gInfo); ++cnt; } cbGenre.DisplayMember = "Value"; cbGenre.ValueMember = "Key"; cbGenre.BindingContext = new BindingContext(); cbGenre.DataSource = new BindingSource(genres, null); if (genres.ContainsValue(strGenre)) { cbGenre.SelectedItem = genres.FirstOrDefault(x => x.Value == strGenre); } txtAlbum.Text = (vbTagger.Album == null) ? "" : vbTagger.Album; if (vbTagger.Date != null) { nudYear.Text = vbTagger.Date; } if (vbTagger.TrackNumber != null) { nudTrackNum.Text = vbTagger.TrackNumber; } if (vbTagger.Arts != null) { // display the embedded picture if exists var pictures = vbTagger.Arts; if (pictures.Count > 0) { TagLib.Picture fstPic = new TagLib.Picture(pictures[0].PictureData); try { tempImageFileName = Path.Combine(Path.GetTempPath(), Path.GetTempFileName() + ".jpg"); using (FileStream fileStream = new FileStream(tempImageFileName, FileMode.OpenOrCreate, FileAccess.ReadWrite)) { using (BinaryWriter writer = new BinaryWriter(fileStream)) { writer.Write(pictures[0].PictureData.ToArray()); } } pictBox.LoadAsync(tempImageFileName); } catch (Exception) { Debug.WriteLine(string.Format("Cannot save temp image file: {0}", tempImageFileName)); } } //else //{ //pictBox.Image = GoStreamAudioGUI.Properties.Resources.noPic; //} } }
public void RemoveMethodShouldNotThrowErrorIfTagNotFound() { var vorbisComment = new VorbisComment(); vorbisComment.Remove("BLABLABLA"); }
public void CreateVorbisComment() { string artist = "Some Artist"; string albumName = "Test Album"; string customTag = "PROJECT"; string customTagValue = "FlacLibSharp"; string customTag2 = "Author"; string customTag2Value = "Aaron"; string title = "Test Track"; string title2 = "Title modified"; string titleTag = "Title"; FileHelper.GetNewFile(origFile, newFile); using (FlacFile flac = new FlacFile(newFile)) { VorbisComment vorbisComment = new VorbisComment(); vorbisComment.Album.Value = albumName; vorbisComment.Artist.Value = artist; vorbisComment[customTag].Value = customTagValue; vorbisComment[customTag2].Value = customTag2Value; vorbisComment.Title.Value = title; vorbisComment[titleTag].Value = title2; flac.Metadata.Add(vorbisComment); flac.Save(); } using (FlacFile flac = new FlacFile(newFile)) { VorbisComment vorbisComment = flac.VorbisComment; Assert.AreEqual<string>(albumName, vorbisComment.Album.Value); Assert.AreEqual<string>(artist, vorbisComment.Artist.Value); Assert.AreEqual<string>(customTagValue, vorbisComment[customTag].Value); Assert.AreEqual<string>(customTag2Value, vorbisComment[customTag2.ToUpper()].Value); Assert.AreEqual<string>(title2, vorbisComment.Title.Value); Assert.AreEqual<string>(title2, vorbisComment[titleTag].Value); } }