示例#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.Ogg.XiphComment xiphtag,
                                                    out int rating, out int playcount)
        {
            rating = -1;
            playcount = 0;
            bool howlerRatingDone = false, howlerPlaycountDone = false, mediaMonkeyFormat = false;
            string ratingRaw = "", playcountRaw = "";

            foreach (string fieldname in xiphtag)
            {

                if (!howlerRatingDone)
                {
                    if (fieldname.StartsWith(RatingPrefix, StringComparison.OrdinalIgnoreCase))
                    {
                        ratingRaw = xiphtag.GetFirstField(fieldname);
                        string ratingCreator = fieldname.Substring(RatingPrefix.Length);
                        if (String.Compare(ratingCreator, HowlerName, StringComparison.OrdinalIgnoreCase) == 0)
                        {
                            // We made this rating, consider it authoritative.
                            howlerRatingDone = true;
                            // Don't return -- we might not have seen a playcount yet.
                        }
                    }
                    else if (String.Compare(fieldname, MediaMonkeyRatingField, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        ratingRaw = xiphtag.GetFirstField(fieldname);
                        mediaMonkeyFormat = true;
                    }

                }
                else if (!howlerPlaycountDone &&
                            fieldname.StartsWith(PlaycountPrefix, StringComparison.OrdinalIgnoreCase))
                {

                    playcountRaw = xiphtag.GetFirstField(fieldname);
                    string playcountCreator = fieldname.Substring(PlaycountPrefix.Length);
                    if (string.Compare(playcountCreator, HowlerName, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        // We made this playcount, consider it authoritative.
                        howlerPlaycountDone = true;
                        // Don't return -- we might not have seen a rating yet.
                    }
                }
            }
            if (!string.IsNullOrEmpty(ratingRaw))
            {
                if (howlerRatingDone || mediaMonkeyFormat)
                    rating = int.Parse(ratingRaw, CultureInfo.InvariantCulture);
                else
                {
                    int bansheeRating = OggToBanshee(ratingRaw);
                    rating = bansheeRating == 0 ? -1 : bansheeRating * 5;
                }

            }
            if (!string.IsNullOrEmpty(playcountRaw))
            {
                playcount = int.Parse(playcountRaw, CultureInfo.InvariantCulture);
            }
        }