예제 #1
0
        private static void SaveIsCompilation(TagLib.File file, bool is_compilation)
        {
            try {
                var xiph_tag = file.GetTag(TagLib.TagTypes.Xiph, true) as TagLib.Ogg.XiphComment;
                if (xiph_tag != null)
                {
                    xiph_tag.IsCompilation = is_compilation;
                    return;
                }
            } catch {}

            try {
                TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true) as TagLib.Id3v2.Tag;
                if (id3v2_tag != null)
                {
                    id3v2_tag.IsCompilation = is_compilation;
                    return;
                }
            } catch {}

            try {
                TagLib.Mpeg4.AppleTag apple_tag = file.GetTag(TagLib.TagTypes.Apple, true) as TagLib.Mpeg4.AppleTag;
                if (apple_tag != null)
                {
                    apple_tag.IsCompilation = is_compilation;
                    return;
                }
            } catch {}
        }
예제 #2
0
        private static bool IsCompilation(TagLib.File file)
        {
            try {
                TagLib.Id3v2.Tag id3v2_tag = file.GetTag(TagLib.TagTypes.Id3v2, true) as TagLib.Id3v2.Tag;
                if (id3v2_tag != null && id3v2_tag.IsCompilation)
                {
                    return(true);
                }
            } catch {}

            try {
                TagLib.Mpeg4.AppleTag apple_tag = file.GetTag(TagLib.TagTypes.Apple, true) as TagLib.Mpeg4.AppleTag;
                if (apple_tag != null && apple_tag.IsCompilation)
                {
                    return(true);
                }
            } catch {}

            // FIXME the FirstAlbumArtist != FirstPerformer check might return true for half the
            // tracks on a compilation album, but false for some
            // TODO checked for 'Soundtrack' (and translated) in the title?
            if (file.Tag.Performers.Length > 0 && file.Tag.AlbumArtists.Length > 0 &&
                (file.Tag.Performers.Length != file.Tag.AlbumArtists.Length ||
                 file.Tag.FirstAlbumArtist != file.Tag.FirstPerformer))
            {
                return(true);
            }
            return(false);
        }
예제 #3
0
        public static void ParseMetadata(
            DirectoryInfo inputDirectory,
            DirectoryInfo jsonOutputDirectory,
            string sqliteFilepath,
            bool exportSqlite,
            bool exportJson,
            bool shouldOverwrite)
        {
            var files      = inputDirectory.EnumerateFiles();
            var validFiles = files.Where(n => SupportedExtensions.Contains(n.Extension));
            var fileTagMap = new Dictionary <string, IDictionary <string, IEnumerable <string> > >();

            foreach (var file in validFiles)
            {
                var         path    = file.FullName;
                TagLib.File tagFile = null;
                try
                {
                    tagFile = TagLib.File.Create(path);
                }
                catch (Exception)
                {
                    // TODO: Add Logging
                    continue;
                }

                if (tagFile.GetTag(TagLib.TagTypes.Xiph) is TagLib.Ogg.XiphComment xiph)
                {
                    IDictionary <string, IEnumerable <string> > tagMap = xiph.ToDictionary(
                        fieldName => fieldName,
                        fieldName => xiph.GetField(fieldName).AsEnumerable());

                    fileTagMap.Add(file.Name, tagMap);
                    continue;
                }

                if (tagFile.GetTag(TagLib.TagTypes.Id3v2) is TagLib.Id3v2.Tag id3File)
                {
                    IDictionary <string, IEnumerable <string> > tagMap = GetID3v2TagMap(id3File);
                    fileTagMap.Add(file.Name, tagMap);
                    continue;
                }
            }

            if (fileTagMap.Any())
            {
                if (exportSqlite)
                {
                    ExportSqlite(fileTagMap, sqliteFilepath);
                }

                if (exportJson)
                {
                    ExportJson(fileTagMap, jsonOutputDirectory, shouldOverwrite);
                }
            }
        }
예제 #4
0
 public static bool UpdateTags(TagLib.File fileInfo, NameValueCollection tags, CUEToolsCodecsConfig config, bool useId3v24)
 {
     if (fileInfo is TagLib.Riff.File)
     {
         return(false);
     }
     TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)fileInfo.GetTag(TagLib.TagTypes.Xiph);
     if (xiph != null)
     {
         foreach (string tag in tags.AllKeys)
         {
             xiph.SetField(tag, tags.GetValues(tag));
         }
         return(true);
     }
     if (fileInfo is TagLib.Mpeg4.File)
     {
         var mpeg4 = (TagLib.Mpeg4.AppleTag)fileInfo.GetTag(TagLib.TagTypes.Apple, true);
         foreach (string tag in tags.AllKeys)
         {
             mpeg4.SetDashBox("com.apple.iTunes", tag, string.Join(";", tags.GetValues(tag)));
         }
         return(true);
     }
     if (fileInfo is TagLib.Mpeg.AudioFile || (fileInfo is TagLib.UserDefined.File &&
                                               (fileInfo as TagLib.UserDefined.File).Tagger == CUEToolsTagger.ID3v2))
     {
         var id3v2 = (TagLib.Id3v2.Tag)fileInfo.GetTag(TagLib.TagTypes.Id3v2, true);
         id3v2.Version = (byte)(useId3v24 ? 4 : 3);
         foreach (string tag in tags.AllKeys)
         {
             var frame = TagLib.Id3v2.UserTextInformationFrame.Get(id3v2, tag, true);
             frame.Text = tags.GetValues(tag);
         }
         return(true);
     }
     if (fileInfo is TagLib.Asf.File)
     {
         var asf = (TagLib.Asf.Tag)fileInfo.GetTag(TagLib.TagTypes.Asf, true);
         foreach (string tag in tags.AllKeys)
         {
             asf.SetDescriptorStrings(tags.GetValues(tag), "foobar2000/" + tag);
         }
         return(true);
     }
     TagLib.Ape.Tag ape = (TagLib.Ape.Tag)fileInfo.GetTag(TagLib.TagTypes.Ape, true);
     if (ape != null)
     {
         foreach (string tag in tags.AllKeys)
         {
             ape.SetValue(tag, tags.GetValues(tag));
         }
     }
     return(true);
 }
예제 #5
0
 /// <summary>
 /// move to previous tag & retreat index
 /// </summary>
 public void Previous()
 {
     if (lv.SelectedItems.Count > Index && Index > 0)
     {
         FileInfo fi = (FileInfo)lv.SelectedItems[--idx].Tag;
         //  lblFile.Text = fi.FullName;
         tag_file = TagLib.File.Create(fi.FullName);
         v2       = (TagLib.Id3v2.Tag)tag_file.GetTag(TagLib.TagTypes.Id3v2);
         v1       = (TagLib.Id3v1.Tag)tag_file.GetTag(TagLib.TagTypes.Id3v1);
         Fill();
     }
 }
예제 #6
0
 private static TagLib.Tag GetSongTag(string songFile, TagLib.File track)
 {
     TagLib.Tag tag;
     if (System.IO.Path.GetExtension(songFile.ToUpper()) == ".FLAC")
     {
         tag = track.GetTag(TagLib.TagTypes.FlacMetadata);
     }
     else
     {
         tag = track.GetTag(TagLib.TagTypes.Id3v2);
     }
     return(tag);
 }
예제 #7
0
        protected override void Metadata()
        {
            ResetOutBuffer();
            using TagLib.File file = TagLib.File.Create(new MemoryFileAbstraction($"buffer.{MediaType.MimeToExt(MusicMime)}", OutBuffer));
            TagLib.Tag tag = MusicMime switch
            {
                "audio/flac" => file.Tag,
                "audio/mpeg" => file.GetTag(TagLib.TagTypes.Id3v2),
                "audio/ogg" => file.Tag,
                _ => throw new FileLoadException($"Failed to get file type while processing \"{InPath}\"."),
            };

            if (tag.Pictures.Length > 0)
            {
                tag.Pictures[0].Type = TagLib.PictureType.FrontCover;
            }

            if (ForceRename)
            {
                if (tag.Title != null && tag.AlbumArtists.Length > 0)
                {
                    OutName = $"{tag.AlbumArtists[0]} - {tag.Title}";
                }
                else if (tag.Title != null && tag.Performers.Length > 0)
                {
                    OutName = $"{tag.Performers[0]} - {tag.Title}";
                }
                else
                {
                    Logger.Error("Failed to find name for {Path}", InPath);
                }
            }

            file.Save();
        }
예제 #8
0
        /// <summary>
        ///
        /// </summary>
        public override void ThreadFunc()
        {
            foreach (FileInfo fi in infos)
            {
                OnStatusUpdate(fi.Name);

                TagLib.File             tag_file = TagLib.File.Create(fi.FullName);
                TagLib.Tag              id3v2    = tag_file.GetTag(TagLib.TagTypes.Id3v2);
                OrganizeFormatEvaluator eval     = new OrganizeFormatEvaluator(format, id3v2);

                // HACK LOOK AT THIS!!!
                string fn    = eval.Value.TrimStart('\\');
                char[] chars = System.IO.Path.GetInvalidFileNameChars();
                foreach (char c in chars)
                {
                    fn = fn.Replace(c, '_');
                }

                string fullname = String.Format("{0}\\{1}{2}",
                                                fi.DirectoryName, fn, fi.Extension);

                fi.MoveTo(fullname);
                //Tools.Functions.MoveTo( fi, dir.TrimEnd( '\\' ), false );
            }

            OnStatusUpdate("Finished");
            OnFinished();
            // HACK!!
            System.Threading.Thread.Sleep(0);
            //SafeClose();
        }
예제 #9
0
        public override void ThreadFunc()
        {
            foreach (FileInfo fi in infos)
            {
                OnStatusUpdate(fi.FullName);

                TagLib.File             tag_file = TagLib.File.Create(fi.FullName);
                TagLib.Tag              id3v1    = tag_file.GetTag(TagLib.TagTypes.Id3v1);
                OrganizeFormatEvaluator eval     = new OrganizeFormatEvaluator(format, id3v1);
                string dir = String.Format("{0}\\{1}",
                                           path.TrimEnd('\\'), eval.Value.TrimStart('\\'));
                if (!Directory.Exists(dir))
                {
                    //TODO MessageBox()
                    Directory.CreateDirectory(dir);
                }
                if (copy)
                {
                    fi.CopyTo(dir + "\\" + fi.Name, overwrite);
                }
                else
                {
                    Tools.Functions.MoveTo(fi, dir + "\\" + fi.Name, overwrite);
                }
            }

            // hold open for at least ...
            System.Threading.Thread.Sleep(1000);
            //SafeClose();
            OnFinished();
        }
예제 #10
0
        /// <summary>
        /// merge like values, hide unlike values
        /// </summary>
        public override void Coalesce()
        {
            FileInfo fi = (FileInfo)lv.SelectedItems[0].Tag;

            TagLib.File      tag_file  = TagLib.File.Create(fi.FullName);
            TagLib.Id3v1.Tag first_tag = tag_file.GetTag(TagLib.TagTypes.Id3v1) as TagLib.Id3v1.Tag;

            foreach (ListViewItem item in lv.SelectedItems)
            {
                fi       = (FileInfo)item.Tag;
                tag_file = TagLib.File.Create(fi.FullName);
                TagLib.Tag tag = tag_file.GetTag(TagLib.TagTypes.Id3v1);

                if (tag != null)
                {
                    if (first_tag.Album != tag.Album)
                    {
                        first_tag.Album = string.Empty;
                    }
                    if (first_tag.JoinedPerformers != tag.JoinedPerformers)
                    {
                        first_tag.Performers = new string[0];
                    }
                    if (first_tag.Title != tag.Title)
                    {
                        first_tag.Title = string.Empty;
                    }
                    if (first_tag.Track != tag.Track)
                    {
                        first_tag.Track = 0;
                    }
                    if (first_tag.Year != tag.Year)
                    {
                        first_tag.Year = 0;
                    }
                    if (first_tag.JoinedGenres != tag.JoinedGenres)
                    {
                        first_tag.Genres = new string[0];
                    }
                    if (first_tag.Comment != tag.Comment)
                    {
                        first_tag.Comment = string.Empty;
                    }
                }
            }
            v1 = first_tag;
        }
예제 #11
0
        public int GetRating(string path)
        {
            TagLib.File fi  = TagLib.File.Create(path);
            TagLib.Tag  tag = fi.GetTag(TagLib.TagTypes.Id3v2);

            TagLib.Id3v2.PopularimeterFrame popM = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, Defaults.PopMUser, true);

            return(PopM2StarRating(popM.Rating));
        }
        // Messy - refactor
        private bool IsCover(TagLib.File file)
        {
            var isCover        = false;
            var originalArtist = "";
            var tagType        = file.TagTypes.ToString();

            if (tagType.Contains("Id3v2"))
            {
                var id3v2Tag = file.GetTag(TagLib.TagTypes.Id3v2);
                var frame    = TagLib.Id3v2.TextInformationFrame.Get((TagLib.Id3v2.Tag)id3v2Tag, "TOPE", true);
                originalArtist = frame.ToString() ?? "";
            }
            else if (tagType.Contains("FlacMetadata"))
            {
                originalArtist = ((TagLib.Flac.Metadata)file.GetTag(TagLib.TagTypes.FlacMetadata)).Comment;
            }
            else if (tagType.Contains("Apple"))
            {
                originalArtist = ((TagLib.Mpeg4.AppleTag)file.GetTag(TagLib.TagTypes.Apple)).Comment;
            }
            else if (tagType.Contains("Ape"))
            {
                originalArtist = ((TagLib.Ape.Tag)file.GetTag(TagLib.TagTypes.Ape)).Comment;
            }
            else if (tagType.Contains("Xiph"))
            {
                originalArtist = ((TagLib.Ogg.XiphComment)file.GetTag(TagLib.TagTypes.Xiph)).Comment;
            }
            else
            {
                var log = new LogWriter($"MasterFile.IsCover() - Could not find TagLib 'cover/original' artist metadata for " +
                                        $"'{this.Filepath}'. TagType: {file.TagTypes}.");
                return(isCover);
            }
            if (TagLibProps.TryGetValue("Artist", out object value))
            {
                if (!String.IsNullOrEmpty(originalArtist) && originalArtist != value.ToString())
                {
                    isCover = true;
                }
            }
            return(isCover);
        }
예제 #13
0
        public void SetId3Tag(string fileName, string key, string value)
        {
            this.mp3Reader?.Close();

            TagLib.File file = TagLib.File.Create(fileName);
            var         tag  = (Tag)file.GetTag(TagLib.TagTypes.Id3v2);

            tag.SetTextFrame(key, value);
            file.Save();
        }
예제 #14
0
        public static void UpdateInfo(string filePath, BeatInfo info)
        {
            TagLib.File      mp3File = TagLib.File.Create(filePath + ".mp3");
            TagLib.Id3v2.Tag tag     = (TagLib.Id3v2.Tag)mp3File.GetTag(TagLib.TagTypes.Id3v2);


            tag.Title      = info.Title;
            tag.Performers = new string[] { info.Artist };
            tag.Comment    = "Beat Downloader - redphx\nhttp://beat.redphx.com\nhttp://www.karaholics.com";

            mp3File.Save();
        }
예제 #15
0
        /// <summary>
        ///
        /// </summary>
        public override void Coalesce()
        {
            //TODO
            FileInfo fi = (FileInfo)lv.SelectedItems[0].Tag;

            TagLib.File tag_file = TagLib.File.Create(fi.FullName);
            TagLib.Tag  last_tag = tag_file.GetTag(TagLib.TagTypes.Id3v1);
            foreach (ListViewItem item in lv.SelectedItems)
            {
                fi       = (FileInfo)item.Tag;
                tag_file = TagLib.File.Create(fi.FullName);
                TagLib.Tag tag = tag_file.GetTag(TagLib.TagTypes.Id3v1);
                last_tag.Album = last_tag.Album != "" && tag.Album == last_tag.Album ? tag.Album : "";
                //last_tag.Artists = last_tag.Artists != "" && tag.Artists == last_tag.Artists ? tag.Artists : "";
                last_tag.Title = last_tag.Title != "" && tag.Title == last_tag.Title ? tag.Title : "";
                last_tag.Track = last_tag.Track != 0 && tag.Track == last_tag.Track ? tag.Track : 0;
                last_tag.Year  = last_tag.Year != 0 && tag.Year == last_tag.Year ? tag.Year : 0;
            }
            //todo
            //this.editCtrl.Fill( last_tag );
        }
예제 #16
0
        private void GetTags()
        {
            using (TagLib.File file = TagLib.File.Create(MediaFile.FullName))
            {
                DateTime id3v1Start = DateTime.Now;

                try
                {
                    TagLib.Id3v1.Tag v1Tag = (TagLib.Id3v1.Tag)file.GetTag(TagLib.TagTypes.Id3v1);
                    ID3V1Tag = new TagLib.Id3v1.Tag();
                    v1Tag.CopyTo(ID3V1Tag, true);
                }
                catch
                {
                    ID3V1Tag = null;
                }

                DateTime id3v1End = DateTime.Now;

                if (Globals.VerboseLogging)
                {
                    Logger.Info($"'{MediaFile.FullName}' ID3V1 tag loaded in {(id3v1End - id3v1Start).TotalMilliseconds} milliseconds.");
                }

                DateTime id3v2Start = DateTime.Now;

                TagLib.Id3v2.Tag v2Tag = (TagLib.Id3v2.Tag)file.GetTag(TagLib.TagTypes.Id3v2);
                ID3V2Tag = new TagLib.Id3v2.Tag();
                v2Tag.CopyTo(ID3V2Tag, true);

                DateTime id3v2End = DateTime.Now;

                if (Globals.VerboseLogging)
                {
                    Logger.Info($"'{MediaFile.FullName}' ID3V2 tag loaded in {(id3v2End - id3v2Start).TotalMilliseconds} milliseconds.");
                }
            }

            ExecuteTagEdits();
        }
예제 #17
0
        public static string[] GetMiscTag(TagLib.File file, string name)
        {
            //TagLib.Mpeg4.AppleTag apple = (TagLib.Mpeg4.AppleTag)file.GetTag(TagLib.TagTypes.Apple);
            //TagLib.Id3v2.Tag id3v2 = (TagLib.Id3v2.Tag)file.GetTag(TagLib.TagTypes.Id3v2);
            TagLib.Ogg.XiphComment xiph = (TagLib.Ogg.XiphComment)file.GetTag(TagLib.TagTypes.Xiph);
            TagLib.Ape.Tag         ape  = (TagLib.Ape.Tag)file.GetTag(TagLib.TagTypes.Ape);

            //if (apple != null)
            //{
            //    string[] text = apple.GetText(name);
            //    if (text.Length != 0)
            //        return text;
            //}

            //if (id3v2 != null)
            //    foreach (TagLib.Id3v2.Frame f in id3v2.GetFrames())
            //        if (f is TagLib.Id3v2.TextInformationFrame && ((TagLib.Id3v2.TextInformationFrame)f).Text != null)
            //            return ((TagLib.Id3v2.TextInformationFrame)f).Text;

            if (xiph != null)
            {
                string[] l = xiph.GetField(name);
                if (l != null && l.Length != 0)
                {
                    return(l);
                }
            }

            if (ape != null)
            {
                TagLib.Ape.Item item = ape.GetItem(name);
                if (item != null)
                {
                    return(item.ToStringArray());
                }
            }

            return(null);
        }
예제 #18
0
        private void UpdateMp3()
        {
            TagLib.File      mp3File = TagLib.File.Create(fullPath + ".mp3");
            TagLib.Id3v2.Tag tag     = (TagLib.Id3v2.Tag)mp3File.GetTag(TagLib.TagTypes.Id3v2);


            tag.Title      = beatTitle;
            tag.Performers = new string[] { beatSinger };
            //tag.Album = "SanNhac.com";
            tag.Comment = "Beat Downloader - redphx\nhttp://www.karaholics.com";

            mp3File.Save();
        }
 private byte GetRating(TagLib.File file)
 {
     try
     {
         var tag   = file.GetTag(TagLib.TagTypes.Id3v2);
         var frame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, "WindowsUser", true);
         return(frame.Rating);
     }
     catch (Exception)
     {
         return(0);
     }
 }
예제 #20
0
        public void Init(string path)
        {
            this.path = path;
            this.mp3  = TagLib.File.Create(path);

            textBox1.Text        = mp3.Name;
            textBox2.Text        = mp3.Tag.Title;
            textBox3.Text        = mp3.Tag.JoinedArtists;
            textBox4.Text        = mp3.Tag.Album;
            numericUpDown1.Value = mp3.Tag.Track;
            numericUpDown2.Value = mp3.Tag.Year;
            richTextBox1.Text    = mp3.Tag.Lyrics;
            TagLib.Tag tag = mp3.GetTag(TagLib.TagTypes.AllTags);
        }
        private bool readMetadataTaglibM4a()
        {
            var afi = _aaxFileItem;

            TagLib.File file = null;
            try {
                file = TagLib.File.Create(afi.FileName, "taglib/m4a", TagLib.ReadStyle.Average);
            } catch (Exception) {
                return(readMetadataTaglibAudible());
            }

            using (file) {
                var tags = file.Tag;

                afi.BookTitle = tags.Title.Decode();
                afi.Authors   = tags.AlbumArtists.Decode();
                var pic = tags.Pictures.FirstOrDefault();
                if (pic != null)
                {
                    afi.Cover = pic.Data?.Data;
                    if (afi.Cover != null && afi.Cover.Length > AaPictureExtractor.PNG_HDR.Count)
                    {
                        if (pic.Filename != null)
                        {
                            afi.CoverExt = Path.GetExtension(pic.Filename).ToLower();
                        }
                        else
                        {
                            imageTypeFromData();
                        }
                    }
                }
                try {
                    afi.PublishingDate = new DateTime((int)tags.Year, 1, 1);
                } catch (Exception) { }
                afi.Copyright = tags.Copyright.Decode();
                afi.Genre     = tags.Genres.FirstOrDefault()?.Decode();

                var atags = file.GetTag(TagLib.TagTypes.Apple) as TagLib.Mpeg4.AppleTag;
                if (atags is null)
                {
                    return(true);
                }
                afi.Narrators = appleCustomTag(atags, NRT).Decode().SplitTrim();
                afi.Abstract  = appleCustomTag(atags, DES).Decode();
                afi.Publisher = appleCustomTag(atags, PUB).Decode();
            }

            return(true);
        }
예제 #22
0
 private static TagLib.Ogg.XiphComment GetTag(TagLib.File file)
 {
     try {
         return(file.GetTag(TagLib.TagTypes.Xiph) as TagLib.Ogg.XiphComment);
     } catch (System.NullReferenceException e) {
         // Haven't seen crashes when getting Ogg tags, but just in case..
         // (See commentary for ID3v2 version)
         Hyena.Log.WarningFormat("Got exception when accessing Ogg Metadata in {0}:",
                                 file.Name);
         Hyena.Log.Warning(e.Message);
         Hyena.Log.Warning(e.StackTrace);
         return(null);
     }
 }
예제 #23
0
 private static TagLib.Id3v2.Tag GetTag(TagLib.File file)
 {
     try {
         return(file.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag);
     } catch (System.NullReferenceException e) {
         // TagLib# can crash here on unusual files (Ex: FLAC files with ID3v2 metadata)
         // Perhaps FLAC+ID3v2 is an unsupported combination for TagLib#?
         Hyena.Log.WarningFormat("Got exception when accessing ID3v2 Metadata in {0}:",
                                 file.Name);
         Hyena.Log.Warning(e.Message);
         Hyena.Log.Warning(e.StackTrace);
         return(null);
     }
 }
예제 #24
0
 public override async Task <bool> SetRating(MusicPlayer.Models.Track track, int rating)
 {
     using (TagLib.File file = TagLib.File.Create(track.FileLocation))
     {
         TagLib.Tag Tag = file.GetTag(TagLib.TagTypes.Id3v2);
         TagLib.Id3v2.Tag.DefaultVersion      = 3;
         TagLib.Id3v2.Tag.ForceDefaultVersion = true;
         var frame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)Tag, "WindowsUser", true);
         //based on 0-5;
         //taglib sharp is 0-255;
         frame.Rating = (byte)(rating * 51);
         file.Save();
     }
     return(true);
 }
예제 #25
0
        private byte GetRatingFromMetadata(TagLib.File file)
        {
            const byte noRating = 0;
            byte       rating;

            try
            {
                var tag   = file.GetTag(TagLib.TagTypes.Id3v2);
                var frame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, "WindowsUser", true);
                rating = frame.Rating;
            }
            catch (Exception)
            {
                rating = noRating;
            }
            return(rating);
        }
예제 #26
0
        internal void EmptyFrames()
        {
            if (_tagLibFile != null)
            {
                var id3v2Tag = (TagLib.Id3v2.Tag)_tagLibFile.GetTag(TagLib.TagTypes.Id3v2);

                if (id3v2Tag != null)
                {
                    // reference {https://en.wikipedia.org/wiki/ID3#ID3v2_Frame_Specification_.28Version_2.3.29}
                    id3v2Tag.SetTextFrame("WOAF", "");
                    id3v2Tag.SetTextFrame("TRSN", "");
                    id3v2Tag.SetTextFrame("TXXX", "");
                    id3v2Tag.SetTextFrame("WXXX", "");
                    id3v2Tag.SetTextFrame("TENC", "");
                }
            }
        }
예제 #27
0
        public static void UpdateFile(MasterFile mf)
        {
            TagLib.File tglb = TagLib.File.Create(mf.Filepath);
            tglb.Tag.Artists      = new string[] { mf.TagLibProps["Artist"].ToString() };
            tglb.Tag.AlbumArtists = new string[] { mf.TagLibProps["Artist"].ToString() };
            tglb.Tag.Performers   = new string[] { mf.TagLibProps["Artist"].ToString() };
            tglb.Tag.Album        = mf.TagLibProps["Album"].ToString();
            tglb.Tag.Genres       = new string[] { mf.TagLibProps["Genres"].ToString() };
            tglb.Tag.Lyrics       = mf.TagLibProps["Lyrics"].ToString();
            tglb.Tag.Title        = mf.TagLibProps["Title"].ToString();
            tglb.Tag.Track        = Convert.ToUInt32(mf.TagLibProps["Track"]);
            tglb.Tag.Year         = Convert.ToUInt32(mf.TagLibProps["Year"]);
            try
            {
                var tag   = tglb.GetTag(TagLib.TagTypes.Id3v2);
                var frame = TagLib.Id3v2.PopularimeterFrame.Get((TagLib.Id3v2.Tag)tag, "WindowsUser", true);
                frame.Rating = Convert.ToByte(mf.TagLibProps["Rating"]);
            }
            catch (Exception)
            {
            }

            // tglb original artist (cover) -- Might have to check with some API if isCover is true to retrieve original artist
            tglb.Tag.Comment = (bool)mf.TagLibProps["IsLive"] ? "Live" : "";
            try
            {
                tglb.Save();
            }
            catch (IOException ex)
            {
                var log = new LogWriter($"Can not save database data to {mf.Filepath}. \"{ex.Message}\"");
            }
            catch (Exception ex)
            {
                var log = new LogWriter($"Can not save database data to {mf.Filepath}. \"{ex.Message}\"");
            }

            var fileInfo = new FileInfo(mf.Filepath);
            var nameInDB = mf.SysIOProps["Name"].ToString();

            if (fileInfo.Name != nameInDB)
            {
                Rename(fileInfo, nameInDB);
            }
        }
예제 #28
0
        public MusicMetaData(string path)
        {
            using (TagLib.File file = TagLib.File.Create(path))
            {
                TagLib.Id3v2.Tag tag2;
                tag2 = file.GetTag(TagLib.TagTypes.Id3v2) as TagLib.Id3v2.Tag;


                Length   = new System.IO.FileInfo(path).Length;
                LengthKo = Length / 1024d;
                LengthMo = LengthMo / 1024d;

                Duration = file.Properties.Duration;
                if (file.Properties.VideoHeight > 0)
                {
                    VideoSize = new System.Drawing.Size(file.Properties.VideoWidth, file.Properties.VideoHeight);
                }
            }
        }
예제 #29
0
        protected override void Metadata()
        {
            ResetOutBuffer();
            using TagLib.File file = TagLib.File.Create(new MemoryFileAbstraction($"buffer.{MediaType.MimeToExt(MusicMime)}", OutBuffer));
            TagLib.Tag tag = MusicMime switch
            {
                "audio/flac" => file.Tag,
                "audio/mpeg" => file.GetTag(TagLib.TagTypes.Id3v2),
                _ => throw new FileLoadException($"Failed to get file type while processing \"{InPath}\"."),
            };

            if (CoverMime != null)
            {
                tag.Pictures = new TagLib.IPicture[1] {
                    new TagLib.Picture(new TagLib.ByteVector(CoverBuffer.ToArray(), (int)CoverBuffer.Length))
                    {
                        MimeType = CoverMime,
                        Type     = TagLib.PictureType.FrontCover
                    }
                };
            }

            if (StdMetadata.Title != null)
            {
                tag.Title = StdMetadata.Title;
            }
            if (StdMetadata.Artists != null)
            {
                tag.Performers = StdMetadata.Artists;
            }
            if (StdMetadata.Album != null)
            {
                tag.Album = StdMetadata.Album;
            }
            if (StdMetadata.AlbumArtist != null && tag.AlbumArtists.Length == 0)
            {
                tag.AlbumArtists = new string[] { StdMetadata.AlbumArtist }
            }
            ;

            file.Save();
        }
예제 #30
0
        public File2TagFormatEvaluator(string format, TagLib.File file)
            : base(@"\<[ABCEGKPRTYkp]\>")
        {
            this.file = file;
            tag       = file.GetTag(TagLib.TagTypes.Id3v1);
            string         fname = System.IO.Path.GetFileNameWithoutExtension(file.Name);
            Regex          regx  = new Regex(exp);
            MatchEvaluator meval = new MatchEvaluator(ReplaceFunc);

            value = regx.Replace(format, meval);

            Regex file_regx = new Regex(value);
            Match m         = file_regx.Match(fname);

            string[] grp_names = file_regx.GetGroupNames();
            foreach (string name in grp_names)
            {
                Group g = m.Groups[name];
                WriteTag(name, g.Value);
            }
        }