Ejemplo n.º 1
0
        /// <summary>
        ///    Creates a deep copy of the current instance.
        /// </summary>
        /// <returns>
        ///    A new <see cref="Frame" /> object identical to the
        ///    current instance.
        /// </returns>
        public override Frame Clone()
        {
            if (file != null)
            {
                Load();
            }

            var frame = new AttachmentFrame {
                encoding    = encoding,
                mime_type   = mime_type,
                Type        = type,
                filename    = filename,
                description = description
            };

            if (data != null)
            {
                frame.data = new ByteVector(data);
            }
            if (raw_data != null)
            {
                frame.data = new ByteVector(raw_data);
            }

            frame.raw_version = raw_version;
            return(frame);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///    Creates a deep copy of the current instance.
        /// </summary>
        /// <returns>
        ///    A new <see cref="Frame" /> object identical to the
        ///    current instance.
        /// </returns>
        public override Frame Clone()
        {
            if (file != null)
            {
                Load();
            }

            AttachmentFrame frame = new AttachmentFrame();

            frame.encoding    = encoding;
            frame.mime_type   = mime_type;
            frame.Type        = type;
            frame.filename    = filename;
            frame.description = description;
            if (data != null)
            {
                frame.data = new ByteVector(data);
            }
            if (raw_data != null)
            {
                frame.data = new ByteVector(raw_data);
            }
            frame.raw_version = raw_version;
            return(frame);
        }
Ejemplo n.º 3
0
        /// <summary>
        ///    Gets a specified attachment frame from the specified tag,
        ///    optionally creating it if it does not exist.
        /// </summary>
        /// <param name="tag">
        ///    A <see cref="Tag" /> object to search in.
        /// </param>
        /// <param name="description">
        ///    A <see cref="string" /> specifying the description to
        ///    match.
        /// </param>
        /// <param name="type">
        ///    A <see cref="PictureType" /> specifying the picture type
        ///    to match.
        /// </param>
        /// <param name="create">
        ///    A <see cref="bool" /> specifying whether or not to create
        ///    and add a new frame to the tag if a match is not found.
        /// </param>
        /// <returns>
        ///    A <see cref="AttachmentFrame" /> object containing
        ///    the matching frame, or <see langword="null" /> if a match
        ///    wasn't found and <paramref name="create" /> is <see
        ///    langword="false" />.
        /// </returns>
        /// <example>
        ///    <para>Sets a cover image with a description. Because <see
        ///    cref="Get(Tag,string,PictureType,bool)" /> is used, if
        ///    the program is called again with the same audio file and
        ///    desciption, the picture will be overwritten with the new
        ///    one.</para>
        ///    <code lang="C#">
        /// using TagLib;
        /// using TagLib.Id3v2;
        ///
        /// public static class SetId3v2Cover
        /// {
        ///     public static void Main (string [] args)
        ///     {
        ///         if (args.Length != 3)
        ///             throw new ApplicationException (
        ///                 "USAGE: SetId3v2Cover.exe AUDIO_FILE PICTURE_FILE DESCRIPTION");
        ///
        ///         // Create the file. Can throw file to TagLib# exceptions.
        ///         File file = File.Create (args [0]);
        ///
        ///         // Get or create the ID3v2 tag.
        ///         TagLib.Id3v2.Tag tag = file.GetTag (TagTypes.Id3v2, true) as TagLib.Id3v2.Tag;
        ///         if (tag == null)
        ///             throw new ApplicationException ("File does not support ID3v2 tags.");
        ///
        ///         // Create a picture. Can throw file related exceptions.
        ///		TagLib.Picture picture = TagLib.Picture.CreateFromPath (args [1]);
        ///
        ///         // Get or create the picture frame.
        ///         AttachedPictureFrame frame = AttachedPictureFrame.Get (
        ///             tag, args [2], PictureType.FrontCover, true);
        ///
        ///         // Set the data from the picture.
        ///         frame.MimeType = picture.MimeType;
        ///         frame.Data     = picture.data;
        ///
        ///         // Save the file.
        ///         file.Save ();
        ///     }
        /// }
        ///    </code>
        /// </example>
        public static AttachmentFrame Get(Tag tag,
                                          string description,
                                          PictureType type,
                                          bool create)
        {
            AttachmentFrame att;

            foreach (Frame frame in tag.GetFrames <AttachmentFrame>())
            {
                att = frame as AttachmentFrame;

                if (att == null)
                {
                    continue;
                }

                if (description != null && att.Description != description)
                {
                    continue;
                }

                if (type != PictureType.Other && att.Type != type)
                {
                    continue;
                }

                return(att);
            }

            if (!create)
            {
                return(null);
            }

            att             = new AttachmentFrame();
            att.Description = description;
            att.Type        = type;

            tag.AddFrame(att);

            return(att);
        }