コード例 #1
0
        public void TrackUtils_EncodePopularity()
        {
            // Cases not covered by metadata-specific test classes
            Assert.AreEqual(0, TrackUtils.EncodePopularity("0.5", MetaDataIO.RC_ASF));
            Assert.AreEqual(1, TrackUtils.EncodePopularity("1.5", MetaDataIO.RC_ASF));
            Assert.AreEqual(1, TrackUtils.EncodePopularity("1,5", MetaDataIO.RC_ASF));
            Assert.AreEqual(25, TrackUtils.EncodePopularity("2.5", MetaDataIO.RC_ASF));
            Assert.AreEqual(50, TrackUtils.EncodePopularity("3.5", MetaDataIO.RC_ASF));
            Assert.AreEqual(75, TrackUtils.EncodePopularity("4.5", MetaDataIO.RC_ASF));
            Assert.AreEqual(99, TrackUtils.EncodePopularity("5", MetaDataIO.RC_ASF));

            Assert.AreEqual(0, TrackUtils.EncodePopularity("0.25", MetaDataIO.RC_APE));
            Assert.AreEqual(10, TrackUtils.EncodePopularity("0.5", MetaDataIO.RC_APE));
            Assert.AreEqual(20, TrackUtils.EncodePopularity("1", MetaDataIO.RC_APE));
            Assert.AreEqual(30, TrackUtils.EncodePopularity("1.5", MetaDataIO.RC_APE));
            Assert.AreEqual(40, TrackUtils.EncodePopularity("2", MetaDataIO.RC_APE));
            Assert.AreEqual(50, TrackUtils.EncodePopularity("2.5", MetaDataIO.RC_APE));
            Assert.AreEqual(60, TrackUtils.EncodePopularity("3", MetaDataIO.RC_APE));
            Assert.AreEqual(70, TrackUtils.EncodePopularity("3.5", MetaDataIO.RC_APE));
            Assert.AreEqual(80, TrackUtils.EncodePopularity("4", MetaDataIO.RC_APE));
            Assert.AreEqual(90, TrackUtils.EncodePopularity("4.5", MetaDataIO.RC_APE));
            Assert.AreEqual(100, TrackUtils.EncodePopularity("5", MetaDataIO.RC_APE));

            Assert.AreEqual(0, TrackUtils.EncodePopularity("0.25", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(13, TrackUtils.EncodePopularity("0.5", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(1, TrackUtils.EncodePopularity("1", MetaDataIO.RC_ID3v2)); // <-- yes, 1
            Assert.AreEqual(54, TrackUtils.EncodePopularity("1.5", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(64, TrackUtils.EncodePopularity("2", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(118, TrackUtils.EncodePopularity("2.5", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(128, TrackUtils.EncodePopularity("3", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(186, TrackUtils.EncodePopularity("3.5", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(196, TrackUtils.EncodePopularity("4", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(242, TrackUtils.EncodePopularity("4.5", MetaDataIO.RC_ID3v2));
            Assert.AreEqual(255, TrackUtils.EncodePopularity("5", MetaDataIO.RC_ID3v2));
        }
コード例 #2
0
ファイル: MetaDataIO.cs プロジェクト: iaingoodhew/atldotnet
        protected string formatBeforeWriting(byte frameType, TagData tag, IDictionary <byte, string> map)
        {
            string value = "";
            string total = "";

            switch (frameType)
            {
            case TagData.TAG_FIELD_RATING: return(TrackUtils.EncodePopularity(map[frameType], ratingConvention).ToString());

            case TagData.TAG_FIELD_TRACK_NUMBER:
                value = map[TagData.TAG_FIELD_TRACK_NUMBER];
                map.TryGetValue(TagData.TAG_FIELD_TRACK_TOTAL, out total);
                return(TrackUtils.ApplyLeadingZeroes(value, total, tag.TrackDigitsForLeadingZeroes, Settings.UseLeadingZeroes, Settings.OverrideExistingLeadingZeroesFormat));

            case TagData.TAG_FIELD_TRACK_TOTAL:
                value = map[TagData.TAG_FIELD_TRACK_TOTAL];
                total = value;
                return(TrackUtils.ApplyLeadingZeroes(value, total, tag.TrackDigitsForLeadingZeroes, Settings.UseLeadingZeroes, Settings.OverrideExistingLeadingZeroesFormat));

            case TagData.TAG_FIELD_TRACK_NUMBER_TOTAL:
                value = map[TagData.TAG_FIELD_TRACK_NUMBER_TOTAL];
                total = value;
                return(TrackUtils.ApplyLeadingZeroes(value, total, tag.TrackDigitsForLeadingZeroes, Settings.UseLeadingZeroes, Settings.OverrideExistingLeadingZeroesFormat));

            case TagData.TAG_FIELD_DISC_NUMBER:
                value = map[TagData.TAG_FIELD_DISC_NUMBER];
                map.TryGetValue(TagData.TAG_FIELD_DISC_TOTAL, out total);
                return(TrackUtils.ApplyLeadingZeroes(value, total, tag.DiscDigitsForLeadingZeroes, Settings.UseLeadingZeroes, Settings.OverrideExistingLeadingZeroesFormat));

            case TagData.TAG_FIELD_DISC_TOTAL:
                value = map[TagData.TAG_FIELD_DISC_TOTAL];
                total = value;
                return(TrackUtils.ApplyLeadingZeroes(value, total, tag.DiscDigitsForLeadingZeroes, Settings.UseLeadingZeroes, Settings.OverrideExistingLeadingZeroesFormat));

            case TagData.TAG_FIELD_DISC_NUMBER_TOTAL:
                value = map[TagData.TAG_FIELD_DISC_NUMBER_TOTAL];
                total = value;
                return(TrackUtils.ApplyLeadingZeroes(value, total, tag.DiscDigitsForLeadingZeroes, Settings.UseLeadingZeroes, Settings.OverrideExistingLeadingZeroesFormat));

            default: return(map[frameType]);
            }
        }
コード例 #3
0
ファイル: APEtag.cs プロジェクト: thelazurite/MusicCleanup
        private Int32 writeFrames(TagData tag, BinaryWriter w)
        {
            Boolean doWritePicture;
            var     nbFrames = 0;

            // Picture fields (first before textual fields, since APE tag is located on the footer)
            foreach (var picInfo in tag.Pictures)
            {
                // Picture has either to be supported, or to come from the right tag standard
                doWritePicture = !picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported);
                if (!doWritePicture)
                {
                    doWritePicture = (getImplementedTagType() == picInfo.TagType);
                }
                // It also has not to be marked for deletion
                doWritePicture = doWritePicture && (!picInfo.MarkedForDeletion);

                if (doWritePicture)
                {
                    writePictureFrame(w, picInfo.PictureData, picInfo.NativeFormat, ImageUtils.GetMimeTypeFromImageFormat(picInfo.NativeFormat), picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? picInfo.NativePicCodeStr : encodeAPEPictureType(picInfo.PicType), picInfo.Description);
                    nbFrames++;
                }
            }

            var map = tag.ToMap();

            // Supported textual fields
            foreach (var frameType in map.Keys)
            {
                foreach (var s in frameMapping.Keys)
                {
                    if (frameType == frameMapping[s])
                    {
                        if (map[frameType].Length > 0) // No frame with empty value
                        {
                            var value = map[frameType];
                            if (TagData.TAG_FIELD_RATING == frameType)
                            {
                                value = TrackUtils.EncodePopularity(value, ratingConvention).ToString();
                            }

                            writeTextFrame(w, s, value);
                            nbFrames++;
                        }
                        break;
                    }
                }
            }

            // Other textual fields
            foreach (var fieldInfo in tag.AdditionalFields)
            {
                if ((fieldInfo.TagType.Equals(MetaDataIOFactory.TAG_ANY) || fieldInfo.TagType.Equals(getImplementedTagType())) && !fieldInfo.MarkedForDeletion)
                {
                    writeTextFrame(w, fieldInfo.NativeFieldCode, fieldInfo.Value);
                    nbFrames++;
                }
            }

            return(nbFrames);
        }
コード例 #4
0
ファイル: VorbisTag.cs プロジェクト: superowner/atldotnet
        private uint writeFrames(TagData tag, BinaryWriter w)
        {
            bool doWritePicture;
            uint nbFrames = 0;

            IDictionary <byte, String> map = tag.ToMap();

            // Supported textual fields
            foreach (byte frameType in map.Keys)
            {
                foreach (string s in frameMapping.Keys)
                {
                    if (frameType == frameMapping[s])
                    {
                        if (map[frameType].Length > 0) // No frame with empty value
                        {
                            string value = map[frameType];
                            if (TagData.TAG_FIELD_RATING == frameType)
                            {
                                value = TrackUtils.EncodePopularity(value, ratingConvention).ToString();
                            }

                            writeTextFrame(w, s, value);
                            nbFrames++;
                        }
                        break;
                    }
                }
            }

            // Chapters
            if (Chapters.Count > 0)
            {
                writeChapters(w, Chapters);
            }

            // Other textual fields
            foreach (MetaFieldInfo fieldInfo in tag.AdditionalFields)
            {
                if ((fieldInfo.TagType.Equals(MetaDataIOFactory.TAG_ANY) || fieldInfo.TagType.Equals(getImplementedTagType())) && !fieldInfo.MarkedForDeletion && !fieldInfo.NativeFieldCode.Equals(VENDOR_METADATA_ID))
                {
                    writeTextFrame(w, fieldInfo.NativeFieldCode, fieldInfo.Value);
                    nbFrames++;
                }
            }

            // Picture fields
            if (writePicturesWithMetadata)
            {
                foreach (PictureInfo picInfo in tag.Pictures)
                {
                    // Picture has either to be supported, or to come from the right tag standard
                    doWritePicture = !picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported);
                    if (!doWritePicture)
                    {
                        doWritePicture = (getImplementedTagType() == picInfo.TagType);
                    }
                    // It also has not to be marked for deletion
                    doWritePicture = doWritePicture && (!picInfo.MarkedForDeletion);

                    if (doWritePicture)
                    {
                        writePictureFrame(w, picInfo.PictureData, picInfo.NativeFormat, ImageUtils.GetMimeTypeFromImageFormat(picInfo.NativeFormat), picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? picInfo.NativePicCode : ID3v2.EncodeID3v2PictureType(picInfo.PicType), picInfo.Description);
                        nbFrames++;
                    }
                }
            }

            return(nbFrames);
        }