Пример #1
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...
                    }
                }
            }
        }
Пример #2
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);
            }
        }
Пример #3
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);
            }
        }