Example #1
0
 public TaggedFile(string fileName)
 {
     this.FileName = fileName;
     char[] delim = new char[] { ';' };
     using (FlacLibSharp.FlacFile file = new FlacLibSharp.FlacFile(fileName))
     {
         var vorbisComment = file.VorbisComment;
         if (vorbisComment != null)
         {
             foreach (var tag in vorbisComment)
             {
                 List <string> values = new List <string>();
                 foreach (var value in tag.Value)
                 {
                     //Console.WriteLine("{0}: {1}", tag.Key, tag.Value);
                     foreach (string part in value.Split(delim))
                     {
                         values.Add(part.Trim());
                     }
                 }
                 Tags.Add(tag.Key.ToLower(), new Tag(tag.Key.ToLower(), values));
             }
         }
     }
 }
Example #2
0
        public void Save()
        {
            using (FlacLibSharp.FlacFile flac = new FlacLibSharp.FlacFile(FileName))
            {
                // First get the existing VorbisComment (if any)
                var comment = flac.VorbisComment;
                if (comment == null)
                {
                    // Create a new vorbis comment metadata block
                    comment = new FlacLibSharp.VorbisComment();
                    // Add it to the flac file
                    flac.Metadata.Add(comment);
                }

                //Remove the ones to be removed
                foreach (var remTag in DeletedTags.Keys)
                {
                    if (comment.ContainsField(remTag))
                    {
                        comment.Remove(remTag);
                    }
                }

                //Update the ones to be updated
                foreach (var updTag in ChangedTags.Keys)
                {
                    if (comment.ContainsField(updTag))
                    {
                        comment.Remove(updTag);
                    }
                    var values = Tags[updTag].GetSaveValues;
                    comment.Add(updTag, values);
                }

                //Add ones to be added
                foreach (var addTag in AddedTags.Keys)
                {
                    if (comment.ContainsField(addTag))
                    {
                        //This shouldn't ever happen, but just in case.
                        comment.Remove(addTag);
                    }
                    comment.Add(addTag, Tags[addTag].GetSaveValues);
                }

                // Write the changes back to the FLAC file
                flac.Save();
            }
        }
Example #3
0
        public IActionResult Test(int n)
        {
            var folder = $@"D:\Music\flac\Western\Classical\Johannes Brahms\Complete Works\CD{n.ToString("00")}";
            var l1     = new List <string>();
            var sw1    = new Stopwatch();

            sw1.Start();
            foreach (var file in System.IO.Directory.EnumerateFiles(folder, "*.flac"))
            {
                //Debug.WriteLine($"{file}");

                using (var flacFile = new FlacLibSharp.FlacFile(file))
                {
                    var vorbisComment = flacFile.VorbisComment;
                    if (vorbisComment != null)
                    {
                        foreach (var tag in vorbisComment)
                        {
                            var values = string.Join("|", tag.Value.Select(x => x.Trim()).ToArray());
                            l1.Add(tag.Key);
                        }
                    }
                }
            }
            sw1.Stop();
            Debug.WriteLine($"{l1.Count()} read in {sw1.ElapsedMilliseconds} ms");
            var l2  = new List <string>();
            var sw2 = new Stopwatch();

            sw2.Start();
            foreach (var file in System.IO.Directory.EnumerateFiles(folder, "*.flac"))
            {
                //Debug.WriteLine($"{file}");

                var t             = new Music.MediaTools.FlacTools(file);
                var vorbisComment = t.GetVorbisCommenTs();
                if (vorbisComment != null)
                {
                    foreach (var kvp in vorbisComment.comments)
                    {
                        l2.Add(kvp.Key);
                    }
                }
            }
            sw2.Stop();
            Debug.WriteLine($"{l2.Count()} read in {sw2.ElapsedMilliseconds} ms");
            return(new EmptyResult());
        }