Пример #1
0
        ////------------------------------------------------------------------------------------------------------------------------------
        /// <inheritdoc/>
        public IAudioTagOffset ReadFromStream(Stream stream, TagOrigin tagOrigin)
        {
            if (stream == null)
                throw new ArgumentNullException("stream");

            if (!stream.CanRead)
                throw new InvalidOperationException("stream can not be read");

            if (!stream.CanSeek)
                throw new InvalidOperationException("stream can not be seeked");

            // This tag can only be located at the end; the header does not contain a size field, so we're not able to calculate the end.
            if (tagOrigin == TagOrigin.Start)
                return null;

            StreamBuffer sb = stream as StreamBuffer ?? new StreamBuffer(stream);
            Lyrics3Tag tag = new Lyrics3Tag { Encoding = Encoding };
            long footerOffset = FindFooterIdentifier(sb);
            if (footerOffset < 0)
                return null;

            sb.Position = Math.Max(footerOffset - Lyrics3Tag.MaxLyricsSize, 0);
            long headerOffset = FindHeaderIdentifier(sb);
            if (headerOffset < 0)
                return null;

            // Read lyrics
            int lyricsLength = (int)(footerOffset - (headerOffset + HeaderIdentifierBytes.Length));
            string lyrics = sb.ReadString(lyricsLength);
            tag.Lyrics = GetLyrics(lyrics);

            // Read footer
            sb.ReadString(FooterIdentifierBytes.Length);

            return new AudioTagOffset(tagOrigin, headerOffset, footerOffset, tag);
        }
Пример #2
0
        /// <summary>
        /// Equals the specified <see cref="Lyrics3Tag"/>.
        /// </summary>
        /// <param name="tag">The <see cref="Lyrics3Tag"/>.</param>
        /// <returns>true if equal; false otherwise.</returns>
        public bool Equals(Lyrics3Tag tag)
        {
            if (ReferenceEquals(null, tag))
                return false;

            if (ReferenceEquals(this, tag))
                return true;

            return String.Equals(tag.Lyrics, Lyrics, StringComparison.OrdinalIgnoreCase);
        }