Exemple #1
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);
     }
 }
Exemple #2
0
        public static void Write(TagLibMetaDataSource source, MetaDataItem metaDataItem, File file)
        {
            if (string.Equals(metaDataItem.Name, CommonMetaData.IsCompilation, StringComparison.OrdinalIgnoreCase))
            {
                var isCompilation = string.Equals(metaDataItem.Value, bool.TrueString, StringComparison.OrdinalIgnoreCase);

                if (TagManager.HasTag(file, TagTypes.Id3v2))
                {
                    var tag = TagManager.GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
                    if (tag != null)
                    {
                        tag.IsCompilation = isCompilation;
                    }
                }
                else if (TagManager.HasTag(file, TagTypes.Apple))
                {
                    var tag = TagManager.GetTag <global::TagLib.Mpeg4.AppleTag>(file, TagTypes.Apple);
                    if (tag != null)
                    {
                        tag.IsCompilation = isCompilation;
                    }
                }
                else if (TagManager.HasTag(file, TagTypes.Xiph))
                {
                    var tag = TagManager.GetTag <global::TagLib.Ogg.XiphComment>(file, TagTypes.Xiph);
                    if (tag != null)
                    {
                        tag.IsCompilation = isCompilation;
                    }
                }

                if (source.MusicBrainz.Value)
                {
                    if (isCompilation)
                    {
                        file.Tag.MusicBrainzReleaseType = MusicBrainzReleaseType.Compilation;
                    }
                    else if (string.Equals(file.Tag.MusicBrainzReleaseType, MusicBrainzReleaseType.Compilation, StringComparison.OrdinalIgnoreCase))
                    {
                        //TODO: MusicBrainzReleaseType could be anything...
                    }
                }
            }
        }
Exemple #3
0
        public static void Read(TagLibMetaDataSource source, IList <MetaDataItem> metaData, File file)
        {
            var isCompilation = default(bool);

            if (TagManager.HasTag(file, TagTypes.Id3v2))
            {
                var tag = TagManager.GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
                if (tag != null)
                {
                    isCompilation = tag.IsCompilation;
                }
            }
            else if (TagManager.HasTag(file, TagTypes.Apple))
            {
                var tag = TagManager.GetTag <global::TagLib.Mpeg4.AppleTag>(file, TagTypes.Apple);
                if (tag != null)
                {
                    isCompilation = tag.IsCompilation;
                }
            }
            else if (TagManager.HasTag(file, TagTypes.Xiph))
            {
                var tag = TagManager.GetTag <global::TagLib.Ogg.XiphComment>(file, TagTypes.Xiph);
                if (tag != null)
                {
                    isCompilation = tag.IsCompilation;
                }
            }

            //Check MB release type, it's innocuous so don't bother respecting READ_MUSICBRAINZ_TAGS.
            if (string.Equals(file.Tag.MusicBrainzReleaseType, MusicBrainzReleaseType.Compilation, StringComparison.OrdinalIgnoreCase))
            {
                isCompilation = true;
            }

            if (isCompilation)
            {
                source.AddTag(metaData, CommonMetaData.IsCompilation, bool.TrueString);
                //TODO: CustomMetaData.VariousArtists should go away but scripts use it, let's keep it updated for now.
                source.AddTag(metaData, CustomMetaData.VariousArtists, bool.TrueString);
            }
        }
Exemple #4
0
        public static void Read(TagLibMetaDataSource source, IList <MetaDataItem> metaData, File file)
        {
            var result = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase);

            //If it's an Id3v2 tag then try to read the popularimeter frame.
            //It can contain a rating and a play counter.
            if (file.TagTypes.HasFlag(TagTypes.Id3v2))
            {
                var tag = TagManager.GetTag <global::TagLib.Id3v2.Tag>(file, TagTypes.Id3v2);
                if (tag == null)
                {
                    return;
                }
                foreach (var frame in tag.GetFrames <global::TagLib.Id3v2.PopularimeterFrame>())
                {
                    ReadPopularimeterFrame(frame, result);
                }
            }
            //If we didn't find a popularimeter frame then attempt to read the rating from a custom tag.
            if (!result.ContainsKey(CommonStatistics.Rating))
            {
                var rating = TagManager.ReadCustomTag(CommonStatistics.Rating, file);
                if (!string.IsNullOrEmpty(rating))
                {
                    result.Add(CommonStatistics.Rating, Convert.ToString(GetRatingStars(rating)));
                }
                else
                {
                    result.Add(CommonStatistics.Rating, string.Empty);
                }
            }
            //If we didn't find a popularimeter frame then attempt to read the play count from a custom tag.
            if (!result.ContainsKey(CommonStatistics.PlayCount))
            {
                var playCount = TagManager.ReadCustomTag(CommonStatistics.PlayCount, file);
                if (!string.IsNullOrEmpty(playCount))
                {
                    result.Add(CommonStatistics.PlayCount, playCount);
                }
                else
                {
                    result.Add(CommonStatistics.PlayCount, "0");
                }
            }
            //Popularimeter frame does not support last played, attempt to read the play count from a custom tag.
            //if (!result.ContainsKey(CommonMetaData.LastPlayed))
            {
                var lastPlayed = TagManager.ReadCustomTag(CommonStatistics.LastPlayed, file);
                if (!string.IsNullOrEmpty(lastPlayed))
                {
                    result.Add(CommonStatistics.LastPlayed, lastPlayed);
                }
                else
                {
                    result.Add(CommonStatistics.LastPlayed, DateTimeHelper.NEVER);
                }
            }
            //Copy our informations back to the meta data collection.
            foreach (var key in result.Keys)
            {
                var value = result[key];
                source.AddTag(metaData, key, value);
            }
        }