Exemplo n.º 1
0
        public AA()
        {
            notEmptyFile = "AA/aa.aa";
            tagType      = MetaDataIOFactory.TAG_NATIVE;

            // Initialize specific test data
            testData = new TagData();

            testData.Title              = "The New York Times Audio Digest, July 10, 2015";
            testData.Artist             = "The New York Times";
            testData.Album              = "The New York Times Audio Digest";
            testData.Comment            = "It's the perfect listen for your morning commute! In the time it takes you to get to work, you'll hear a digest of the day's top stories, prepared by the editorial staff of The New York Times....";
            testData.PublishingDate     = DateTime.Parse("10-JUL-2015").ToString();
            testData.Publisher          = "The New York Times";
            testData.Composer           = "The New York Times";
            testData.GeneralDescription = "It's the perfect listen for your morning commute! In the time it takes you to get to work, you'll hear a digest of the day's top stories, prepared by the editorial staff of The New York Times. Each edition includes articles from the front page, as well as the paper's international, national, business, sports, and editorial sections.";
            testData.Copyright          = "(P) and ©2015 The New York Times News Services Division of The New York Times Company";

            // Initialize specific test data (Picture native codes are strings)
            testData.Pictures.Clear();
            PictureInfo pic = PictureInfo.fromBinaryData(
                File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "AA/aa.jpg"),
                PIC_TYPE.Generic,
                MetaDataIOFactory.TAG_ANY,
                11);

            pic.ComputePicHash();
            testData.Pictures.Add(pic);

            supportsInternationalChars = true;
        }
Exemplo n.º 2
0
        public void ReadPicture(Stream s, ReadTagParams readTagParams)
        {
            int  picturePosition;
            long initPosition = s.Position;
            VorbisMetaDataBlockPicture block = ReadMetadataBlockPicture(s);

            if (block.picType.Equals(PictureInfo.PIC_TYPE.Unsupported))
            {
                addPictureToken(getImplementedTagType(), (byte)block.nativePicCode);
                picturePosition = takePicturePosition(getImplementedTagType(), (byte)block.nativePicCode);
            }
            else
            {
                addPictureToken(block.picType);
                picturePosition = takePicturePosition(block.picType);
            }

            if (readTagParams.ReadPictures)
            {
                s.Seek(initPosition + block.picDataOffset, SeekOrigin.Begin);
                PictureInfo picInfo = PictureInfo.fromBinaryData(s, block.picDataLength, block.picType, getImplementedTagType(), block.nativePicCode, picturePosition);
                picInfo.Description = block.description;
                tagData.Pictures.Add(picInfo);

                if (!tagExists)
                {
                    tagExists = true;
                }
            }
        }
Exemplo n.º 3
0
        public APE()
        {
            emptyFile    = "MP3/empty.mp3";
            notEmptyFile = "MP3/APE.mp3";
            tagType      = MetaDataIOFactory.TAG_APE;

            // Initialize specific test data (Publisher and Description fields not supported in APE tag)
            testData.Publisher          = null;
            testData.GeneralDescription = null;
            testData.RecordingDate      = null;

            // Initialize specific test data (Picture native codes are strings)
            testData.Pictures.Clear();
            PictureInfo pic = PictureInfo.fromBinaryData(
                File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpeg"),
                PIC_TYPE.Unsupported,
                MetaDataIOFactory.TAG_ANY,
                "COVER ART (FRONT)");

            pic.ComputePicHash();
            testData.Pictures.Add(pic);

            pic = PictureInfo.fromBinaryData(
                File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.png"),
                PIC_TYPE.Unsupported,
                MetaDataIOFactory.TAG_ANY,
                "COVER ART (BACK)");
            pic.ComputePicHash();
            testData.Pictures.Add(pic);
        }
Exemplo n.º 4
0
        public MP4()
        {
            emptyFile    = "AAC/empty.m4a"; // Has empty udta/meta tags
            notEmptyFile = "AAC/mp4.m4a";
            tagType      = MetaDataIOFactory.TAG_NATIVE;

            // MP4 does not support leading zeroes
            testData.TrackNumber   = "1";
            testData.TrackTotal    = "2";
            testData.DiscNumber    = "3";
            testData.DiscTotal     = "4";
            testData.RecordingDate = "1997-06-20T00:00:00"; // No timestamp in MP4 date format
            testData.Conductor     = null;                  // TODO - Should be supported; extended field makes it harder to manipulate by the generic test code
            testData.Publisher     = null;
            testData.Genre         = "Household";           // "House" was generating a 'gnre' numeric field whereas ATL standard way of tagging is '(c)gen' string field => Start with a non-standard Genre

            testData.AdditionalFields.Clear();
            testData.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, "----:com.apple.iTunes:TEST", "xxx"));

            testData.Pictures.Clear();
            PictureInfo pic = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpeg"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_ANY, 13);

            pic.ComputePicHash();
            testData.Pictures.Add(pic);

            supportsDateOrYear = true;
        }
Exemplo n.º 5
0
        private void readCover(BinaryReader source, long offset, PictureInfo.PIC_TYPE pictureType)
        {
            source.BaseStream.Seek(offset, SeekOrigin.Begin);
            int pictureSize = StreamUtils.DecodeBEInt32(source.ReadBytes(4));
            int picOffset   = StreamUtils.DecodeBEInt32(source.ReadBytes(4));

            source.BaseStream.Seek(picOffset, SeekOrigin.Begin);

            PictureInfo picInfo = PictureInfo.fromBinaryData(source.BaseStream, pictureSize, pictureType, getImplementedTagType(), TOC_COVER_ART);

            tagData.Pictures.Add(picInfo);
        }
Exemplo n.º 6
0
        private void ImportCoverButton_Click(object sender, RoutedEventArgs e)
        {
            var dialog = new OpenFileDialog();
            var image  = CoverArts[CoverArtSelector.SelectedIndex];

            dialog.Filter = "Image Files|*.png;*.jpg|Other|*";
            if (dialog.ShowDialog() == true)
            {
                CoverArts[CoverArtSelector.SelectedIndex] = PictureInfo.fromBinaryData(
                    File.ReadAllBytes(dialog.FileName),
                    image.PicType);
            }
            ChangeCoverArt();
            SetUnsavedChanges(true);
        }
Exemplo n.º 7
0
        public void TagIO_RW_AddRemoveTagPictures()
        {
            string testFileLocation = TestUtils.CopyAsTempTestFile("MP3/id3v2.4_UTF8.mp3");
            Track  theTrack         = new Track(testFileLocation);

            theTrack.EmbeddedPictures.RemoveAt(1); // Remove Conductor; Front Cover remains

            // Add CD
            PictureInfo newPicture = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.gif"), PictureInfo.PIC_TYPE.CD);

            theTrack.EmbeddedPictures.Add(newPicture);

            theTrack.Save();

            theTrack = new Track(testFileLocation);

            Assert.AreEqual(2, theTrack.EmbeddedPictures.Count); // Front Cover, CD

            bool foundFront = false;
            bool foundCD    = false;

            foreach (PictureInfo pic in theTrack.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Front))
                {
                    foundFront = true;
                }
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.CD))
                {
                    foundCD = true;
                }
            }

            Assert.IsTrue(foundFront);
            Assert.IsTrue(foundCD);

            // Remove all
            theTrack.EmbeddedPictures.Clear();
            theTrack.Save();
            theTrack = new Track(testFileLocation);
            Assert.AreEqual(0, theTrack.EmbeddedPictures.Count);

            // Get rid of the working copy
            if (Settings.DeleteAfterSuccess)
            {
                File.Delete(testFileLocation);
            }
        }
Exemplo n.º 8
0
        public void CS_UpdatingMetadataPictures()
        {
            // Load audio file information into memory
            Track theTrack = new Track(audioFilePath);

            // Delete first embedded picture (let's say it exists)
            theTrack.EmbeddedPictures.RemoveAt(0);

            // Add 'CD' embedded picture
            PictureInfo newPicture = PictureInfo.fromBinaryData(System.IO.File.ReadAllBytes(imagePath), PictureInfo.PIC_TYPE.CD);

            theTrack.EmbeddedPictures.Add(newPicture);

            // Save modifications on the disc
            theTrack.Save();
        }
Exemplo n.º 9
0
        public void TagIO_RW_UpdateTagPictures()
        {
            string testFileLocation = TestUtils.CopyAsTempTestFile("MP3/id3v2.4_UTF8.mp3");
            Track  theTrack         = new Track(testFileLocation);

            // Update Front picture
            PictureInfo newPicture = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg"), PictureInfo.PIC_TYPE.Front);

            theTrack.EmbeddedPictures.Add(newPicture);

            theTrack.Save();

            theTrack = new Track(testFileLocation);

            Assert.AreEqual(2, theTrack.EmbeddedPictures.Count); // Front Cover, Conductor

            bool foundFront     = false;
            bool foundConductor = false;

            foreach (PictureInfo pic in theTrack.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Front))
                {
                    foundFront = true;
                    using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                    {
                        Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Assert.AreEqual(900, picture.Width);
                        Assert.AreEqual(290, picture.Height);
                    }
                }
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported))
                {
                    foundConductor = true;
                }
            }

            Assert.IsTrue(foundFront);
            Assert.IsTrue(foundConductor);

            // Get rid of the working copy
            if (Settings.DeleteAfterSuccess)
            {
                File.Delete(testFileLocation);
            }
        }
Exemplo n.º 10
0
        public void CS_WriteChapters()
        {
            // Note : if you target ID3v2 chapters, it is highly advised to use Settings.ID3v2_tagSubVersion = 3
            // as most readers only support ID3v2.3 chapters
            Track theFile = new Track(audioFilePath);

            theFile.Chapters = new System.Collections.Generic.List <ChapterInfo>();

            ChapterInfo ch = new ChapterInfo();

            ch.StartTime   = 123;
            ch.StartOffset = 456;
            ch.EndTime     = 789;
            ch.EndOffset   = 101112;
            ch.UniqueID    = "";
            ch.Title       = "aaa";
            ch.Subtitle    = "bbb";
            ch.Url         = new ChapterInfo.UrlInfo("ccc", "ddd");
            theFile.Chapters.Add(ch);

            ch             = new ChapterInfo();
            ch.StartTime   = 1230;
            ch.StartOffset = 4560;
            ch.EndTime     = 7890;
            ch.EndOffset   = 1011120;
            ch.UniqueID    = "002";
            ch.Title       = "aaa0";
            ch.Subtitle    = "bbb0";
            ch.Url         = new ChapterInfo.UrlInfo("ccc", "ddd0");
            // Add a picture to the 2nd chapter
            ch.Picture = PictureInfo.fromBinaryData(System.IO.File.ReadAllBytes(imagePath));
            theFile.Chapters.Add(ch);

            // Persists the chapters
            theFile.Save();

            // Reads the file again from sratch
            theFile = new Track(audioFilePath);
            IList <PictureInfo> pics = theFile.EmbeddedPictures; // Hack to load chapter pictures

            // Display chapters
            foreach (ChapterInfo chap in theFile.Chapters)
            {
                System.Console.WriteLine(chap.Title + "(" + chap.StartTime + ")");
            }
        }
Exemplo n.º 11
0
        public void performWrite(String filePath)
        {
            IProgress <float> progress = new Progress <float>(displayProgress);
            Track             t        = new Track(filePath /*, progress*/);

            //t.AdditionalFields.Add(new KeyValuePair<string, string>("test", "aaa"));
            // Modify metadata
            t.Artist   = "Hey ho";
            t.Composer = "Oscar Wilde";
            t.Album    = "Fake album starts here and is longer than the original one";

            if (t.EmbeddedPictures.Count > 0)
            {
                t.EmbeddedPictures.Clear();
            }
            t.EmbeddedPictures.Add(PictureInfo.fromBinaryData(File.ReadAllBytes(@"E:\temp\mp3\windowsIcon\folder.jpg")));

            t.Save();
        }
Exemplo n.º 12
0
        public MetaIOTest()
        {
            // Initialize default test data
            testData = new TagData();

            testData.Title              = "aa父bb";
            testData.Artist             = "֎FATHER֎";
            testData.Album              = "Papa֍rules";
            testData.AlbumArtist        = "aaᱬbb";
            testData.Comment            = "父父!";
            testData.RecordingYear      = "1997";
            testData.RecordingDate      = "1997-06-20T04:04:04";
            testData.Genre              = "House";
            testData.Rating             = "0";
            testData.TrackNumber        = "01";
            testData.TrackTotal         = "02";
            testData.Composer           = "ccᱬdd";
            testData.Conductor          = ""; // Empty string means "supported, but not valued in test sample"
            testData.Publisher          = "";
            testData.DiscNumber         = "03";
            testData.DiscTotal          = "04";
            testData.Copyright          = "";
            testData.GeneralDescription = "";

            testData.AdditionalFields = new List <MetaFieldInfo>();
            testData.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ANY, "TEST", "xxx"));

            testData.Pictures = new List <PictureInfo>();
            PictureInfo pic = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpeg"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_ANY, 0x03);

            pic.ComputePicHash();
            testData.Pictures.Add(pic);

            pic = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.png"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_ANY, 0x02);
            pic.ComputePicHash();
            testData.Pictures.Add(pic);
        }
Exemplo n.º 13
0
        protected void test_RW_Existing(string fileName, int initialNbPictures, bool deleteTempFile = true, bool sameSizeAfterEdit = false, bool sameBitsAfterEdit = false)
        {
            ConsoleLogger log = new ConsoleLogger();

            // Source : file with existing tag incl. unsupported picture (Conductor); unsupported field (MOOD)
            string           location         = TestUtils.GetResourceLocationRoot() + fileName;
            string           testFileLocation = TestUtils.CopyAsTempTestFile(fileName);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Add a new supported field and a new supported picture
            Assert.IsTrue(theFile.ReadFromFile());

            TagData theTag = new TagData();

            char internationalChar = supportsInternationalChars ? '父' : '!';

            TagData initialTestData = new TagData(testData);

            // These two cases cover all tag capabilities
            if (testData.Title != null)
            {
                theTag.Title = "Test !!" + internationalChar;
            }
            else if (testData.GeneralDescription != null)
            {
                theTag.GeneralDescription = "Description" + internationalChar;
            }

            if (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0)
            {
                theTag.AdditionalFields = new List <MetaFieldInfo>();
                foreach (MetaFieldInfo info in testData.AdditionalFields)
                {
                    theTag.AdditionalFields.Add(info);
                    break; // 1 is enough
                }
            }
            testData = new TagData(theTag);

            PictureInfo picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"), PictureInfo.PIC_TYPE.CD);

            theTag.Pictures.Add(picInfo);


            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType));

            readExistingTagsOnFile(theFile, initialNbPictures + 1);
            Assert.IsNotNull(theFile.getMeta(tagType));
            IMetaDataIO meta = theFile.getMeta(tagType);

            Assert.IsTrue(meta.Exists);

            if (testData.Pictures != null && testData.Pictures.Count > 0)
            {
                int nbFound = 0;
                foreach (PictureInfo pic in meta.EmbeddedPictures)
                {
                    if (pic.PicType.Equals(PictureInfo.PIC_TYPE.CD))
                    {
                        if (tagType.Equals(MetaDataIOFactory.TAG_APE))
                        {
                            Assert.AreEqual("Cover Art (Media)", pic.NativePicCodeStr);
                        }
                        else // ID3v2 convention
                        {
                            Assert.AreEqual(0x06, pic.NativePicCode);
                        }
                        using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                        {
                            Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                            Assert.AreEqual(600, picture.Height);
                            Assert.AreEqual(900, picture.Width);
                        }
                        nbFound++;
                        break;
                    }
                }

                Assert.AreEqual(1, nbFound);
            }

            // Remove the additional supported field
            theTag   = new TagData(initialTestData);
            testData = new TagData(initialTestData);

            // Remove additional picture
            picInfo = new PictureInfo(PictureInfo.PIC_TYPE.CD);
            picInfo.MarkedForDeletion = true;
            theTag.Pictures.Add(picInfo);

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType));

            readExistingTagsOnFile(theFile, initialNbPictures);

            // Additional removed field
            Assert.AreEqual("", theFile.getMeta(tagType).Conductor);


            // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added)
            if (sameSizeAfterEdit || sameBitsAfterEdit)
            {
                FileInfo originalFileInfo = new FileInfo(location);
                FileInfo testFileInfo     = new FileInfo(testFileLocation);

                if (sameSizeAfterEdit)
                {
                    Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length);
                }

                if (sameBitsAfterEdit)
                {
                    string originalMD5 = TestUtils.GetFileMD5Hash(location);
                    string testMD5     = TestUtils.GetFileMD5Hash(testFileLocation);

                    Assert.AreEqual(originalMD5, testMD5);
                }
            }

            // Get rid of the working copy
            if (deleteTempFile)
            {
                File.Delete(testFileLocation);
            }
        }
Exemplo n.º 14
0
        // Reads large data chunks by streaming
        private void SetExtendedTagItem(Stream Source, int size, ReadTagParams readTagParams)
        {
            const int     KEY_BUFFER   = 20;
            StringBuilder tagIdBuilder = new StringBuilder();

            byte[] stringData  = new byte[KEY_BUFFER];
            int    equalsIndex = -1;

            while (-1 == equalsIndex)
            {
                Source.Read(stringData, 0, KEY_BUFFER);

                for (int i = 0; i < KEY_BUFFER; i++)
                {
                    if (stringData[i] == 0x3D) // '=' character
                    {
                        equalsIndex = i;
                        break;
                    }
                }

                tagIdBuilder.Append(Utils.Latin1Encoding.GetString(stringData, 0, (-1 == equalsIndex) ? KEY_BUFFER : equalsIndex));
            }
            Source.Seek(-(KEY_BUFFER - equalsIndex - 1), SeekOrigin.Current);

            string tagId = tagIdBuilder.ToString();

            if (tagId.Equals(PICTURE_METADATA_ID_NEW))
            {
                size = size - 1 - PICTURE_METADATA_ID_NEW.Length;
                // Make sure total size is a multiple of 4
                size = size - (size % 4);

                // Read the whole base64-encoded picture header _and_ binary data
                byte[] encodedData = new byte[size];
                Source.Read(encodedData, 0, size);

                // Gets rid of unwanted zeroes
                // 0x3D ('=' char) is the padding neutral character that has to replace zero, which is not part of base64 range
                for (int i = 0; i < encodedData.Length; i++)
                {
                    if (0 == encodedData[i])
                    {
                        encodedData[i] = 0x3D;
                    }
                }

                using (MemoryStream mem = new MemoryStream(Utils.DecodeFrom64(encodedData)))
                {
                    mem.Seek(0, SeekOrigin.Begin);
                    ReadPicture(mem, readTagParams);
                }
            }
            else if (tagId.Equals(PICTURE_METADATA_ID_OLD)) // Deprecated picture info
            {
                PictureInfo.PIC_TYPE picType = PictureInfo.PIC_TYPE.Generic;
                int picturePosition          = takePicturePosition(picType);

                addPictureToken(picType);

                if (readTagParams.ReadPictures)
                {
                    size = size - 1 - PICTURE_METADATA_ID_OLD.Length;
                    // Make sure total size is a multiple of 4
                    size = size - (size % 4);

                    byte[] encodedData = new byte[size];
                    Source.Read(encodedData, 0, size);

                    PictureInfo picInfo = PictureInfo.fromBinaryData(Utils.DecodeFrom64(encodedData), picType, getImplementedTagType(), 0, picturePosition);
                    tagData.Pictures.Add(picInfo);
                }
            }
        }
Exemplo n.º 15
0
        public void TagIO_RW_MP4_Unsupported_Empty()
        {
            // Source : tag-free M4A
            String           testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));


            // Check that it is indeed tag-free
            Assert.IsTrue(theFile.ReadFromFile());

            Assert.IsNotNull(theFile.NativeTag);
            Assert.IsFalse(theFile.NativeTag.Exists);


            // Add new unsupported fields
            TagData theTag = new TagData();

            theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST", "This is a test 父"));
            theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TES2", "This is another test 父"));

            // Add new unsupported pictures
            PictureInfo picInfo = PictureInfo.fromBinaryData(
                File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"),
                PIC_TYPE.Unsupported,
                MetaDataIOFactory.TAG_NATIVE,
                "1234");

            theTag.Pictures.Add(picInfo);
            picInfo = PictureInfo.fromBinaryData(
                File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg"),
                PIC_TYPE.Unsupported,
                MetaDataIOFactory.TAG_NATIVE,
                "5678");
            theTag.Pictures.Add(picInfo);


            theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE);

            Assert.IsTrue(theFile.ReadFromFile(true, true));

            Assert.IsNotNull(theFile.NativeTag);
            Assert.IsTrue(theFile.NativeTag.Exists);

            Assert.AreEqual(2, theFile.NativeTag.AdditionalFields.Count);

            Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST"));
            Assert.AreEqual("This is a test 父", theFile.NativeTag.AdditionalFields["TEST"]);

            Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TES2"));
            Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TES2"]);

            Assert.AreEqual(2, theFile.NativeTag.EmbeddedPictures.Count);
            byte found = 0;

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Generic) && (0 == found)) // No custom nor categorized picture type in MP4
                {
                    Image picture = Image.FromStream(new MemoryStream(pic.PictureData));
                    Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Assert.AreEqual(picture.Height, 600);
                    Assert.AreEqual(picture.Width, 900);
                    found++;
                }
                else if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Generic) && (1 == found))  // No custom nor categorized picture type in MP4
                {
                    Image picture = Image.FromStream(new MemoryStream(pic.PictureData));
                    Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Assert.AreEqual(picture.Height, 290);
                    Assert.AreEqual(picture.Width, 900);
                    found++;
                }
            }

            Assert.AreEqual(2, found);

            // Remove the additional unsupported field
            theTag = new TagData();
            MetaFieldInfo fieldInfo = new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST");

            fieldInfo.MarkedForDeletion = true;
            theTag.AdditionalFields.Add(fieldInfo);

            // Remove additional picture
            picInfo = new PictureInfo(PictureInfo.PIC_TYPE.Generic, 1);
            picInfo.MarkedForDeletion = true;
            theTag.Pictures.Add(picInfo);

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            Assert.IsTrue(theFile.ReadFromFile(true, true));

            Assert.IsNotNull(theFile.NativeTag);
            Assert.IsTrue(theFile.NativeTag.Exists);

            // Additional removed field
            Assert.AreEqual(1, theFile.NativeTag.AdditionalFields.Count);
            Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TES2"));
            Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TES2"]);

            // Pictures
            Assert.AreEqual(1, theFile.NativeTag.EmbeddedPictures.Count);

            found = 0;

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Generic) && (0 == found))
                {
                    Image picture = Image.FromStream(new MemoryStream(pic.PictureData));
                    Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Assert.AreEqual(picture.Height, 290);
                    Assert.AreEqual(picture.Width, 900);
                    found++;
                }
            }

            Assert.AreEqual(1, found);


            // Get rid of the working copy
            File.Delete(testFileLocation);
        }
Exemplo n.º 16
0
        private bool readFrames(BinaryReader source, TagInfo Tag, MetaDataIO.ReadTagParams readTagParams)
        {
            string frameName;
            string strValue;
            int    frameDataSize;
            long   valuePosition;
            int    frameFlags;

            source.BaseStream.Seek(Tag.FileSize - Tag.DataShift - Tag.Size, SeekOrigin.Begin);
            // Read all stored fields
            for (int iterator = 0; iterator < Tag.FrameCount; iterator++)
            {
                frameDataSize = source.ReadInt32();
                frameFlags    = source.ReadInt32();
                frameName     = StreamUtils.ReadNullTerminatedString(source, Utils.Latin1Encoding); // Slightly more permissive than what APE specs indicate in terms of allowed characters ("Space(0x20), Slash(0x2F), Digits(0x30...0x39), Letters(0x41...0x5A, 0x61...0x7A)")

                valuePosition = source.BaseStream.Position;

                if (frameDataSize < 0 || valuePosition + frameDataSize > Tag.FileSize)
                {
                    LogDelegator.GetLogDelegate()(Log.LV_ERROR, "Invalid value found while reading APEtag frame");
                    return(false);
                }

                if ((frameDataSize > 0) && (frameDataSize <= 1000))
                {
                    /*
                     * According to spec : "Items are not zero-terminated like in C / C++.
                     * If there's a zero character, multiple items are stored under the key and the items are separated by zero characters."
                     *
                     * => Values have to be splitted
                     */
                    strValue = Utils.StripEndingZeroChars(Encoding.UTF8.GetString(source.ReadBytes(frameDataSize)));
                    strValue = strValue.Replace('\0', Settings.InternalValueSeparator).Trim();
                    SetMetaField(frameName.Trim().ToUpper(), strValue, readTagParams.ReadAllMetaFrames);
                }
                else if (frameDataSize > 0 && !frameName.ToLower().Contains("lyrics")) // Size > 1000 => Probably an embedded picture
                {
                    int picturePosition;
                    PictureInfo.PIC_TYPE picType = decodeAPEPictureType(frameName);

                    if (picType.Equals(PictureInfo.PIC_TYPE.Unsupported))
                    {
                        addPictureToken(getImplementedTagType(), frameName);
                        picturePosition = takePicturePosition(getImplementedTagType(), frameName);
                    }
                    else
                    {
                        addPictureToken(picType);
                        picturePosition = takePicturePosition(picType);
                    }

                    if (readTagParams.ReadPictures)
                    {
                        // Description seems to be a null-terminated ANSI string containing
                        //    * The frame name
                        //    * A byte (0x2E)
                        //    * The picture type (3 characters; similar to the 2nd part of the mime-type)
                        string      description = StreamUtils.ReadNullTerminatedString(source, Utils.Latin1Encoding);
                        PictureInfo picInfo     = PictureInfo.fromBinaryData(source.BaseStream, frameDataSize - description.Length - 1, picType, getImplementedTagType(), frameName, picturePosition);
                        picInfo.Description = description;
                        tagData.Pictures.Add(picInfo);
                    }
                }
                source.BaseStream.Seek(valuePosition + frameDataSize, SeekOrigin.Begin);
            }

            return(true);
        }
Exemplo n.º 17
0
        public void TagIO_RW_WMA_Existing()
        {
            ConsoleLogger log = new ConsoleLogger();

            // Source : MP3 with existing tag incl. unsupported picture (Conductor); unsupported field (WM/Mood)
            string           location         = TestUtils.GetResourceLocationRoot() + notEmptyFile;
            string           testFileLocation = TestUtils.CopyAsTempTestFile(notEmptyFile);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Add a new supported field and a new supported picture
            Assert.IsTrue(theFile.ReadFromFile());

            TagData theTag = new TagData();

            theTag.Conductor = "John Jackman";

            PictureInfo picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"), PictureInfo.PIC_TYPE.Back);

            theTag.Pictures.Add(picInfo);


            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            readExistingTagsOnFile(theFile, 3);

            // Additional supported field
            Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor);

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Back))
                {
                    Assert.AreEqual(pic.NativePicCode, 0x04);
                    Image picture = Image.FromStream(new MemoryStream(pic.PictureData));
                    Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                    Assert.AreEqual(picture.Height, 600);
                    Assert.AreEqual(picture.Width, 900);
                    break;
                }
            }


            // Remove the additional supported field
            theTag           = new TagData();
            theTag.Conductor = "";

            // Remove additional picture
            picInfo = new PictureInfo(PictureInfo.PIC_TYPE.Back);
            picInfo.MarkedForDeletion = true;
            theTag.Pictures.Add(picInfo);

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            readExistingTagsOnFile(theFile);

            // Additional removed field
            Assert.AreEqual("", theFile.NativeTag.Conductor);


            // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added)

            /* Not possible yet due to zone order differences
             *          FileInfo originalFileInfo = new FileInfo(location);
             *          FileInfo testFileInfo = new FileInfo(testFileLocation);
             *
             *          Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length);
             *
             *          string originalMD5 = TestUtils.GetFileMD5Hash(location);
             *          string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation);
             *
             *          Assert.IsTrue(originalMD5.Equals(testMD5));
             */
            // Get rid of the working copy
            File.Delete(testFileLocation);
        }
Exemplo n.º 18
0
        public void TagIO_RW_MP4_Existing()
        {
            ConsoleLogger log = new ConsoleLogger();

            // Source : MP3 with existing tag incl. unsupported picture (Cover Art (Fronk)); unsupported field (MOOD)
            String           testFileLocation = TestUtils.CopyAsTempTestFile(notEmptyFile);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Add a new supported field and a new supported picture
            Assert.IsTrue(theFile.ReadFromFile());

            TagData theTag = new TagData();

            theTag.Conductor = "John Jackman";

            byte[]      data    = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.png");
            PictureInfo picInfo = PictureInfo.fromBinaryData(data, PictureInfo.PIC_TYPE.Generic, MetaDataIOFactory.TAG_ANY, 14);

            theTag.Pictures.Add(picInfo);


            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            readExistingTagsOnFile(theFile, 2);

            // Additional supported field
            Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor);

            byte nbFound = 0;

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Generic) && (1 == nbFound))
                {
                    Image picture = Image.FromStream(new MemoryStream(pic.PictureData));
                    Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Png);
                    Assert.AreEqual(picture.Width, 175);
                    Assert.AreEqual(picture.Height, 168);
                }
                nbFound++;
            }

            Assert.AreEqual(2, nbFound);

            // Remove the additional supported field
            theTag           = new TagData();
            theTag.Conductor = "";

            // Remove additional picture
            picInfo = new PictureInfo(PictureInfo.PIC_TYPE.Back);
            picInfo.MarkedForDeletion = true;
            theTag.Pictures.Add(picInfo);

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            readExistingTagsOnFile(theFile);

            // Additional removed field
            Assert.AreEqual("", theFile.NativeTag.Conductor);


            // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added)

            /* NOT POSSIBLE YET mainly due to tag order and tag naming (e.g. "gnre" becoming "©gen") differences
             *          FileInfo originalFileInfo = new FileInfo(location);
             *          FileInfo testFileInfo = new FileInfo(testFileLocation);
             *
             *          Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length);
             *
             *          string originalMD5 = TestUtils.GetFileMD5Hash(location);
             *          string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation);
             *
             *          Assert.IsTrue(originalMD5.Equals(testMD5));
             */
            // Get rid of the working copy
            File.Delete(testFileLocation);
        }
Exemplo n.º 19
0
        public void TagIO_RW_VorbisFLAC_Unsupported_Empty()
        {
            // Source : tag-free file
            string           testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));


            // Check that it is indeed tag-free
            Assert.IsTrue(theFile.ReadFromFile());

            Assert.IsNotNull(theFile.NativeTag);
            Assert.IsFalse(theFile.NativeTag.Exists);


            // Add new unsupported fields
            TagData theTag = new TagData();

            theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST", "This is a test 父"));
            theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST2", "This is another test 父"));

            // Add new unsupported pictures
            PictureInfo picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_NATIVE, 0x0A);

            theTag.Pictures.Add(picInfo);
            picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg"), PIC_TYPE.Unsupported, MetaDataIOFactory.TAG_NATIVE, 0x0B);
            theTag.Pictures.Add(picInfo);


            theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE);

            Assert.IsTrue(theFile.ReadFromFile(true, true));

            Assert.IsNotNull(theFile.NativeTag);
            Assert.IsTrue(theFile.NativeTag.Exists);

            Assert.AreEqual(3, theFile.NativeTag.AdditionalFields.Count); // 3 instead of 2 because of the VENDOR field... (specific to VorbisTag)

            Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST"));
            Assert.AreEqual("This is a test 父", theFile.NativeTag.AdditionalFields["TEST"]);

            Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST2"));
            Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TEST2"]);

            Assert.AreEqual(2, theFile.NativeTag.EmbeddedPictures.Count);
            byte found = 0;

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && pic.NativePicCode.Equals(0x0A))
                {
                    using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                    {
                        Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Assert.AreEqual(600, picture.Height);
                        Assert.AreEqual(900, picture.Width);
                    }
                    found++;
                }
                else if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && pic.NativePicCode.Equals(0x0B))
                {
                    using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                    {
                        Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Assert.AreEqual(290, picture.Height);
                        Assert.AreEqual(900, picture.Width);
                    }
                    found++;
                }
            }

            Assert.AreEqual(2, found);

            // Remove the additional unsupported field
            theTag = new TagData();
            MetaFieldInfo fieldInfo = new MetaFieldInfo(MetaDataIOFactory.TAG_NATIVE, "TEST");

            fieldInfo.MarkedForDeletion = true;
            theTag.AdditionalFields.Add(fieldInfo);

            // Remove additional picture
            picInfo = new PictureInfo(MetaDataIOFactory.TAG_NATIVE, 0x0A);
            picInfo.MarkedForDeletion = true;
            theTag.Pictures.Add(picInfo);

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            Assert.IsTrue(theFile.ReadFromFile(true, true));

            Assert.IsNotNull(theFile.NativeTag);
            Assert.IsTrue(theFile.NativeTag.Exists);

            // Additional removed field
            Assert.AreEqual(2, theFile.NativeTag.AdditionalFields.Count); // 2 instead of 1 because of the VENDOR field...
            Assert.IsTrue(theFile.NativeTag.AdditionalFields.Keys.Contains("TEST2"));
            Assert.AreEqual("This is another test 父", theFile.NativeTag.AdditionalFields["TEST2"]);

            // Pictures
            Assert.AreEqual(1, theFile.NativeTag.EmbeddedPictures.Count);

            found = 0;

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) && pic.NativePicCode.Equals(0x0B))
                {
                    using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                    {
                        Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                        Assert.AreEqual(290, picture.Height);
                        Assert.AreEqual(900, picture.Width);
                    }
                    found++;
                }
            }

            Assert.AreEqual(1, found);


            // Get rid of the working copy
            if (Settings.DeleteAfterSuccess)
            {
                File.Delete(testFileLocation);
            }
        }
Exemplo n.º 20
0
        public void TagIO_RW_AddRemoveChapters()
        {
            string testFileLocation = TestUtils.CopyAsTempTestFile("MP3/chapters.mp3");
            Track  theTrack         = new Track(testFileLocation);

            theTrack.ChaptersTableDescription = "Content";
            theTrack.Chapters.RemoveAt(2);

            // Add new chapter
            ChapterInfo chapter = new ChapterInfo();

            chapter.StartTime   = 440;
            chapter.StartOffset = 4400;
            chapter.EndTime     = 880;
            chapter.EndOffset   = 8800;
            chapter.UniqueID    = "849849";
            chapter.Picture     = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpeg"));
            theTrack.Chapters.Add(chapter);


            IList <ChapterInfo> chaptersSave = new List <ChapterInfo>(theTrack.Chapters);

            chaptersSave = chaptersSave.OrderBy(chap => chap.StartTime).ToList();

            theTrack.Save();

            theTrack = new Track(testFileLocation);
            IList <PictureInfo> pics = theTrack.EmbeddedPictures; // Hack to load chapter pictures

            Assert.AreEqual("Content", theTrack.ChaptersTableDescription);
            Assert.AreEqual(chaptersSave.Count, theTrack.Chapters.Count);

            ChapterInfo readChapter;

            for (int i = 0; i < theTrack.Chapters.Count; i++)
            {
                readChapter = theTrack.Chapters[i];
                Assert.AreEqual(chaptersSave[i].StartOffset, readChapter.StartOffset);
                Assert.AreEqual(chaptersSave[i].StartTime, readChapter.StartTime);
                Assert.AreEqual(chaptersSave[i].EndOffset, readChapter.EndOffset);
                Assert.AreEqual(chaptersSave[i].EndTime, readChapter.EndTime);
                Assert.AreEqual(chaptersSave[i].Title, readChapter.Title);
                Assert.AreEqual(chaptersSave[i].Subtitle, readChapter.Subtitle);
                Assert.AreEqual(chaptersSave[i].UniqueID, readChapter.UniqueID);
                if (chaptersSave[i].Url != null)
                {
                    Assert.AreEqual(chaptersSave[i].Url.Description, readChapter.Url.Description);
                    Assert.AreEqual(chaptersSave[i].Url.Url, readChapter.Url.Url);
                }
                if (chaptersSave[i].Picture != null)
                {
                    Assert.IsNotNull(readChapter.Picture);
                    Assert.AreEqual(chaptersSave[i].Picture.ComputePicHash(), readChapter.Picture.ComputePicHash());
                }
            }

            // Delete all
            theTrack.Chapters.Clear();
            theTrack.Save();
            theTrack = new Track(testFileLocation);
            Assert.AreEqual(0, theTrack.Chapters.Count);

            // Get rid of the working copy
            if (Settings.DeleteAfterSuccess)
            {
                File.Delete(testFileLocation);
            }
        }
Exemplo n.º 21
0
        private void tagIO_RW_VorbisFLAC_Existing(string fileName, int initialNbPictures, bool deleteTempFile = true)
        {
            ATL.Settings.AddNewPadding = true;
            ATL.Settings.PaddingSize   = 4063; // Default padding of the sample FLAC file

            try
            {
                ConsoleLogger log = new ConsoleLogger();

                // Source : file with existing tag incl. unsupported picture (Conductor); unsupported field (MOOD)
                string           location         = TestUtils.GetResourceLocationRoot() + fileName;
                string           testFileLocation = TestUtils.CopyAsTempTestFile(fileName);
                AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

                // Add a new supported field and a new supported picture
                Assert.IsTrue(theFile.ReadFromFile());

                TagData theTag = new TagData();
                theTag.Conductor = "John Jackman";

                PictureInfo picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"), PictureInfo.PIC_TYPE.CD);
                theTag.Pictures.Add(picInfo);


                // Add the new tag and check that it has been indeed added with all the correct information
                Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

                readExistingTagsOnFile(theFile, initialNbPictures + 1);

                // Additional supported field
                Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor);

                int nbFound = 0;
                foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
                {
                    if (pic.PicType.Equals(PictureInfo.PIC_TYPE.CD))
                    {
                        Assert.AreEqual(0x06, pic.NativePicCode);
                        using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                        {
                            Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                            Assert.AreEqual(600, picture.Height);
                            Assert.AreEqual(900, picture.Width);
                        }
                        nbFound++;
                        break;
                    }
                }

                Assert.AreEqual(1, nbFound);

                // Remove the additional supported field
                theTag           = new TagData();
                theTag.Conductor = "";

                // Remove additional picture
                picInfo = new PictureInfo(PictureInfo.PIC_TYPE.CD);
                picInfo.MarkedForDeletion = true;
                theTag.Pictures.Add(picInfo);

                // Add the new tag and check that it has been indeed added with all the correct information
                Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

                readExistingTagsOnFile(theFile, initialNbPictures);

                // Additional removed field
                Assert.AreEqual("", theFile.NativeTag.Conductor);


                // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added)
                FileInfo originalFileInfo = new FileInfo(location);
                FileInfo testFileInfo     = new FileInfo(testFileLocation);

                Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length);

                /*
                 * Not possible yet due to field order differences
                 *
                 * string originalMD5 = TestUtils.GetFileMD5Hash(location);
                 * string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation);
                 *
                 * Assert.IsTrue(originalMD5.Equals(testMD5));
                 */

                // Get rid of the working copy
                if (deleteTempFile && Settings.DeleteAfterSuccess)
                {
                    File.Delete(testFileLocation);
                }
            }
            finally
            {
                ATL.Settings.AddNewPadding = false;
                ATL.Settings.PaddingSize   = 2048;
            }
        }
Exemplo n.º 22
0
        public void TagIO_RW_ID3v24_Extended()
        {
            ArrayLogger logger = new ArrayLogger();

            // Source : MP3 with extended tag properties (tag restrictions)
            string           testFileLocation = TestUtils.CopyAsTempTestFile("MP3/id3v2.4_UTF8_extendedTag.mp3");
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Check that the presence of an extended tag does not disrupt field reading
            readExistingTagsOnFile(theFile);

            Settings.ID3v2_useExtendedHeaderRestrictions = true;

            try
            {
                // Insert a very long field while tag restrictions specify that string shouldn't be longer than 30 characters
                TagData theTag = new TagData();
                theTag.Conductor = "Veeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeery long field";

                // Insert a large picture while tag restrictions specify that pictures shouldn't be larger than 64x64pixels AND tag size shouldn't be larger than 4 KB
                PictureInfo picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg"), PictureInfo.PIC_TYPE.Back);
                theTag.Pictures.Add(picInfo);

                // Insert a gif picture while tag restrictions specify that pictures should be either jpeg or png
                picInfo = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.gif"), PictureInfo.PIC_TYPE.Back);
                theTag.Pictures.Add(picInfo);

                // Insert 20 garbage fields to raise the number of field above maximum required fields (30)
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA01", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA02", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA03", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA04", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA05", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA06", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA07", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA08", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA09", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA10", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA11", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA12", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA13", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA14", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA15", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA16", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA17", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA18", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA19", "aaa"));
                theTag.AdditionalFields.Add(new MetaFieldInfo(MetaDataIOFactory.TAG_ID3V2, "GA20", "aaa"));


                // Add the new tag and check that it has been indeed added with all the correct information
                Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_ID3V2));

                // Get rid of the working copy
                File.Delete(testFileLocation);
            }
            finally
            {
                Settings.ID3v2_useExtendedHeaderRestrictions = false;
            }

            bool isAlertFieldLength  = false;
            bool isAlertTagSize      = false;
            bool isAlertNbFrames     = false;
            bool isAlertPicDimension = false;
            bool isAlertPicType      = false;

            foreach (Logging.Log.LogItem logItem in logger.Items)
            {
                if (logItem.Message.Contains("is longer than authorized"))
                {
                    isAlertFieldLength = true;
                }
                if (logItem.Message.StartsWith("Tag is too large"))
                {
                    isAlertTagSize = true;
                }
                if (logItem.Message.StartsWith("Tag has too many frames"))
                {
                    isAlertNbFrames = true;
                }
                if (logItem.Message.EndsWith("does not respect ID3v2 restrictions (exactly 64x64)"))
                {
                    isAlertPicDimension = true;
                }
                if (logItem.Message.EndsWith("does not respect ID3v2 restrictions (jpeg or png required)"))
                {
                    isAlertPicType = true;
                }
            }

            Assert.IsTrue(isAlertFieldLength);
            Assert.IsTrue(isAlertTagSize);
            Assert.IsTrue(isAlertNbFrames);
            Assert.IsTrue(isAlertPicDimension);
            Assert.IsTrue(isAlertPicType);
        }
Exemplo n.º 23
0
        private void TagIO_RW_ID3v2_Chapters()
        {
            ConsoleLogger log = new ConsoleLogger();

            // Source : empty MP3
            String           testFileLocation = TestUtils.CopyAsTempTestFile(emptyFile);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            Assert.IsTrue(theFile.ReadFromFile(true, true));
            Assert.IsNotNull(theFile.ID3v2);
            Assert.IsFalse(theFile.ID3v2.Exists);

            Dictionary <uint, ChapterInfo> expectedChaps = new Dictionary <uint, ChapterInfo>();

            TagData theTag = new TagData();

            theTag.ChaptersTableDescription = "Content֍";
            theTag.Chapters = new List <ChapterInfo>();
            ChapterInfo ch = new ChapterInfo();

            ch.StartTime   = 123;
            ch.StartOffset = 456;
            ch.EndTime     = 789;
            ch.EndOffset   = 101112;
            ch.UniqueID    = "";
            ch.Title       = "aaa";
            ch.Subtitle    = "bbb";
            ch.Url         = new ChapterInfo.UrlInfo("ccc", "ddd");
            ch.Picture     = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpeg"));
            ch.Picture.ComputePicHash();

            theTag.Chapters.Add(ch);
            expectedChaps.Add(ch.StartTime, ch);

            ch             = new ChapterInfo();
            ch.StartTime   = 1230;
            ch.StartOffset = 4560;
            ch.EndTime     = 7890;
            ch.EndOffset   = 1011120;
            ch.UniqueID    = "002";
            ch.Title       = "aaa0";
            ch.Subtitle    = "bbb0";
            ch.Url         = new ChapterInfo.UrlInfo("ccc", "ddd0");

            theTag.Chapters.Add(ch);
            expectedChaps.Add(ch.StartTime, ch);

            // Check if they are persisted properly
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_ID3V2));

            Assert.IsTrue(theFile.ReadFromFile(true, true));
            Assert.IsNotNull(theFile.ID3v2);
            Assert.IsTrue(theFile.ID3v2.Exists);

            Assert.AreEqual("Content֍", theFile.ID3v2.ChaptersTableDescription);
            Assert.AreEqual(2, theFile.ID3v2.Chapters.Count);

            // Check if values are the same
            int found = 0;

            foreach (ChapterInfo chap in theFile.ID3v2.Chapters)
            {
                if (expectedChaps.ContainsKey(chap.StartTime))
                {
                    found++;
                    if (1 == found)
                    {
                        Assert.AreNotEqual(chap.UniqueID, expectedChaps[chap.StartTime].UniqueID);             // ID of first chapter was empty; ATL has generated a random ID for it
                    }
                    else
                    {
                        Assert.AreEqual(chap.UniqueID, expectedChaps[chap.StartTime].UniqueID);
                    }
                    Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime);
                    Assert.AreEqual(chap.EndTime, expectedChaps[chap.StartTime].EndTime);
                    Assert.AreEqual(chap.StartOffset, expectedChaps[chap.StartTime].StartOffset);
                    Assert.AreEqual(chap.EndOffset, expectedChaps[chap.StartTime].EndOffset);
                    Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title);
                    Assert.AreEqual(chap.Subtitle, expectedChaps[chap.StartTime].Subtitle);
                    if (expectedChaps[chap.StartTime].Url != null)
                    {
                        Assert.AreEqual(chap.Url.Url, expectedChaps[chap.StartTime].Url.Url);
                        Assert.AreEqual(chap.Url.Description, expectedChaps[chap.StartTime].Url.Description);
                    }
                    if (expectedChaps[chap.StartTime].Picture != null)
                    {
                        Assert.IsNotNull(chap.Picture);
                        Assert.AreEqual(expectedChaps[chap.StartTime].Picture.PictureHash, chap.Picture.ComputePicHash());
                    }
                }
                else
                {
                    System.Console.WriteLine(chap.StartTime);
                }
            }
            Assert.AreEqual(2, found);

            // Get rid of the working copy
            File.Delete(testFileLocation);
        }
Exemplo n.º 24
0
        public void TagIO_RW_ID3v2_Chapters_Existing()
        {
            ConsoleLogger log = new ConsoleLogger();

            // Source : MP3 with existing tag incl. chapters
            String           testFileLocation = TestUtils.CopyAsTempTestFile("MP3/chapters.mp3");
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Check if the two fields are indeed accessible
            Assert.IsTrue(theFile.ReadFromFile(true, true));
            Assert.IsNotNull(theFile.ID3v2);
            Assert.IsTrue(theFile.ID3v2.Exists);

            Assert.AreEqual("toplevel toc", theFile.ID3v2.ChaptersTableDescription);
            Assert.AreEqual(9, theFile.ID3v2.Chapters.Count);

            Dictionary <uint, ChapterInfo> expectedChaps = new Dictionary <uint, ChapterInfo>();

            ChapterInfo ch = new ChapterInfo();

            ch.StartTime = 0;
            ch.Title     = "Intro";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "https://auphonic.com/");
            ch.Picture   = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "MP3/chapterImage1.jpg"));
            ch.Picture.ComputePicHash();
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 15000;
            ch.Title     = "Creating a new production";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "https://auphonic.com/engine/upload/");
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 22000;
            ch.Title     = "Sound analysis";
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 34000;
            ch.Title     = "Adaptive leveler";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "https://auphonic.com/audio_examples%23leveler");
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 45000;
            ch.Title     = "Global loudness normalization";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "https://auphonic.com/audio_examples%23loudnorm");
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 60000;
            ch.Title     = "Audio restoration algorithms";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "https://auphonic.com/audio_examples%23denoise");
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 76000;
            ch.Title     = "Output file formats";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "http://auphonic.com/blog/5/");
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 94000;
            ch.Title     = "External services";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "http://auphonic.com/blog/16/");
            expectedChaps.Add(ch.StartTime, ch);

            ch           = new ChapterInfo();
            ch.StartTime = 111500;
            ch.Title     = "Get a free account!";
            ch.Url       = new ChapterInfo.UrlInfo("chapter url", "https://auphonic.com/accounts/register");
            expectedChaps.Add(ch.StartTime, ch);

            int found = 0;

            foreach (ChapterInfo chap in theFile.ID3v2.Chapters)
            {
                if (expectedChaps.ContainsKey(chap.StartTime))
                {
                    found++;
                    Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime);
                    Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title);
                    if (expectedChaps[chap.StartTime].Url != null)
                    {
                        Assert.AreEqual(chap.Url.Url, expectedChaps[chap.StartTime].Url.Url);
                        Assert.AreEqual(chap.Url.Description, expectedChaps[chap.StartTime].Url.Description);
                    }
                    if (expectedChaps[chap.StartTime].Picture != null)
                    {
                        Assert.IsNotNull(chap.Picture);
                        Assert.AreEqual(expectedChaps[chap.StartTime].Picture.PictureHash, chap.Picture.ComputePicHash());
                    }
                }
                else
                {
                    System.Console.WriteLine(chap.StartTime);
                }
            }
            Assert.AreEqual(9, found);


            // Modify elements
            TagData theTag = new TagData();

            theTag.ChaptersTableDescription = "Content֍";
            theTag.Chapters = new List <ChapterInfo>();
            expectedChaps.Clear();

            ch             = new ChapterInfo();
            ch.StartTime   = 123;
            ch.StartOffset = 456;
            ch.EndTime     = 789;
            ch.EndOffset   = 101112;
            ch.UniqueID    = "";
            ch.Title       = "aaa";
            ch.Subtitle    = "bbb";
            ch.Url         = new ChapterInfo.UrlInfo("ccc", "ddd");
            ch.Picture     = PictureInfo.fromBinaryData(File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpeg"));
            ch.Picture.ComputePicHash();

            theTag.Chapters.Add(ch);
            expectedChaps.Add(ch.StartTime, ch);

            ch             = new ChapterInfo();
            ch.StartTime   = 1230;
            ch.StartOffset = 4560;
            ch.EndTime     = 7890;
            ch.EndOffset   = 1011120;
            ch.UniqueID    = "002";
            ch.Title       = "aaa0";
            ch.Subtitle    = "bbb0";
            ch.Url         = new ChapterInfo.UrlInfo("ccc", "ddd0");

            theTag.Chapters.Add(ch);
            expectedChaps.Add(ch.StartTime, ch);

            // Check if they are persisted properly
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_ID3V2));

            Assert.IsTrue(theFile.ReadFromFile(true, true));
            Assert.IsNotNull(theFile.ID3v2);
            Assert.IsTrue(theFile.ID3v2.Exists);

            Assert.AreEqual("Content֍", theFile.ID3v2.ChaptersTableDescription);
            Assert.AreEqual(2, theFile.ID3v2.Chapters.Count);

            // Check if values are the same
            found = 0;
            foreach (ChapterInfo chap in theFile.ID3v2.Chapters)
            {
                if (expectedChaps.ContainsKey(chap.StartTime))
                {
                    found++;
                    if (1 == found)
                    {
                        Assert.AreNotEqual(chap.UniqueID, expectedChaps[chap.StartTime].UniqueID);             // ID of first chapter was empty; ATL has generated a random ID for it
                    }
                    else
                    {
                        Assert.AreEqual(chap.UniqueID, expectedChaps[chap.StartTime].UniqueID);
                    }
                    Assert.AreEqual(chap.StartTime, expectedChaps[chap.StartTime].StartTime);
                    Assert.AreEqual(chap.EndTime, expectedChaps[chap.StartTime].EndTime);
                    Assert.AreEqual(chap.StartOffset, expectedChaps[chap.StartTime].StartOffset);
                    Assert.AreEqual(chap.EndOffset, expectedChaps[chap.StartTime].EndOffset);
                    Assert.AreEqual(chap.Title, expectedChaps[chap.StartTime].Title);
                    Assert.AreEqual(chap.Subtitle, expectedChaps[chap.StartTime].Subtitle);
                    if (expectedChaps[chap.StartTime].Url != null)
                    {
                        Assert.AreEqual(expectedChaps[chap.StartTime].Url.Url, chap.Url.Url);
                        Assert.AreEqual(expectedChaps[chap.StartTime].Url.Description, chap.Url.Description);
                    }
                    if (expectedChaps[chap.StartTime].Picture != null)
                    {
                        Assert.IsNotNull(chap.Picture);
                        Assert.AreEqual(expectedChaps[chap.StartTime].Picture.PictureHash, chap.Picture.ComputePicHash());
                    }
                }
                else
                {
                    System.Console.WriteLine(chap.StartTime);
                }
            }
            Assert.AreEqual(2, found);

            // Get rid of the working copy
            File.Delete(testFileLocation);
        }
Exemplo n.º 25
0
        public void test_RW_Unsupported_Empty(string fileName, bool deleteTempFile = true)
        {
            ConsoleLogger log = new ConsoleLogger();

            // Source : totally metadata-free file
            string           location         = TestUtils.GetResourceLocationRoot() + fileName;
            string           testFileLocation = TestUtils.CopyAsTempTestFile(fileName);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Check that it is indeed tag-free
            Assert.IsTrue(theFile.ReadFromFile());

            Assert.IsNotNull(theFile.getMeta(tagType));
            IMetaDataIO meta = theFile.getMeta(tagType);

            if (canMetaNotExist)
            {
                Assert.IsFalse(meta.Exists);
            }


            bool handleUnsupportedFields   = (testData.AdditionalFields != null && testData.AdditionalFields.Count > 0);
            bool handleUnsupportedPictures = (testData.Pictures != null && testData.Pictures.Count > 0);
            char internationalChar         = supportsInternationalChars ? '父' : '!';

            // Add new unsupported fields
            TagData theTag = new TagData();

            if (handleUnsupportedFields)
            {
                theTag.AdditionalFields.Add(new MetaFieldInfo(tagType, "TEST", "This is a test " + internationalChar));
                theTag.AdditionalFields.Add(new MetaFieldInfo(tagType, "TES2", "This is another test " + internationalChar));
            }

            // Add new unsupported pictures
            PictureInfo picInfo = null;
            byte        found   = 0;

            object pictureCode1, pictureCode2;

            if (tagType.Equals(MetaDataIOFactory.TAG_APE))
            {
                pictureCode1 = "pic1";
                pictureCode2 = "pic2";
            }
            else
            {
                pictureCode1 = 23;
                pictureCode2 = 24;
            }

            if (handleUnsupportedPictures)
            {
                byte[] data = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.jpg");
                picInfo = PictureInfo.fromBinaryData(data, PIC_TYPE.Unsupported, tagType, pictureCode1);
                theTag.Pictures.Add(picInfo);

                data    = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic2.jpg");
                picInfo = PictureInfo.fromBinaryData(data, PIC_TYPE.Unsupported, tagType, pictureCode2);
                theTag.Pictures.Add(picInfo);
            }

            theFile.UpdateTagInFile(theTag, tagType);

            Assert.IsTrue(theFile.ReadFromFile(true, true));

            Assert.IsNotNull(theFile.getMeta(tagType));
            meta = theFile.getMeta(tagType);
            Assert.IsTrue(meta.Exists);

            if (handleUnsupportedFields)
            {
                Assert.AreEqual(2, meta.AdditionalFields.Count);

                Assert.IsTrue(meta.AdditionalFields.Keys.Contains("TEST"));
                Assert.AreEqual("This is a test " + internationalChar, meta.AdditionalFields["TEST"]);

                Assert.IsTrue(meta.AdditionalFields.Keys.Contains("TES2"));
                Assert.AreEqual("This is another test " + internationalChar, meta.AdditionalFields["TES2"]);
            }

            if (handleUnsupportedPictures)
            {
                Assert.AreEqual(2, meta.EmbeddedPictures.Count);
                found = 0;

                foreach (PictureInfo pic in meta.EmbeddedPictures)
                {
                    if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) &&
                        (pic.NativePicCode.Equals(pictureCode1) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(pictureCode1)))
                        )
                    {
                        using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                        {
                            Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                            Assert.AreEqual(600, picture.Height);
                            Assert.AreEqual(900, picture.Width);
                        }
                        found++;
                    }
                    else if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) &&
                             (pic.NativePicCode.Equals(pictureCode2) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(pictureCode2)))
                             )
                    {
                        using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                        {
                            Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                            Assert.AreEqual(290, picture.Height);
                            Assert.AreEqual(900, picture.Width);
                        }
                        found++;
                    }
                }

                Assert.AreEqual(2, found);
            }

            // Remove the additional unsupported field
            if (handleUnsupportedFields)
            {
                theTag = new TagData();
                MetaFieldInfo fieldInfo = new MetaFieldInfo(tagType, "TEST");
                fieldInfo.MarkedForDeletion = true;
                theTag.AdditionalFields.Add(fieldInfo);
            }

            // Remove additional picture
            if (handleUnsupportedPictures)
            {
                picInfo = new PictureInfo(tagType, pictureCode1);
                picInfo.MarkedForDeletion = true;
                theTag.Pictures.Add(picInfo);
            }

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, tagType));

            Assert.IsTrue(theFile.ReadFromFile(true, true));

            Assert.IsNotNull(theFile.getMeta(tagType));
            meta = theFile.getMeta(tagType);
            Assert.IsTrue(meta.Exists);

            if (handleUnsupportedFields)
            {
                // Additional removed field
                Assert.AreEqual(1, meta.AdditionalFields.Count);
                Assert.IsTrue(meta.AdditionalFields.Keys.Contains("TES2"));
                Assert.AreEqual("This is another test " + internationalChar, meta.AdditionalFields["TES2"]);
            }

            // Pictures
            if (handleUnsupportedPictures)
            {
                Assert.AreEqual(1, meta.EmbeddedPictures.Count);

                found = 0;

                foreach (PictureInfo pic in meta.EmbeddedPictures)
                {
                    if (pic.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) &&
                        (pic.NativePicCode.Equals(pictureCode2) || (pic.NativePicCodeStr != null && pic.NativePicCodeStr.Equals(pictureCode2)))
                        )
                    {
                        using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                        {
                            Assert.AreEqual(picture.RawFormat, System.Drawing.Imaging.ImageFormat.Jpeg);
                            Assert.AreEqual(290, picture.Height);
                            Assert.AreEqual(900, picture.Width);
                        }
                        found++;
                    }
                }

                Assert.AreEqual(1, found);
            }

            // Get rid of the working copy
            if (deleteTempFile)
            {
                File.Delete(testFileLocation);
            }
        }
Exemplo n.º 26
0
        public void readTagField(BinaryReader source, string zoneCode, string fieldName, ushort fieldDataType, int fieldDataSize, ReadTagParams readTagParams, bool isExtendedHeader = false, ushort languageIndex = 0, ushort streamNumber = 0)
        {
            string fieldValue = "";
            bool   setMeta    = true;

            addFrameClass(fieldName, fieldDataType);

            if (0 == fieldDataType) // Unicode string
            {
                fieldValue = Utils.StripEndingZeroChars(Encoding.Unicode.GetString(source.ReadBytes(fieldDataSize)));
            }
            else if (1 == fieldDataType) // Byte array
            {
                if (fieldName.ToUpper().Equals("WM/PICTURE"))
                {
                    byte picCode = source.ReadByte();
                    // TODO factorize : abstract PictureTypeDecoder + unsupported / supported decision in MetaDataIO ?
                    PictureInfo.PIC_TYPE picType = ID3v2.DecodeID3v2PictureType(picCode);

                    int picturePosition;
                    if (picType.Equals(PictureInfo.PIC_TYPE.Unsupported))
                    {
                        addPictureToken(MetaDataIOFactory.TAG_NATIVE, picCode);
                        picturePosition = takePicturePosition(MetaDataIOFactory.TAG_NATIVE, picCode);
                    }
                    else
                    {
                        addPictureToken(picType);
                        picturePosition = takePicturePosition(picType);
                    }

                    if (readTagParams.ReadPictures)
                    {
                        int    picSize     = source.ReadInt32();
                        string mimeType    = StreamUtils.ReadNullTerminatedString(source, Encoding.Unicode);
                        string description = StreamUtils.ReadNullTerminatedString(source, Encoding.Unicode);

                        PictureInfo picInfo = PictureInfo.fromBinaryData(source.BaseStream, picSize, picType, getImplementedTagType(), picCode, picturePosition);
                        picInfo.Description = description;

                        tagData.Pictures.Add(picInfo);
                    }
                    setMeta = false;
                }
                else
                {
                    source.BaseStream.Seek(fieldDataSize, SeekOrigin.Current);
                }
            }
            else if (2 == fieldDataType) // 16-bit Boolean (metadata); 32-bit Boolean (extended header)
            {
                if (isExtendedHeader)
                {
                    fieldValue = source.ReadUInt32().ToString();
                }
                else
                {
                    fieldValue = source.ReadUInt16().ToString();
                }
            }
            else if (3 == fieldDataType) // 32-bit unsigned integer
            {
                uint intValue = source.ReadUInt32();
                if (fieldName.Equals("WM/GENRE", StringComparison.OrdinalIgnoreCase))
                {
                    intValue++;
                }
                fieldValue = intValue.ToString();
            }
            else if (4 == fieldDataType) // 64-bit unsigned integer
            {
                fieldValue = source.ReadUInt64().ToString();
            }
            else if (5 == fieldDataType) // 16-bit unsigned integer
            {
                fieldValue = source.ReadUInt16().ToString();
            }
            else if (6 == fieldDataType) // 128-bit GUID; unused for now
            {
                source.BaseStream.Seek(fieldDataSize, SeekOrigin.Current);
            }

            if (setMeta)
            {
                SetMetaField(fieldName.Trim(), fieldValue, readTagParams.ReadAllMetaFrames, zoneCode, 0, streamNumber, decodeLanguage(source.BaseStream, languageIndex));
            }
        }
Exemplo n.º 27
0
        public void TagIO_RW_MP4_Existing()
        {
            new ConsoleLogger();

            // Source : MP3 with existing tag incl. unsupported picture (Cover Art (Fronk)); unsupported field (MOOD)
            String           testFileLocation = TestUtils.CopyAsTempTestFile(notEmptyFile);
            AudioDataManager theFile          = new AudioDataManager(ATL.AudioData.AudioDataIOFactory.GetInstance().GetFromPath(testFileLocation));

            // Add a new supported field and a new supported picture
            Assert.IsTrue(theFile.ReadFromFile());

            TagData theTag = new TagData();

            theTag.Conductor = "John Jackman";

            byte[]      data    = File.ReadAllBytes(TestUtils.GetResourceLocationRoot() + "_Images/pic1.png");
            PictureInfo picInfo = PictureInfo.fromBinaryData(data, PictureInfo.PIC_TYPE.Generic, MetaDataIOFactory.TAG_ANY, 14);

            theTag.Pictures.Add(picInfo);

            theTag.Chapters = theFile.NativeTag.Chapters;
            theTag.Chapters.Add(new ChapterInfo(3000, "Chapter 2"));

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));


            try
            {
                // Read Quicktime chapters specifically
                ATL.Settings.MP4_readChaptersExclusive = 1;
                Assert.IsTrue(theFile.ReadFromFile(true, true));
                Assert.AreEqual(2, theFile.NativeTag.Chapters.Count);
                Assert.AreEqual((uint)0, theFile.NativeTag.Chapters[0].StartTime);    // 1st Quicktime chapter can't start at position > 0
                Assert.AreEqual("aa父bb", theFile.NativeTag.Chapters[0].Title);
                Assert.AreEqual((uint)2945, theFile.NativeTag.Chapters[1].StartTime); // Approximate due to the way timecodes are formatted in the MP4 format
                Assert.AreEqual("Chapter 2", theFile.NativeTag.Chapters[1].Title);

                // Read Nero chapters specifically
                ATL.Settings.MP4_readChaptersExclusive = 2;
                Assert.IsTrue(theFile.ReadFromFile(true, true));
                Assert.AreEqual(2, theFile.NativeTag.Chapters.Count);
                Assert.AreEqual((uint)55, theFile.NativeTag.Chapters[0].StartTime);
                Assert.AreEqual("aa父bb", theFile.NativeTag.Chapters[0].Title);
                Assert.AreEqual((uint)3000, theFile.NativeTag.Chapters[1].StartTime);
                Assert.AreEqual("Chapter 2", theFile.NativeTag.Chapters[1].Title);
            }
            finally
            {
                ATL.Settings.MP4_readChaptersExclusive = 0;
            }


            // Read the rest supported fields
            readExistingTagsOnFile(theFile, 2);

            // Additional supported field
            Assert.AreEqual("John Jackman", theFile.NativeTag.Conductor);

            byte nbFound = 0;

            foreach (PictureInfo pic in theFile.NativeTag.EmbeddedPictures)
            {
                if (pic.PicType.Equals(PIC_TYPE.Generic) && (1 == nbFound))
                {
                    using (Image picture = Image.FromStream(new MemoryStream(pic.PictureData)))
                    {
                        Assert.AreEqual(ImageFormat.Png, picture.RawFormat);
                        Assert.AreEqual(175, picture.Width);
                        Assert.AreEqual(168, picture.Height);
                    }
                }
                nbFound++;
            }

            Assert.AreEqual(2, nbFound);

            // Remove the additional supported field
            theTag           = new TagData();
            theTag.Conductor = "";

            // Remove additional picture
            picInfo = new PictureInfo(PIC_TYPE.Back);
            picInfo.MarkedForDeletion = true;
            theTag.Pictures.Add(picInfo);

            // Add the new tag and check that it has been indeed added with all the correct information
            Assert.IsTrue(theFile.UpdateTagInFile(theTag, MetaDataIOFactory.TAG_NATIVE));

            readExistingTagsOnFile(theFile);

            // Additional removed field
            Assert.AreEqual("", theFile.NativeTag.Conductor);


            // Check that the resulting file (working copy that has been tagged, then untagged) remains identical to the original file (i.e. no byte lost nor added)

            /* NOT POSSIBLE YET mainly due to tag order and tag naming (e.g. "gnre" becoming "©gen") differences
             *          FileInfo originalFileInfo = new FileInfo(location);
             *          FileInfo testFileInfo = new FileInfo(testFileLocation);
             *
             *          Assert.AreEqual(originalFileInfo.Length, testFileInfo.Length);
             *
             *          string originalMD5 = TestUtils.GetFileMD5Hash(location);
             *          string testMD5 = TestUtils.GetFileMD5Hash(testFileLocation);
             *
             *          Assert.IsTrue(originalMD5.Equals(testMD5));
             */
            // Get rid of the working copy
            if (Settings.DeleteAfterSuccess)
            {
                File.Delete(testFileLocation);
            }
        }