/// <summary> /// Converts an ID3 tag to another version after resolving the differences between the two versions. The resultant tag /// will have all the frames from the source tag, but those frames not recognized in the new version will be treated as /// UnknownFrame objects. /// Similarly, frames recognized in the output tag version, but not in the source version are converted accordingly. /// </summary> /// <param name="version">Version of the tag to convert to.</param> /// <returns>The converted tag of the specified version, or null if there were any errors.</returns> public Id3Tag ConvertTo(Id3Version version) { //If the requested version is the same as this version, just return the same instance. if (Version == version) { return(this); } //Get the ID3 tag handlers for the destination and create a empty tag var destinationHandler = Id3Handler.GetHandler(version); Id3Tag destinationTag = destinationHandler.CreateTag(); foreach (Id3Frame sourceFrame in this) { if (sourceFrame is UnknownFrame unknownFrame) { string frameId = unknownFrame.Id; Id3Frame destinationFrame = destinationHandler.GetFrameFromFrameId(frameId); destinationTag.AddUntypedFrame(destinationFrame); } else { destinationTag.AddUntypedFrame(sourceFrame); } } return(destinationTag); }
/// <summary> /// Retrieves the specified tag data as a byte array. This method does not attempt to read the tag data, it simply /// reads the header and if present the tag bytes are read directly from the stream. This means that typical exceptions /// that get thrown in a tag read will not occur in this method. /// </summary> /// <param name="version">The tag version number.</param> /// <returns>A byte array of the tag data.</returns> public byte[] GetTagBytes(Id3Version version) { Id3Handler handler = ExistingHandlers.FirstOrDefault(h => h.Version == version); byte[] tagBytes = handler?.GetTagBytes(Stream); return(tagBytes); }
public Id3Tag GetTag(Id3Version version, out object additionalData) { Id3Handler handler = ExistingHandlers.FirstOrDefault(h => h.Version == version); if (handler != null) { return(handler.ReadTag(Stream, out additionalData)); } additionalData = null; return(null); }
/// <summary> /// Deletes the ID3 tag of the specified version from the MP3 data. /// </summary> /// <param name="version">The tag version</param> public void DeleteTag(Id3Version version) { EnsureWritePermissions(Mp3Messages.NoWritePermissions_CannotDeleteTag); Id3Handler handler = ExistingHandlers.FirstOrDefault(h => h.Version == version); if (handler != null) { handler.DeleteTag(Stream); InvalidateExistingHandlers(); } }
public bool WriteTag(Id3Tag tag, Id3Version version, WriteConflictAction conflictAction = WriteConflictAction.NoAction) { tag.Version = version; return(WriteTag(tag, conflictAction)); }
public bool HasTagOfVersion(Id3Version version) => ExistingHandlers.Any(h => h.Version == version);
/// <summary> /// Retrieves an ID3 tag of the specified version number. /// </summary> /// <param name="version">The tag version number.</param> /// <returns>The ID3 tag of the specified version number, or null if it doesn't exist.</returns> public Id3Tag GetTag(Id3Version version) { Id3Handler handler = ExistingHandlers.FirstOrDefault(h => h.Version == version); return(handler?.ReadTag(Stream, out _)); }
internal Id3HandlerMetadata(Id3Version version, Id3TagFamily family, Type type) { Version = version; Family = family; Type = type; }
/// <summary> /// Returns the ID3 tag handler for the specified tag version. /// </summary> /// <param name="version">Version of ID3 tag</param> /// <returns>The tag handler for the specified version or null if it is not in the collection.</returns> internal static Id3Handler GetHandler(Id3Version version) { Id3HandlerMetadata foundHandler = AvailableHandlers.First(ah => ah.Version == version); return(foundHandler.Instance); }