Example #1
0
        private void SetItunesMediaProperties(AppleTag target, Properties fileProperties, AppleDefaultBoxes.ITunesMediaTypes mediaType)
        {
            var hdVideoTagValue = fileProperties.VideoWidth >= HDVideoMinWidth && fileProperties.VideoHeight >= HDVideoMinHeight ? 1 : 0;

            target.SetData(AppleDefaultBoxes.ITunesHDVideo, new ByteVector(new byte[] { Convert.ToByte(hdVideoTagValue) }), 0);
            target.SetData(AppleDefaultBoxes.ITunesMediaType, new ByteVector(new byte[] { Convert.ToByte((int)mediaType) }), 0);
        }
Example #2
0
        /// <summary>
        ///    Removes a set of tag types from the current instance.
        /// </summary>
        /// <param name="types">
        ///    A bitwise combined <see cref="TagLib.TagTypes" /> value
        ///    containing tag types to be removed from the file.
        /// </param>
        /// <remarks>
        ///    In order to remove all tags from a file, pass <see
        ///    cref="TagTypes.AllTags" /> as <paramref name="types" />.
        /// </remarks>
        public override void RemoveTags(TagTypes types)
        {
            if ((types & TagTypes.Apple) != TagTypes.Apple ||
                apple_tag == null)
            {
                return;
            }

            apple_tag.DetachIlst();
            apple_tag = null;
            tag.SetTags();
        }
Example #3
0
 private void Read(ReadStyle propertiesStyle)
 {
     this.tag = new CombinedTag();
     base.Mode = TagLib.File.AccessMode.Read;
     try
     {
         FileParser parser = new FileParser(this);
         if (propertiesStyle == ReadStyle.None)
         {
             parser.ParseTag();
         }
         else
         {
             parser.ParseTagAndProperties();
         }
         base.InvariantStartPosition = parser.MdatStartPosition;
         base.InvariantEndPosition = parser.MdatEndPosition;
         this.udta_box = parser.UserDataBox;
         if (((this.udta_box != null) && (this.udta_box.GetChild(BoxType.Meta) != null)) && (this.udta_box.GetChild(BoxType.Meta).GetChild(BoxType.Ilst) != null))
         {
             base.TagTypesOnDisk |= TagTypes.Apple;
         }
         if (this.udta_box == null)
         {
             this.udta_box = new IsoUserDataBox();
         }
         this.apple_tag = new AppleTag(this.udta_box);
         TagLib.Tag[] tags = new TagLib.Tag[] { this.apple_tag };
         this.tag.SetTags(tags);
         if (propertiesStyle == ReadStyle.None)
         {
             base.Mode = TagLib.File.AccessMode.Closed;
         }
         else
         {
             IsoMovieHeaderBox movieHeaderBox = parser.MovieHeaderBox;
             if (movieHeaderBox == null)
             {
                 base.Mode = TagLib.File.AccessMode.Closed;
                 throw new CorruptFileException("mvhd box not found.");
             }
             IsoAudioSampleEntry audioSampleEntry = parser.AudioSampleEntry;
             IsoVisualSampleEntry visualSampleEntry = parser.VisualSampleEntry;
             ICodec[] codecs = new ICodec[] { audioSampleEntry, visualSampleEntry };
             this.properties = new TagLib.Properties(movieHeaderBox.Duration, codecs);
         }
     }
     finally
     {
         base.Mode = TagLib.File.AccessMode.Closed;
     }
 }
Example #4
0
 public override TagLib.Tag GetTag(TagTypes type, bool create)
 {
     if (type != TagTypes.Apple)
     {
         return null;
     }
     if ((this.apple_tag == null) && create)
     {
         this.apple_tag = new AppleTag(this.udta_box);
         TagLib.Tag[] tags = new TagLib.Tag[] { this.apple_tag };
         this.tag.SetTags(tags);
     }
     return this.apple_tag;
 }
Example #5
0
        /// <summary>
        ///    Gets a tag of a specified type from the current instance,
        ///    optionally creating a new tag if possible.
        /// </summary>
        /// <param name="type">
        ///    A <see cref="TagTypes" /> value indicating the
        ///    type of tag to read.
        /// </param>
        /// <param name="create">
        ///    A <see cref="bool" /> value specifying whether or not to
        ///    try and create the tag if one is not found.
        /// </param>
        /// <returns>
        ///    A <see cref="Tag" /> object containing the tag that was
        ///    found in or added to the current instance. If no
        ///    matching tag was found and none was created, <see
        ///    langword="null" /> is returned.
        /// </returns>
        /// <remarks>
        ///    At the time of this writing, only <see cref="AppleTag" />
        ///    is supported. All other tag types will be ignored.
        /// </remarks>
        public override Tag GetTag(TagTypes type, bool create)
        {
            if (type == TagTypes.Apple)
            {
                if (apple_tag == null && create)
                {
                    apple_tag = new AppleTag(udta_box);
                    tag.SetTags(apple_tag);
                }

                return(apple_tag);
            }

            return(null);
        }
Example #6
0
        private async Task TagMp4File(Video video, string filePath, CancellationToken cancellationToken)
        {
            // Try to get picture
            var picture = await TryGetPictureAsync(video, cancellationToken);

            // Inject tags
            var taggedFile = File.Create(filePath);

            taggedFile.Tag.Pictures = picture != null ? new[] { picture } : Array.Empty <IPicture>();
            AppleTag customTag = (AppleTag)taggedFile.GetTag(TagTypes.Apple);

            customTag.SetDashBox("Upload Date", "    Upload Date", video.UploadDate.ToString("yyyy-MM-dd"));
            customTag.SetDashBox("Channel", "    Channel", video.Author);
            taggedFile.Save();
        }
Example #7
0
        /// <summary>
        ///    Gets a tag of a specified type from the current instance,
        ///    optionally creating a new tag if possible.
        /// </summary>
        /// <param name="type">
        ///    A <see cref="TagLib.TagTypes" /> value indicating the
        ///    type of tag to read.
        /// </param>
        /// <param name="create">
        ///    A <see cref="bool" /> value specifying whether or not to
        ///    try and create the tag if one is not found.
        /// </param>
        /// <returns>
        ///    A <see cref="Tag" /> object containing the tag that was
        ///    found in or added to the current instance. If no
        ///    matching tag was found and none was created, <see
        ///    langword="null" /> is returned.
        /// </returns>
        /// <remarks>
        ///    At the time of this writing, only <see cref="AppleTag" />
        ///    is supported. All other tag types will be ignored.
        /// </remarks>
        public override TagLib.Tag GetTag(TagTypes type, bool create)
        {
            if (type == TagTypes.Apple)
            {
                if (apple_tag == null && create)
                {
                    IsoUserDataBox udtaBox = FindAppleTagUdta();
                    if (null == udtaBox)
                    {
                        udtaBox = new IsoUserDataBox();
                    }
                    apple_tag = new AppleTag(udtaBox);
                    tag.SetTags(apple_tag);
                }

                return(apple_tag);
            }

            return(null);
        }
Example #8
0
		/// <summary>
		///    Gets a tag of a specified type from the current instance,
		///    optionally creating a new tag if possible.
		/// </summary>
		/// <param name="type">
		///    A <see cref="TagLib.TagTypes" /> value indicating the
		///    type of tag to read.
		/// </param>
		/// <param name="create">
		///    A <see cref="bool" /> value specifying whether or not to
		///    try and create the tag if one is not found.
		/// </param>
		/// <returns>
		///    A <see cref="Tag" /> object containing the tag that was
		///    found in or added to the current instance. If no
		///    matching tag was found and none was created, <see
		///    langword="null" /> is returned.
		/// </returns>
		/// <remarks>
		///    At the time of this writing, only <see cref="AppleTag" />
		///    is supported. All other tag types will be ignored.
		/// </remarks>
		public override TagLib.Tag GetTag (TagTypes type, bool create)
		{
			if (type == TagTypes.Apple) {
				if (apple_tag == null && create) {
					apple_tag = new AppleTag (udta_box);
					tag.SetTags (apple_tag);
				}
				
				return apple_tag;
			}
			
			return null;
		}
Example #9
0
        /// <summary>
        ///    Reads the file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        private void Read(ReadStyle propertiesStyle)
        {
            // +TODO: Support Id3v2 boxes!!!
            tag  = new CombinedTag();
            Mode = AccessMode.Read;
            try {
                FileParser parser = new FileParser(this);

                if (propertiesStyle == ReadStyle.None)
                {
                    parser.ParseTag();
                }
                else
                {
                    parser.ParseTagAndProperties();
                }

                InvariantStartPosition = parser.MdatStartPosition;
                InvariantEndPosition   = parser.MdatEndPosition;

                udta_boxes.AddRange(parser.UserDataBoxes);

                // Ensure our collection contains at least a single empty box
                if (udta_boxes.Count == 0)
                {
                    IsoUserDataBox dummy = new IsoUserDataBox();
                    udta_boxes.Add(dummy);
                }

                // Check if a udta with ILST actually exists
                if (IsAppleTagUdtaPresent())
                {
                    TagTypesOnDisk |= TagTypes.Apple;                           //There is an udta present with ILST info
                }
                // Find the udta box with the Apple Tag ILST
                IsoUserDataBox udtaBox = FindAppleTagUdta();
                if (null == udtaBox)
                {
                    udtaBox = new IsoUserDataBox();
                }
                apple_tag = new AppleTag(udtaBox);
                tag.SetTags(apple_tag);

                // If we're not reading properties, we're done.
                if (propertiesStyle == ReadStyle.None)
                {
                    Mode = AccessMode.Closed;
                    return;
                }

                // Get the movie header box.
                IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
                if (mvhd_box == null)
                {
                    Mode = AccessMode.Closed;
                    throw new CorruptFileException(
                              "mvhd box not found.");
                }

                IsoAudioSampleEntry audio_sample_entry =
                    parser.AudioSampleEntry;
                IsoVisualSampleEntry visual_sample_entry =
                    parser.VisualSampleEntry;

                // Read the properties.
                properties = new Properties(mvhd_box.Duration,
                                            audio_sample_entry, visual_sample_entry);
            } finally {
                Mode = AccessMode.Closed;
            }
        }
Example #10
0
        /// <summary>
        ///    Reads the file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        private void Read(ReadStyle propertiesStyle)
        {
            // TODO: Support Id3v2 boxes!!!
            tag  = new CombinedTag();
            Mode = AccessMode.Read;
            try {
                FileParser parser = new FileParser(this);

                if (propertiesStyle == ReadStyle.None)
                {
                    parser.ParseTag();
                }
                else
                {
                    parser.ParseTagAndProperties();
                }

                InvariantStartPosition = parser.MdatStartPosition;
                InvariantEndPosition   = parser.MdatEndPosition;

                udta_box = parser.UserDataBox;

                if (udta_box != null && udta_box.GetChild(BoxType.Meta)
                    != null && udta_box.GetChild(BoxType.Meta
                                                 ).GetChild(BoxType.Ilst) != null)
                {
                    TagTypesOnDisk |= TagTypes.Apple;
                }

                if (udta_box == null)
                {
                    udta_box = new IsoUserDataBox();
                }

                apple_tag = new AppleTag(udta_box);
                tag.SetTags(apple_tag);

                // If we're not reading properties, we're done.
                if (propertiesStyle == ReadStyle.None)
                {
                    Mode = AccessMode.Closed;
                    return;
                }

                // Get the movie header box.
                IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
                if (mvhd_box == null)
                {
                    Mode = AccessMode.Closed;
                    throw new CorruptFileException(
                              "mvhd box not found.");
                }

                IsoAudioSampleEntry audio_sample_entry =
                    parser.AudioSampleEntry;
                IsoVisualSampleEntry visual_sample_entry =
                    parser.VisualSampleEntry;

                // Read the properties.
                properties = new Properties(mvhd_box.Duration,
                                            audio_sample_entry, visual_sample_entry);
            } finally {
                Mode = AccessMode.Closed;
            }
        }
        /// <summary>
        ///    Gets a tag of a specified type from the current instance,
        ///    optionally creating a new tag if possible.
        /// </summary>
        /// <param name="type">
        ///    A <see cref="TagLib.TagTypes" /> value indicating the
        ///    type of tag to read.
        /// </param>
        /// <param name="create">
        ///    A <see cref="bool" /> value specifying whether or not to
        ///    try and create the tag if one is not found.
        /// </param>
        /// <returns>
        ///    A <see cref="Tag" /> object containing the tag that was
        ///    found in or added to the current instance. If no
        ///    matching tag was found and none was created, <see
        ///    langword="null" /> is returned.
        /// </returns>
        /// <remarks>
        ///    At the time of this writing, only <see cref="AppleTag" />
        ///    is supported. All other tag types will be ignored.
        /// </remarks>
        public override TagLib.Tag GetTag(TagTypes type, bool create)
        {
            if (type == TagTypes.Apple) {
                if (apple_tag == null && create) {
                    IsoUserDataBox udtaBox = FindAppleTagUdta();
                    if (null == udtaBox) {
                        udtaBox = new IsoUserDataBox();
                    }
                    apple_tag = new AppleTag (udtaBox);
                    tag.SetTags (apple_tag);
                }

                return apple_tag;
            }

            return null;
        }
Example #12
0
 private void SetPropertyIfValid(AppleTag target, string value, ByteVector key)
 {
     SetPropertyIfValid(target, value, (d, e) => d.SetText(key, e));
 }
Example #13
0
 public override void RemoveTags(TagTypes types)
 {
     if (((types & TagTypes.Apple) == TagTypes.Apple) && (this.apple_tag != null))
     {
         this.apple_tag.DetachIlst();
         this.apple_tag = null;
         this.tag.SetTags(new TagLib.Tag[0]);
     }
 }
Example #14
0
		/// <summary>
		///    Removes a set of tag types from the current instance.
		/// </summary>
		/// <param name="types">
		///    A bitwise combined <see cref="TagLib.TagTypes" /> value
		///    containing tag types to be removed from the file.
		/// </param>
		/// <remarks>
		///    In order to remove all tags from a file, pass <see
		///    cref="TagTypes.AllTags" /> as <paramref name="types" />.
		/// </remarks>
		public override void RemoveTags (TagTypes types)
		{
			if ((types & TagTypes.Apple) != TagTypes.Apple ||
				apple_tag == null)
				return;
			
			apple_tag.DetachIlst ();
			apple_tag = null;
			tag.SetTags ();
		}
        /// <summary>
        ///    Reads the file with a specified read style.
        /// </summary>
        /// <param name="propertiesStyle">
        ///    A <see cref="ReadStyle" /> value specifying at what level
        ///    of accuracy to read the media properties, or <see
        ///    cref="ReadStyle.None" /> to ignore the properties.
        /// </param>
        private void Read(ReadStyle propertiesStyle)
        {
            // TODO: Support Id3v2 boxes!!!
            tag = new CombinedTag ();
            Mode = AccessMode.Read;
            try {
                FileParser parser = new FileParser (this);

                if (propertiesStyle == ReadStyle.None)
                    parser.ParseTag ();
                else
                    parser.ParseTagAndProperties ();

                InvariantStartPosition = parser.MdatStartPosition;
                InvariantEndPosition = parser.MdatEndPosition;

                udta_boxes.AddRange(parser.UserDataBoxes);

                // Ensure our collection contains at least a single empty box
                if (udta_boxes.Count == 0) {
                    IsoUserDataBox dummy = new IsoUserDataBox ();
                    udta_boxes.Add(dummy);
                }

                // Check if a udta with ILST actually exists
                if (IsAppleTagUdtaPresent ())
                    TagTypesOnDisk |= TagTypes.Apple;	//There is an udta present with ILST info

                // Find the udta box with the Apple Tag ILST
                IsoUserDataBox udtaBox = FindAppleTagUdta();
                if (null == udtaBox) {
                    udtaBox = new IsoUserDataBox();
                }
                apple_tag = new AppleTag (udtaBox);
                tag.SetTags (apple_tag);

                // If we're not reading properties, we're done.
                if (propertiesStyle == ReadStyle.None) {
                    Mode = AccessMode.Closed;
                    return;
                }

                // Get the movie header box.
                IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
                if(mvhd_box == null) {
                    Mode = AccessMode.Closed;
                    throw new CorruptFileException (
                        "mvhd box not found.");
                }

                IsoAudioSampleEntry  audio_sample_entry =
                    parser.AudioSampleEntry;
                IsoVisualSampleEntry visual_sample_entry =
                    parser.VisualSampleEntry;

                // Read the properties.
                properties = new Properties (mvhd_box.Duration,
                    audio_sample_entry, visual_sample_entry);
            } finally {
                Mode = AccessMode.Closed;
            }
        }
Example #16
0
		/// <summary>
		///    Reads the file with a specified read style.
		/// </summary>
		/// <param name="propertiesStyle">
		///    A <see cref="ReadStyle" /> value specifying at what level
		///    of accuracy to read the media properties, or <see
		///    cref="ReadStyle.None" /> to ignore the properties.
		/// </param>
		private void Read (ReadStyle propertiesStyle)
		{
			// TODO: Support Id3v2 boxes!!!
			tag = new CombinedTag ();
			Mode = AccessMode.Read;
			try {
				FileParser parser = new FileParser (this);
				
				if (propertiesStyle == ReadStyle.None)
					parser.ParseTag ();
				else
					parser.ParseTagAndProperties ();
				
				InvariantStartPosition = parser.MdatStartPosition;
				InvariantEndPosition = parser.MdatEndPosition;
				
				udta_box = parser.UserDataBox;
				
				if (udta_box != null && udta_box.GetChild (BoxType.Meta)
					!= null && udta_box.GetChild (BoxType.Meta
					).GetChild (BoxType.Ilst) != null)
					TagTypesOnDisk |= TagTypes.Apple;
				
				if (udta_box == null)
					udta_box = new IsoUserDataBox ();
				
				apple_tag = new AppleTag (udta_box);
				tag.SetTags (apple_tag);
				
				// If we're not reading properties, we're done.
				if (propertiesStyle == ReadStyle.None) {
					Mode = AccessMode.Closed;
					return;
				}
				
				// Get the movie header box.
				IsoMovieHeaderBox mvhd_box = parser.MovieHeaderBox;
				if(mvhd_box == null) {
					Mode = AccessMode.Closed;
					throw new CorruptFileException (
						"mvhd box not found.");
				}
				
				IsoAudioSampleEntry  audio_sample_entry =
					parser.AudioSampleEntry;
				IsoVisualSampleEntry visual_sample_entry =
					parser.VisualSampleEntry;
				
				// Read the properties.
				properties = new Properties (mvhd_box.Duration,
					audio_sample_entry, visual_sample_entry);
			} finally {
				Mode = AccessMode.Closed;
			}
		}
Example #17
0
 public AppleTvTag(TagLib.File f)
 {
     m_Tags = (TagLib.Mpeg4.AppleTag) f.GetTag(TagLib.TagTypes.Apple, true);
 }