Exemple #1
0
 /// <summary>
 ///    Constructs and initializes a new instance of <see
 ///    cref="SynchronisedLyricsFrame" /> with a specified
 ///    description, ISO-639-2 language code, and text type.
 /// </summary>
 /// <param name="description">
 ///    A <see cref="string" /> object containing the description
 ///    of the new instnace.
 /// </param>
 /// <param name="language">
 ///    A <see cref="string" /> object containing the ISO-639-2
 ///    language code of the new instance.
 /// </param>
 /// <param name="type">
 ///    A <see cref="SynchedTextType" /> containing the type of
 ///    text to be stored in the new instance.
 /// </param>
 /// <remarks>
 ///    When a frame is created, it is not automatically added to
 ///    the tag. Consider using <see cref="Get" /> for more
 ///    integrated frame creation.
 /// </remarks>
 public SynchronisedLyricsFrame(string description,
                                string language,
                                SynchedTextType type)
     : this(description, language, type,
            TagLib.Id3v2.Tag.DefaultEncoding)
 {
 }
 public SynchronisedLyricsFrame (string description, string language, SynchedTextType type, StringType encoding) : base (FrameType.SYLT, 4)
 {
    this.text_encoding = encoding;
    this.language      = language;
    this.description   = description;
    this.lyrics_type   = type;
 }
Exemple #3
0
 public SynchronisedLyricsFrame(string description, string language, SynchedTextType type, StringType encoding) : base(FrameType.SYLT, 4)
 {
     this.text_encoding = encoding;
     this.language      = language;
     this.description   = description;
     this.lyrics_type   = type;
 }
 public static SynchronisedLyricsFrame Get(TagLib.Id3v2.Tag tag, string description, string language, SynchedTextType type, bool create)
 {
     IEnumerator<Frame> enumerator = tag.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             Frame current = enumerator.Current;
             SynchronisedLyricsFrame frame2 = current as SynchronisedLyricsFrame;
             if (((frame2 != null) && ((frame2.Description == description) && ((language == null) || (language == frame2.Language)))) && (type == frame2.Type))
             {
                 return frame2;
             }
         }
     }
     finally
     {
         if (enumerator == null)
         {
         }
         enumerator.Dispose();
     }
     if (!create)
     {
         return null;
     }
     SynchronisedLyricsFrame frame3 = new SynchronisedLyricsFrame(description, language, type);
     tag.AddFrame(frame3);
     return frame3;
 }
Exemple #5
0
        /// <summary>
        ///    Gets a specified lyrics frame from the specified tag,
        ///    trying to to match the description and language but
        ///    accepting an incomplete match.
        /// </summary>
        /// <param name="tag">
        ///    A <see cref="Tag" /> object to search in.
        /// </param>
        /// <param name="description">
        ///    A <see cref="string" /> object specifying the description
        ///    to match.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> object specifying the ISO-639-2
        ///    language code to match.
        /// </param>
        /// <param name="type">
        ///    A <see cref="SynchedTextType" /> value specifying the
        ///    text type to match.
        /// </param>
        /// <returns>
        ///    A <see cref="SynchronisedLyricsFrame" /> object
        ///    containing the matching frame, or <see langword="null" />
        ///    if a match wasn't found.
        /// </returns>
        /// <remarks>
        ///    <para>The method tries matching with the following order
        ///    of precidence:</para>
        ///    <list type="number">
        ///       <item><term>The first frame with a matching
        ///       description, language, and type.</term></item>
        ///       <item><term>The first frame with a matching
        ///       description and language.</term></item>
        ///       <item><term>The first frame with a matching
        ///       language.</term></item>
        ///       <item><term>The first frame with a matching
        ///       description.</term></item>
        ///       <item><term>The first frame with a matching
        ///       type.</term></item>
        ///       <item><term>The first frame.</term></item>
        ///    </list>
        /// </remarks>
        public static SynchronisedLyricsFrame GetPreferred(Tag tag,
                                                           string description,
                                                           string language,
                                                           SynchedTextType type)
        {
            // This is weird, so bear with me. The best thing we can
            // have is something straightforward and in our own
            // language. If it has a description, then it is
            // probably used for something other than an actual
            // comment. If that doesn't work, we'd still rather have
            // something in our language than something in another.
            // After that all we have left are things in other
            // languages, so we'd rather have one with actual
            // content, so we try to get one with no description
            // first.

            int best_value = -1;
            SynchronisedLyricsFrame best_frame = null;

            foreach (Frame f in tag)
            {
                SynchronisedLyricsFrame cf =
                    f as SynchronisedLyricsFrame;

                if (cf == null)
                {
                    continue;
                }

                int value = 0;
                if (cf.Language == language)
                {
                    value += 4;
                }
                if (cf.Description == description)
                {
                    value += 2;
                }
                if (cf.Type == type)
                {
                    value += 1;
                }

                if (value == 7)
                {
                    return(cf);
                }

                if (value <= best_value)
                {
                    continue;
                }

                best_value = value;
                best_frame = cf;
            }

            return(best_frame);
        }
Exemple #6
0
        /// <summary>
        ///    Populates the values in the current instance by parsing
        ///    its field data in a specified version.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the
        ///    extracted field data.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> indicating the ID3v2 version the
        ///    field data is encoded in.
        /// </param>
        protected override void ParseFields(ByteVector data,
                                            byte version)
        {
            if (data.Count < 6)
            {
                throw new CorruptFileException(
                          "Not enough bytes in field.");
            }

            encoding         = (StringType)data [0];
            language         = data.ToString(StringType.Latin1, 1, 3);
            timestamp_format = (TimestampFormat)data [4];
            lyrics_type      = (SynchedTextType)data [5];

            ByteVector delim = ByteVector.TextDelimiter(
                encoding);
            int delim_index = data.Find(delim, 6, delim.Count);

            if (delim_index < 0)
            {
                throw new CorruptFileException(
                          "Text delimiter expected.");
            }

            description = data.ToString(encoding, 6,
                                        delim_index - 6);

            int offset           = delim_index + delim.Count;
            List <SynchedText> l = new List <SynchedText> ();

            while (offset + delim.Count + 4 < data.Count)
            {
                delim_index = data.Find(delim, offset,
                                        delim.Count);

                if (delim_index < offset)
                {
                    throw new CorruptFileException(
                              "Text delimiter expected.");
                }

                string text = data.ToString(encoding, offset,
                                            delim_index - offset);
                offset = delim_index + delim.Count;

                if (offset + 4 > data.Count)
                {
                    break;
                }

                l.Add(new SynchedText(data.Mid(offset, 4)
                                      .ToUInt(), text));
                offset += 4;
            }

            this.text = l.ToArray();
        }
 public SynchronisedLyricsFrame(string description, string language, SynchedTextType type, StringType encoding) : base(FrameType.SYLT, 4)
 {
     this.encoding = TagLib.Id3v2.Tag.DefaultEncoding;
     this.text = new SynchedText[0];
     this.encoding = encoding;
     this.language = language;
     this.description = description;
     this.lyrics_type = type;
 }
 public static SynchronisedLyricsFrame GetPreferred(TagLib.Id3v2.Tag tag, string description, string language, SynchedTextType type)
 {
     int num = -1;
     SynchronisedLyricsFrame frame = null;
     IEnumerator<Frame> enumerator = tag.GetEnumerator();
     try
     {
         while (enumerator.MoveNext())
         {
             Frame current = enumerator.Current;
             SynchronisedLyricsFrame frame3 = current as SynchronisedLyricsFrame;
             if (frame3 != null)
             {
                 int num2 = 0;
                 if (frame3.Language == language)
                 {
                     num2 += 4;
                 }
                 if (frame3.Description == description)
                 {
                     num2 += 2;
                 }
                 if (frame3.Type == type)
                 {
                     num2++;
                 }
                 if (num2 == 7)
                 {
                     return frame3;
                 }
                 if (num2 > num)
                 {
                     num = num2;
                     frame = frame3;
                 }
             }
         }
     }
     finally
     {
         if (enumerator == null)
         {
         }
         enumerator.Dispose();
     }
     return frame;
 }
Exemple #9
0
        /// <summary>
        ///    Gets a specified lyrics 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" /> object specifying the description
        ///    to match.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> object specifying the ISO-639-2
        ///    language code to match.
        /// </param>
        /// <param name="type">
        ///    A <see cref="SynchedTextType" /> value specifying the
        ///    text 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="SynchronisedLyricsFrame" /> object
        ///    containing the matching frame, or <see langword="null" />
        ///    if a match wasn't found and <paramref name="create" /> is
        ///    <see langword="false" />.
        /// </returns>
        public static SynchronisedLyricsFrame Get(Tag tag,
                                                  string description,
                                                  string language,
                                                  SynchedTextType type,
                                                  bool create)
        {
            foreach (Frame f in tag)
            {
                SynchronisedLyricsFrame lyr =
                    f as SynchronisedLyricsFrame;

                if (lyr == null)
                {
                    continue;
                }

                if (lyr.Description == description &&
                    (language == null ||
                     language == lyr.Language) &&
                    type == lyr.Type)
                {
                    return(lyr);
                }
            }

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

            SynchronisedLyricsFrame frame =
                new SynchronisedLyricsFrame(description,
                                            language, type);

            tag.AddFrame(frame);
            return(frame);
        }
        /// <summary>
        ///    Populates the values in the current instance by parsing
        ///    its field data in a specified version.
        /// </summary>
        /// <param name="data">
        ///    A <see cref="ByteVector" /> object containing the
        ///    extracted field data.
        /// </param>
        /// <param name="version">
        ///    A <see cref="byte" /> indicating the ID3v2 version the
        ///    field data is encoded in.
        /// </param>
        protected override void ParseFields(ByteVector data,
            byte version)
        {
            if (data.Count < 6)
                throw new CorruptFileException (
                    "Not enough bytes in field.");

            encoding = (StringType) data [0];
            language = data.ToString (StringType.Latin1, 1, 3);
            timestamp_format = (TimestampFormat) data [4];
            lyrics_type = (SynchedTextType) data [5];

            ByteVector delim = ByteVector.TextDelimiter (
                encoding);
            int delim_index = data.Find (delim, 6, delim.Count);

            if (delim_index < 0)
                throw new CorruptFileException (
                    "Text delimiter expected.");

            description = data.ToString (encoding, 6,
                delim_index - 6);

            int offset = delim_index + delim.Count;
            List<SynchedText> l = new List<SynchedText> ();

            while (offset + delim.Count + 4 < data.Count) {
                delim_index = data.Find (delim, offset,
                    delim.Count);

                if (delim_index < offset)
                    throw new CorruptFileException (
                        "Text delimiter expected.");

                string text = data.ToString (encoding, offset,
                    delim_index - offset);
                offset = delim_index + delim.Count;

                if (offset + 4 > data.Count)
                    break;

                l.Add (new SynchedText (data.Mid (offset, 4)
                    .ToUInt (), text));
                offset += 4;
            }

            this.text = l.ToArray ();
        }
        /// <summary>
        ///    Gets a specified lyrics frame from the specified tag,
        ///    trying to to match the description and language but
        ///    accepting an incomplete match.
        /// </summary>
        /// <param name="tag">
        ///    A <see cref="Tag" /> object to search in.
        /// </param>
        /// <param name="description">
        ///    A <see cref="string" /> object specifying the description
        ///    to match.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> object specifying the ISO-639-2
        ///    language code to match.
        /// </param>
        /// <param name="type">
        ///    A <see cref="SynchedTextType" /> value specifying the
        ///    text type to match.
        /// </param>
        /// <returns>
        ///    A <see cref="SynchronisedLyricsFrame" /> object
        ///    containing the matching frame, or <see langword="null" />
        ///    if a match wasn't found.
        /// </returns>
        /// <remarks>
        ///    <para>The method tries matching with the following order
        ///    of precidence:</para>
        ///    <list type="number">
        ///       <item><term>The first frame with a matching
        ///       description, language, and type.</term></item>
        ///       <item><term>The first frame with a matching
        ///       description and language.</term></item>
        ///       <item><term>The first frame with a matching
        ///       language.</term></item>
        ///       <item><term>The first frame with a matching
        ///       description.</term></item>
        ///       <item><term>The first frame with a matching
        ///       type.</term></item>
        ///       <item><term>The first frame.</term></item>
        ///    </list>
        /// </remarks>
        public static SynchronisedLyricsFrame GetPreferred(Tag tag,
            string description,
            string language,
            SynchedTextType type)
        {
            // This is weird, so bear with me. The best thing we can
            // have is something straightforward and in our own
            // language. If it has a description, then it is
            // probably used for something other than an actual
            // comment. If that doesn't work, we'd still rather have
            // something in our language than something in another.
            // After that all we have left are things in other
            // languages, so we'd rather have one with actual
            // content, so we try to get one with no description
            // first.

            int best_value = -1;
            SynchronisedLyricsFrame best_frame = null;

            foreach (Frame f in tag) {
                SynchronisedLyricsFrame cf =
                    f as SynchronisedLyricsFrame;

                if (cf == null)
                    continue;

                int value = 0;
                if (cf.Language == language)
                    value += 4;
                if (cf.Description == description)
                    value += 2;
                if (cf.Type == type)
                    value += 1;

                if (value == 7)
                    return cf;

                if (value <= best_value)
                    continue;

                best_value = value;
                best_frame = cf;
            }

            return best_frame;
        }
        /// <summary>
        ///    Gets a specified lyrics 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" /> object specifying the description
        ///    to match.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> object specifying the ISO-639-2
        ///    language code to match.
        /// </param>
        /// <param name="type">
        ///    A <see cref="SynchedTextType" /> value specifying the
        ///    text 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="SynchronisedLyricsFrame" /> object
        ///    containing the matching frame, or <see langword="null" />
        ///    if a match wasn't found and <paramref name="create" /> is
        ///    <see langword="false" />.
        /// </returns>
        public static SynchronisedLyricsFrame Get(Tag tag,
            string description,
            string language,
            SynchedTextType type,
            bool create)
        {
            foreach (Frame f in tag) {
                SynchronisedLyricsFrame lyr =
                    f as SynchronisedLyricsFrame;

                if (lyr == null)
                    continue;

                if (lyr.Description == description &&
                    (language == null ||
                        language == lyr.Language) &&
                    type == lyr.Type)
                    return lyr;
            }

            if (!create)
                return null;

            SynchronisedLyricsFrame frame =
                new SynchronisedLyricsFrame (description,
                    language, type);
            tag.AddFrame (frame);
            return frame;
        }
        /// <summary>
        ///    Constructs and initializes a new instance of <see
        ///    cref="SynchronisedLyricsFrame" /> with a specified
        ///    description, ISO-639-2 language code, and text type.
        /// </summary>
        /// <param name="description">
        ///    A <see cref="string" /> object containing the description
        ///    of the new instnace.
        /// </param>
        /// <param name="language">
        ///    A <see cref="string" /> object containing the ISO-639-2
        ///    language code of the new instance.
        /// </param>
        /// <param name="type">
        ///    A <see cref="SynchedTextType" /> containing the type of
        ///    text to be stored in the new instance.
        /// </param>
        /// <remarks>
        ///    When a frame is created, it is not automatically added to
        ///    the tag. Consider using <see cref="Get" /> for more
        ///    integrated frame creation.
        /// </remarks>
        public SynchronisedLyricsFrame(string description,
            string language,
            SynchedTextType type)
            : this(description, language, type,
				TagLib.Id3v2.Tag.DefaultEncoding)
        {
        }
 protected override void ParseFields(ByteVector data, byte version)
 {
     if (data.Count < 6)
     {
         throw new CorruptFileException("Not enough bytes in field.");
     }
     this.encoding = (StringType) data[0];
     this.language = data.ToString(StringType.Latin1, 1, 3);
     this.timestamp_format = (TimestampFormat) data[4];
     this.lyrics_type = (SynchedTextType) data[5];
     ByteVector pattern = ByteVector.TextDelimiter(this.encoding);
     int num = data.Find(pattern, 6, pattern.Count);
     if (num < 0)
     {
         throw new CorruptFileException("Text delimiter expected.");
     }
     this.description = data.ToString(this.encoding, 6, num - 6);
     int offset = num + pattern.Count;
     List<SynchedText> list = new List<SynchedText>();
     while (((offset + pattern.Count) + 4) < data.Count)
     {
         num = data.Find(pattern, offset, pattern.Count);
         if (num < offset)
         {
             throw new CorruptFileException("Text delimiter expected.");
         }
         string text = data.ToString(this.encoding, offset, num - offset);
         offset = num + pattern.Count;
         if ((offset + 4) > data.Count)
         {
             break;
         }
         list.Add(new SynchedText((long) data.Mid(offset, 4).ToUInt(), text));
         offset += 4;
     }
     this.text = list.ToArray();
 }
Exemple #15
0
        public static SynchronisedLyricsFrame GetPreferred(Tag tag, string description, string language, SynchedTextType type)
        {
            int best_value = -1;
            SynchronisedLyricsFrame best_frame = null;

            foreach (Frame f in tag)
            {
                SynchronisedLyricsFrame cf = f as SynchronisedLyricsFrame;
                if (cf == null)
                {
                    continue;
                }
                int value = 0;
                if (cf.Language == language)
                {
                    value += 4;
                }
                if (cf.Description == description)
                {
                    value += 2;
                }
                if (cf.Type == type)
                {
                    value += 1;
                }
                if (value == 7)
                {
                    return(cf);
                }
                if (value <= best_value)
                {
                    continue;
                }
                best_value = value;
                best_frame = cf;
            }
            return(best_frame);
        }