コード例 #1
0
 public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
 {
     if (file.TagTypes.HasFlag(TagTypes.Id3v2))
     {
         var tag    = GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
         var frames = tag.GetFrames <global::TagLib.Id3v2.PopularimeterFrame>();
         if (frames != null && frames.Any())
         {
             foreach (var frame in frames)
             {
                 WritePopularimeterFrame(source, metaDataItem, file, frame);
             }
         }
         else
         {
             var frame = new global::TagLib.Id3v2.PopularimeterFrame(string.Empty);
             WritePopularimeterFrame(source, metaDataItem, file, frame);
             tag.AddFrame(frame);
         }
     }
     else
     {
         WriteCustomTag(metaDataItem.Name, metaDataItem.Value, file);
     }
 }
コード例 #2
0
 public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
 {
     if (file.TagTypes.HasFlag(TagTypes.Id3v2) && (new[] { CommonStatistics.Rating, CommonStatistics.PlayCount }).Contains(metaDataItem.Name, StringComparer.OrdinalIgnoreCase))
     {
         var tag    = TagManager.GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
         var frames = tag.GetFrames <global::TagLib.Id3v2.PopularimeterFrame>();
         if (frames != null && frames.Any())
         {
             foreach (var frame in frames)
             {
                 WritePopularimeterFrame(frame, metaDataItem);
             }
         }
         else
         {
             var frame = new global::TagLib.Id3v2.PopularimeterFrame(string.Empty);
             WritePopularimeterFrame(frame, metaDataItem);
             tag.AddFrame(frame);
         }
     }
     else if (string.Equals(metaDataItem.Name, CommonStatistics.Rating, StringComparison.OrdinalIgnoreCase))
     {
         TagManager.WriteCustomTag(metaDataItem.Name, Convert.ToString(GetRatingMask(metaDataItem.Value)), file);
     }
     else
     {
         TagManager.WriteCustomTag(metaDataItem.Name, metaDataItem.Value, file);
     }
 }
コード例 #3
0
 private static void ReadPopularimeterFrame(global::TagLib.Id3v2.PopularimeterFrame frame, IDictionary <string, string> result)
 {
     if (frame.Rating > 0)
     {
         result.Add(CommonStatistics.Rating, Convert.ToString(GetRatingStars(frame.Rating)));
     }
     if (frame.PlayCount > 0)
     {
         result.Add(CommonStatistics.PlayCount, Convert.ToString(frame.PlayCount));
     }
 }
コード例 #4
0
 private static void WritePopularimeterFrame(global::TagLib.Id3v2.PopularimeterFrame frame, MetaDataItem metaDataItem)
 {
     if (string.Equals(metaDataItem.Name, CommonStatistics.Rating, StringComparison.OrdinalIgnoreCase))
     {
         frame.Rating = GetRatingMask(metaDataItem.Value);
     }
     else if (string.Equals(metaDataItem.Name, CommonStatistics.PlayCount, StringComparison.OrdinalIgnoreCase))
     {
         frame.PlayCount = Convert.ToUInt64(metaDataItem.Value);
     }
 }
コード例 #5
0
            private static void WritePopularimeterFrame(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file, global::TagLib.Id3v2.PopularimeterFrame frame)
            {
                const byte RATING_1 = 1;
                const byte RATING_2 = 64;
                const byte RATING_3 = 128;
                const byte RATING_4 = 196;
                const byte RATING_5 = 255;

                switch (metaDataItem.Name)
                {
                case CommonMetaData.Rating:
                    switch (Convert.ToByte(metaDataItem.Value))
                    {
                    case 1:
                        frame.Rating = RATING_1;
                        break;

                    case 2:
                        frame.Rating = RATING_2;
                        break;

                    case 3:
                        frame.Rating = RATING_3;
                        break;

                    case 4:
                        frame.Rating = RATING_4;
                        break;

                    case 5:
                        frame.Rating = RATING_5;
                        break;
                    }
                    break;

                case CommonMetaData.PlayCount:
                    frame.PlayCount = Convert.ToUInt64(metaDataItem.Value);
                    break;
                }
            }
コード例 #6
0
            private static void ReadPopularimeterFrame(TagLibMetaDataSource source, IList <MetaDataItem> metaData, File file, global::TagLib.Id3v2.PopularimeterFrame frame)
            {
                const byte RATING_1 = 1;
                const byte RATING_2 = 64;
                const byte RATING_3 = 128;
                const byte RATING_4 = 196;
                const byte RATING_5 = 255;

                if (frame.Rating != 0)
                {
                    var rating = 0;
                    switch (frame.Rating)
                    {
                    case RATING_1:
                        rating = 1;
                        break;

                    case RATING_2:
                        rating = 2;
                        break;

                    case RATING_3:
                        rating = 3;
                        break;

                    case RATING_4:
                        rating = 4;
                        break;

                    case RATING_5:
                        rating = 5;
                        break;
                    }
                    source.AddTag(metaData, CommonMetaData.Rating, Convert.ToString(rating));
                }
                if (frame.PlayCount != 0)
                {
                    source.AddTag(metaData, CommonMetaData.PlayCount, Convert.ToString(frame.PlayCount));
                }
            }