Пример #1
0
		private Tag FindMpcTag(TagTypes type, bool create)
		{
			switch (type)
			{
				case TagTypes.Id3v2:
					{
						if (create && id3v2Tag == null)
						{
							id3v2Tag = new Id3v2Tag();

							if (tag != null)
								TagLib.Tag.Duplicate(tag, id3v2Tag, true);

							tag.SetTags(apeTag, id3v2Tag, id3v1Tag);
						}
						return id3v2Tag;
					}

				case TagTypes.Id3v1:
					{
						if (create && id3v1Tag == null)
						{
							id3v1Tag = new Id3v1Tag();

							if (tag != null)
								TagLib.Tag.Duplicate(tag, id3v1Tag, true);

							tag.SetTags(apeTag, id3v2Tag, id3v1Tag);
						}
						return id3v1Tag;
					}

				case TagTypes.Ape:
					{
						if (create && apeTag == null)
						{
							apeTag = new ApeTag();

							if (tag != null)
								TagLib.Tag.Duplicate(tag, apeTag, true);

							tag.SetTags(apeTag, id3v2Tag, id3v1Tag);
						}
						return apeTag;
					}

				default:
					return null;
			}
		}
Пример #2
0
		private Tag FindFlacTag(TagTypes type, bool create)
		{
			switch (type)
			{
				case TagTypes.Id3v1:
					{
						if (create && id3v1_tag == null)
						{
							id3v1_tag = new Id3v1Tag();

							if (tag != null)
								TagLib.Tag.Duplicate(tag, id3v1_tag, true);

							tag.SetTags(comment, id3v2_tag, id3v1_tag);
						}
						return id3v1_tag;
					}

				case TagTypes.Id3v2:
					{
						if (create && id3v2_tag == null)
						{
							id3v2_tag = new Id3v2Tag();

							if (tag != null)
								TagLib.Tag.Duplicate(tag, id3v2_tag, true);

							tag.SetTags(comment, id3v2_tag, id3v1_tag);
						}
						return id3v2_tag;
					}

				case TagTypes.Xiph:
					{
						if (create && comment == null)
						{
							comment = new OggXiphComment();

							if (tag != null)
								TagLib.Tag.Duplicate(tag, comment, true);

							tag.SetTags(comment, id3v2_tag, id3v1_tag);
						}
						return comment;
					}

				default:
					return null;
			}
		}
Пример #3
0
		private void Read(ReadStyle propertiesStyle)
		{
			long flacDataBegin;
			long flacDataEnd;

			// Look for an ID3v2 tag
			long id3v2Location = FindId3v2();

			if (id3v2Location >= 0)
			{
				id3v2_tag = new Id3v2Tag(this, id3v2Location);
				flacDataBegin = id3v2Location + id3v2_tag.Header.CompleteTagSize;
			}
			else
				flacDataBegin = 0;

			// Look for an ID3v1 tag
			long id3v1_location = FindId3v1();

			if (id3v1_location >= 0)
			{
				id3v1_tag = new Id3v1Tag(this, id3v1_location);
				flacDataEnd = id3v1_location;
			}
			else
				flacDataEnd = Length;

			// Look for FLAC metadata, including vorbis comments

			xiph_comment_data = Scan(flacDataBegin, flacDataEnd);

			if (!IsValid) return;

			if (XiphCommentData.Count > 0)
				comment = new OggXiphComment(XiphCommentData);

			tag.SetTags(comment, id3v2_tag, id3v1_tag);

			FindFlacTag(TagTypes.Xiph, true);

			if (propertiesStyle != ReadStyle.None)
				properties = new FlacProperties(stream_info_data, stream_length, propertiesStyle);
		}
		public static Id3v2AttachedPictureFrame Find(Id3v2Tag tag, string description, PictureType type)
		{
			if (tag != null)
			{
				foreach (Id3v2AttachedPictureFrame frame in tag.GetFrames("APIC"))
					if (frame != null && frame.Description == description && frame.Type == type)
						return frame;
				return null;
			}
			else throw new ArgumentNullException("tag");
		}
Пример #5
0
		public bool Strip (TagTypes types, bool freeMemory)
		{
			FileAccessMode original_mode = Mode;
         
			if(IsReadOnly)
			{
				TagLibDebugger.Debug("Mpeg.File.Strip() - Cannot strip tags from a read only file.");
				return false;
			}
         
			try
			{
				Mode = FileAccessMode.Write;
			}
			catch (TagLibException)
			{
				TagLibDebugger.Debug("Mpeg.File.Strip() - Cannot strip tags from a read only file.");
				return false;
			}

			if ((types & TagTypes.Id3v2) != 0)
			{
				long id3v2_location = FindId3v2 ();
				if (id3v2_location >= 0)
				{
					Seek(id3v2_location);
					Id3v2Header header = new Id3v2Header (ReadBlock ((int)Id3v2Header.Size));
               
					if (header.TagSize == 0)
						TagLibDebugger.Debug ("Mpc.File.Save() -- Id3v2 header is broken. Ignoring.");
					else
						RemoveBlock (id3v2_location, (int) header.CompleteTagSize);
				}
            
				if (freeMemory)
					id3v2_tag = null;
			}

			long id3v1_location = FindId3v1 ();
         
			if ((types & TagTypes.Id3v1) != 0)
			{
				if (id3v1_location >= 0)
				{
					Truncate(id3v1_location);
					id3v1_location = -1;
				}
            
				if (freeMemory)
					id3v1_tag = null;
			}

			if ((types & TagTypes.Ape) != 0)
			{
				long ape_location = FindApe (id3v1_location >= 0);
				if (ape_location != -1)
				{
					Seek(ape_location);
					int ape_size = (int) (new ApeFooter(ReadBlock((int) ApeFooter.Size))).CompleteTagSize;
					ape_location = ape_location + ApeFooter.Size - ape_size;
					RemoveBlock(ape_location, ape_size);
				}
            
				if (freeMemory)
					ape_tag = null;
			}
         
			tag.SetTags(id3v2_tag, ape_tag, id3v1_tag);
         
			Mode = original_mode;
			return true;
		}
Пример #6
0
		private void Read(ReadStyle propertiesStyle)
		{
			// Look for an ID3v2 tag
			long id3v2_location = FindId3v2();

			if (id3v2_location >= 0)
				id3v2_tag = new Id3v2Tag(this, id3v2_location);


			// Look for an ID3v1 tag
			long id3v1_location = FindId3v1();

			if (id3v1_location >= 0)
				id3v1_tag = new Id3v1Tag(this, id3v1_location);


			// Look for an APE tag
			long ape_location = FindApe(id3v1_location >= 0);

			if (ape_location >= 0)
				ape_tag = new ApeTag(this, ape_location);


			tag.SetTags(id3v2_tag, ape_tag, id3v1_tag);

			FindMpegTag(TagTypes.Id3v2, true);

			if (propertiesStyle != ReadStyle.None)
				properties = new MpegProperties(this, propertiesStyle);
		}
		public static Id3v2CommentsFrame Find(Id3v2Tag tag, string description)
		{
			if (tag != null)
			{
				foreach (Id3v2CommentsFrame frame in tag.GetFrames("COMM"))
					if (frame != null && frame.Description == description)
						return frame;
				return null;
			}
			else throw new ArgumentNullException("tag");
		}
Пример #8
0
		public void Remove(TagTypes types)
		{
			if ((types & TagTypes.Id3v1) != 0)
				id3v1Tag = null;

			if ((types & TagTypes.Id3v2) != 0)
				id3v2Tag = null;

			if ((types & TagTypes.Ape) != 0)
				apeTag = null;

			tag.SetTags(apeTag, id3v2Tag, id3v1Tag);
		}
Пример #9
0
		private void Read(ReadStyle propertiesStyle)
		{
			// Look for an ID3v1 tag
			long id3v1Location = FindId3v1();

			if (id3v1Location >= 0)
			{
				id3v1Tag = new Id3v1Tag(this, id3v1Location);
			}


			// Look for an APE tag
			long apeLocation = FindApe(id3v1Location != 0);

			if (apeLocation >= 0)
				apeTag = new ApeTag(this, apeLocation);


			// Look for an ID3v2 tag
			long id3v2Location = FindId3v2();

			if (id3v2Location >= 0)
				id3v2Tag = new Id3v2Tag(this, id3v2Location);


			tag.SetTags(apeTag, id3v2Tag, id3v1Tag);
			FindMpcTag(TagTypes.Ape, true);


			// Look for MPC metadata
			Seek((id3v2Location >= 0) ? (id3v2Location + id3v2Tag.Header.CompleteTagSize) : 0);

			if (propertiesStyle != ReadStyle.None)
				properties = new MpcProperties(ReadBlock((int)MpcProperties.HeaderSize),
				   Length - Tell - apeTag.Footer.CompleteTagSize);
		}
Пример #10
0
        public bool Strip(TagTypes types, bool freeMemory)
        {
            FileAccessMode original_mode = Mode;

            if (IsReadOnly)
            {
                TagLibDebugger.Debug("Mpeg.File.Strip() - Cannot strip tags from a read only file.");
                return(false);
            }

            try
            {
                Mode = FileAccessMode.Write;
            }
            catch (TagLibException)
            {
                TagLibDebugger.Debug("Mpeg.File.Strip() - Cannot strip tags from a read only file.");
                return(false);
            }

            if ((types & TagTypes.Id3v2) != 0)
            {
                long id3v2_location = FindId3v2();
                if (id3v2_location >= 0)
                {
                    Seek(id3v2_location);
                    Id3v2Header header = new Id3v2Header(ReadBlock((int)Id3v2Header.Size));

                    if (header.TagSize == 0)
                    {
                        TagLibDebugger.Debug("Mpc.File.Save() -- Id3v2 header is broken. Ignoring.");
                    }
                    else
                    {
                        RemoveBlock(id3v2_location, (int)header.CompleteTagSize);
                    }
                }

                if (freeMemory)
                {
                    id3v2_tag = null;
                }
            }

            long id3v1_location = FindId3v1();

            if ((types & TagTypes.Id3v1) != 0)
            {
                if (id3v1_location >= 0)
                {
                    Truncate(id3v1_location);
                    id3v1_location = -1;
                }

                if (freeMemory)
                {
                    id3v1_tag = null;
                }
            }

            if ((types & TagTypes.Ape) != 0)
            {
                long ape_location = FindApe(id3v1_location >= 0);
                if (ape_location != -1)
                {
                    Seek(ape_location);
                    int ape_size = (int)(new ApeFooter(ReadBlock((int)ApeFooter.Size))).CompleteTagSize;
                    ape_location = ape_location + ApeFooter.Size - ape_size;
                    RemoveBlock(ape_location, ape_size);
                }

                if (freeMemory)
                {
                    ape_tag = null;
                }
            }

            tag.SetTags(id3v2_tag, ape_tag, id3v1_tag);

            Mode = original_mode;
            return(true);
        }
		public static Id3v2RelativeVolumeFrame Find(Id3v2Tag tag, string identification)
		{
			if (tag != null)
			{
				foreach (Id3v2RelativeVolumeFrame frame in tag.GetFrames("RVA2"))
				{
					if (frame != null && frame.Identification == identification)
						return frame;
				}
				return null;
			}
			else throw new ArgumentNullException("tag");
		}
Пример #12
0
		public static Id3v2PrivateFrame Find(Id3v2Tag tag, string owner)
		{
			if (tag != null)
			{
				foreach (Id3v2PrivateFrame frame in tag.GetFrames("PRIV"))
					if (frame != null && frame.Owner == owner)
						return frame;
				return null;
			}
			else throw new ArgumentNullException("tag");
		}