Ejemplo n.º 1
0
        private ushort writeExtendedMeta(TagData tag, BinaryWriter w, bool isExtendedMetaLibrary = false)
        {
            ushort counter = 0;

            // Supported textual fields : all current supported fields are located in extended content description frame

            // Other textual fields
            foreach (MetaFieldInfo fieldInfo in tag.AdditionalFields)
            {
                if ((fieldInfo.TagType.Equals(MetaDataIOFactory.TAG_ANY) || fieldInfo.TagType.Equals(getImplementedTagType())) && !fieldInfo.MarkedForDeletion)
                {
                    if ((ZONE_EXTENDED_HEADER_METADATA.Equals(fieldInfo.Zone) && !isExtendedMetaLibrary) || (ZONE_EXTENDED_HEADER_METADATA_LIBRARY.Equals(fieldInfo.Zone) && isExtendedMetaLibrary))
                    {
                        writeTextFrame(w, fieldInfo.NativeFieldCode, fieldInfo.Value, true, encodeLanguage(w.BaseStream, fieldInfo.Language), fieldInfo.StreamNumber);
                        counter++;
                    }
                }
            }

            // Picture fields
            if (isExtendedMetaLibrary)
            {
                foreach (PictureInfo picInfo in tag.Pictures)
                {
                    if (1 == picInfo.TransientFlag)
                    {
                        writePictureFrame(w, picInfo.PictureData, picInfo.MimeType, picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? (byte)picInfo.NativePicCode : ID3v2.EncodeID3v2PictureType(picInfo.PicType), picInfo.Description, true);
                        counter++;
                    }
                }
            }

            return(counter);
        }
Ejemplo n.º 2
0
        private int writePictureBlock(BinaryWriter w, PictureInfo picture)
        {
            long sizePos, dataPos, finalPos;

            w.Write(META_PICTURE);

            sizePos = w.BaseStream.Position;
            w.Write(new byte[] { 0, 0, 0 }); // Placeholder for 24-bit integer that will be rewritten at the end of the method

            dataPos = w.BaseStream.Position;
            vorbisTag.WritePicture(w, picture.PictureData, picture.NativeFormat, ImageUtils.GetMimeTypeFromImageFormat(picture.NativeFormat), picture.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? picture.NativePicCode : ID3v2.EncodeID3v2PictureType(picture.PicType), picture.Description);

            finalPos = w.BaseStream.Position;
            w.BaseStream.Seek(sizePos, SeekOrigin.Begin);
            w.Write(StreamUtils.EncodeBEUInt24((uint)(finalPos - dataPos)));
            w.BaseStream.Seek(finalPos, SeekOrigin.Begin);

            return(1);
        }
Ejemplo n.º 3
0
        private int writeExtendedContentDescription(TagData tag, BinaryWriter w)
        {
            long   beginPos, frameSizePos, counterPos, finalFramePos;
            ushort counter = 0;

            beginPos = w.BaseStream.Position;
            w.Write(WMA_EXTENDED_CONTENT_DESCRIPTION_ID);
            frameSizePos = w.BaseStream.Position;
            w.Write((ulong)0);  // Frame size placeholder to be rewritten at the end of the method
            counterPos = w.BaseStream.Position;
            w.Write((ushort)0); // Counter placeholder to be rewritten at the end of the method

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

            // Supported textual fields
            foreach (byte frameType in map.Keys)
            {
                foreach (string s in frameMapping.Keys)
                {
                    if (!embeddedFields.Contains(s) && frameType == frameMapping[s])
                    {
                        if (map[frameType].Length > 0) // No frame with empty value
                        {
                            string value = formatBeforeWriting(frameType, tag, map);

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

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

            // Picture fields
            foreach (PictureInfo picInfo in tag.Pictures)
            {
                if (0 == picInfo.TransientFlag)
                {
                    writePictureFrame(w, picInfo.PictureData, picInfo.MimeType, picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? (byte)picInfo.NativePicCode : ID3v2.EncodeID3v2PictureType(picInfo.PicType), picInfo.Description);
                    counter++;
                }
            }


            // Go back to frame size locations to write their actual size
            finalFramePos = w.BaseStream.Position;
            w.BaseStream.Seek(frameSizePos, SeekOrigin.Begin);
            w.Write(Convert.ToUInt64(finalFramePos - beginPos));
            w.BaseStream.Seek(counterPos, SeekOrigin.Begin);
            w.Write(counter);
            w.BaseStream.Seek(finalFramePos, SeekOrigin.Begin);

            return(counter);
        }
Ejemplo n.º 4
0
        private uint writeFrames(TagData tag, BinaryWriter w)
        {
            bool doWritePicture;
            uint nbFrames = 0;

            IDictionary <byte, String> map = tag.ToMap();
            string recordingYear           = Utils.ProtectValue(tag.RecordingYear);

            if (recordingYear.Length > 0)
            {
                string recordingDate = Utils.ProtectValue(tag.RecordingDate);
                if (0 == recordingDate.Length || !recordingDate.StartsWith(recordingYear))
                {
                    map[TagData.TAG_FIELD_RECORDING_DATE] = recordingYear;
                }
            }

            // 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 = formatBeforeWriting(frameType, tag, map);
                            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);
        }
Ejemplo n.º 5
0
        private Int32 writePictures(BinaryWriter w, IList <PictureInfo> pictures, Boolean isLast)
        {
            var   result = 0;
            Int64 sizePos, dataPos, finalPos;
            Byte  blockType;

            foreach (var picture in pictures)
            {
                blockType = META_PICTURE;
                if (isLast)
                {
                    blockType = (Byte)(blockType & 0x80);
                }

                w.Write(blockType);
                sizePos = w.BaseStream.Position;
                w.Write(new Byte[] { 0, 0, 0 }); // Placeholder for 24-bit integer that will be rewritten at the end of the method

                dataPos = w.BaseStream.Position;
                vorbisTag.WritePicture(w, picture.PictureData, picture.NativeFormat, ImageUtils.GetMimeTypeFromImageFormat(picture.NativeFormat), picture.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? picture.NativePicCode : ID3v2.EncodeID3v2PictureType(picture.PicType), picture.Description);

                finalPos = w.BaseStream.Position;
                w.BaseStream.Seek(sizePos, SeekOrigin.Begin);
                w.Write(StreamUtils.EncodeBEUInt24((UInt32)(finalPos - dataPos)));
                w.BaseStream.Seek(finalPos, SeekOrigin.Begin);
                result++;
            }

            return(result);
        }
Ejemplo n.º 6
0
        private UInt32 writeFrames(TagData tag, BinaryWriter w)
        {
            Boolean doWritePicture;
            UInt32  nbFrames = 0;

            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;
                    }
                }
            }

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

            // Other textual fields
            foreach (var 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 (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.NativePicCode : ID3v2.EncodeID3v2PictureType(picInfo.PicType), picInfo.Description);
                        nbFrames++;
                    }
                }
            }

            return(nbFrames);
        }
Ejemplo n.º 7
0
        private int writePictures(BinaryWriter w, IList <PictureInfo> pictures, bool isLast)
        {
            int  result = 0;
            long sizePos, dataPos, finalPos;
            byte blockType;

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

                if (doWritePicture)
                {
                    blockType = META_PICTURE;
                    if (isLast)
                    {
                        blockType = (byte)(blockType & 0x80);
                    }

                    w.Write(blockType);
                    sizePos = w.BaseStream.Position;
                    w.Write(new byte[] { 0, 0, 0 }); // Placeholder for 24-bit integer that will be rewritten at the end of the method

                    dataPos = w.BaseStream.Position;
                    vorbisTag.WritePicture(w, picture.PictureData, picture.NativeFormat, ImageUtils.GetMimeTypeFromImageFormat(picture.NativeFormat), picture.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? picture.NativePicCode : ID3v2.EncodeID3v2PictureType(picture.PicType), picture.Description);

                    finalPos = w.BaseStream.Position;
                    w.BaseStream.Seek(sizePos, SeekOrigin.Begin);
                    w.Write(StreamUtils.EncodeBEUInt24((uint)(finalPos - dataPos)));
                    w.BaseStream.Seek(finalPos, SeekOrigin.Begin);
                    result++;
                }
            }

            return(result);
        }
Ejemplo n.º 8
0
        private ushort writeExtendedMeta(TagData tag, BinaryWriter w, bool isExtendedMetaLibrary = false)
        {
            bool   doWritePicture;
            ushort counter = 0;

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

            // Supported textual fields : all current supported fields are located in extended content description frame

            // Other textual fields
            foreach (MetaFieldInfo fieldInfo in tag.AdditionalFields)
            {
                if ((fieldInfo.TagType.Equals(MetaDataIOFactory.TAG_ANY) || fieldInfo.TagType.Equals(getImplementedTagType())) && !fieldInfo.MarkedForDeletion)
                {
                    if ((ZONE_EXTENDED_HEADER_METADATA.Equals(fieldInfo.Zone) && !isExtendedMetaLibrary) || (ZONE_EXTENDED_HEADER_METADATA_LIBRARY.Equals(fieldInfo.Zone) && isExtendedMetaLibrary))
                    {
                        writeTextFrame(w, fieldInfo.NativeFieldCode, fieldInfo.Value, true, encodeLanguage(w.BaseStream, fieldInfo.Language), fieldInfo.StreamNumber);
                        counter++;
                    }
                }
            }

            // Picture fields (exclusively written in Metadata Library Object zone)
            if (isExtendedMetaLibrary)
            {
                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 && picInfo.PictureData.Length + 50 > ushort.MaxValue)
                    {
                        writePictureFrame(w, picInfo.PictureData, picInfo.NativeFormat, ImageUtils.GetMimeTypeFromImageFormat(picInfo.NativeFormat), picInfo.PicType.Equals(PictureInfo.PIC_TYPE.Unsupported) ? (byte)picInfo.NativePicCode : ID3v2.EncodeID3v2PictureType(picInfo.PicType), picInfo.Description, true);
                        counter++;
                    }
                }
            }

            return(counter);
        }