Beispiel #1
0
        // Scans the file for ogg rating/playcount tags as defined by the Quod Libet standard
        // If a Banshee tag is found, it is given priority.
        // If a Banshee tag is not found, the last rating/playcount tags found are used
        public static void GetRatingAndPlayCount(TagLib.File from_file,
                                                 ref int rating, ref int playcount)
        {
            TagLib.Ogg.XiphComment xiphtag = GetTag(from_file);
            if (xiphtag == null)
            {
                return;
            }

            bool   banshee_rating_done = false, banshee_playcount_done = false;
            string rating_raw = "", playcount_raw = "";

            foreach (string fieldname in xiphtag)
            {
                if (!banshee_rating_done &&
                    fieldname.ToUpper().StartsWith(rating_prefix))
                {
                    rating_raw = xiphtag.GetFirstField(fieldname);
                    string rating_creator = fieldname.Substring(rating_prefix.Length);
                    if (rating_creator.ToUpper() == ogg_our_creator_name)
                    {
                        // We made this rating, consider it authoritative.
                        banshee_rating_done = true;
                        // Don't return -- we might not have seen a playcount yet.
                    }
                }
                else if (!banshee_playcount_done &&
                         fieldname.ToUpper().StartsWith(playcount_prefix))
                {
                    playcount_raw = xiphtag.GetFirstField(fieldname);
                    string playcount_creator = fieldname.Substring(playcount_prefix.Length);
                    if (playcount_creator.ToUpper() == ogg_our_creator_name)
                    {
                        // We made this playcount, consider it authoritative.
                        banshee_playcount_done = true;
                        // Don't return -- we might not have seen a rating yet.
                    }
                }
            }
            if (rating_raw != "")
            {
                rating = OggToBanshee(rating_raw);
            }
            if (playcount_raw != "")
            {
                playcount = int.Parse(playcount_raw);
            }
            Hyena.Log.DebugFormat("Importing Ogg Rating={0}({1}) and Playcount={2}({3}) from File \"{4}\"",
                                  rating, rating_raw,
                                  playcount, playcount_raw, from_file.Name);
        }
Beispiel #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));
            }
        }