Esempio n. 1
0
        public Mp3Tagger(string path, bool write = true)
        {
            f = Utils.OpenFile(path, write);
            t = (TagLib.Id3v2.Tag)f.TagLibFile.GetTag(TagLib.TagTypes.Id3v2, true);
            if (t == null)
            {
                SafeClose();
                throw new HaException("MP3 file has no Id3v2 tag");
            }

            // ID3 is lame as hell, doesnt actually have textual description for tags (unlike beast-ass Xiph)
            valueTags.Add("album", FixString(t.Album));
            valueTags.Add("albumartist", FixString(Aggregate(t.AlbumArtists)));
            valueTags.Add("artist", FixString(Aggregate(t.Performers)));
            valueTags.Add("year", t.Year.ToString());

            IEnumerable <TagLib.Id3v2.UserTextInformationFrame> frames = t.GetFrames <TagLib.Id3v2.UserTextInformationFrame>().Where(x => x.Description.ToLower() == "hatag");

            if (frames.Count() > 0)
            {
                utif = frames.ElementAt(0);
                string data = utif.Text.Length == 0 ? "" : utif.Text[0];
                data.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(x => tags.Add(x));
            }
            else
            {
                utif = new TagLib.Id3v2.UserTextInformationFrame("hatag");
                utif.TextEncoding = TagLib.StringType.Latin1;
                t.AddFrame(utif);
            }
        }
Esempio n. 2
0
        public FlacTagger(string path, bool write = true)
        {
            f = Utils.OpenFile(path, write);
            t = (TagLib.Ogg.XiphComment)f.TagLibFile.GetTag(TagLib.TagTypes.Xiph, true);
            if (t == null)
            {
                SafeClose();
                throw new HaException("FLAC file has no Xiph tag");
            }
            foreach (string tagName in t)
            {
                valueTags.Add(tagName.ToLower(), t.GetFirstField(tagName).ToLower());
            }
            string data = t.GetFirstField("hatag");

            if (data != null)
            {
                data.Split(new string[] { "," }, StringSplitOptions.RemoveEmptyEntries).ToList().ForEach(x => tags.Add(x));
            }
        }