コード例 #1
0
        /// <summary>
        /// Parses the extended information line into a Playlist entry.
        /// </summary>
        /// <param name="target">The target.</param>
        /// <param name="line">The line.</param>
        public static void BeginExtendedInfoLine(this PlaylistEntry target, string line)
        {
            var result     = new PlaylistEntry();
            var lineData   = line.Substring($"{Playlist.EntryPrefix}:".Length).Trim();
            var attributes = lineData.ParseAttributes();

            foreach (var attribute in attributes)
            {
                lineData = lineData.Replace(attribute.Substring, string.Empty);
                target.Attributes[attribute.Key] = attribute.Value;
            }

            lineData = lineData.Trim();
            var headerFields = lineData.Split(',');

            if (headerFields.Length >= 1 && long.TryParse(headerFields[0].Trim(), out long duration))
            {
                target.Duration = TimeSpan.FromSeconds(Convert.ToDouble(duration));
            }

            if (headerFields.Length >= 2)
            {
                target.Title = headerFields[1].Trim();
            }
        }
コード例 #2
0
        /// <summary>
        /// Parses the extended information line into a Playlist entry.
        /// </summary>
        /// <param name="entry">The playlist entry item to parse data into.</param>
        /// <param name="line">The line of text.</param>
        public static void BeginExtendedInfoLine(this PlaylistEntry entry, string line)
        {
            // Get the line of text removing the start of the line data
            var entryAttributesText = line.Substring($"{PlaylistEntryCollection.EntryPrefix}:".Length).Trim();
            var entryAttributes     = entryAttributesText.ParseAttributes();

            foreach (var attribute in entryAttributes)
            {
                entryAttributesText             = entryAttributesText.ReplaceOrdinal(attribute.Substring, string.Empty);
                entry.Attributes[attribute.Key] = attribute.Value;
            }

            // We need to further parse the data beyond the attributes
            // so we parse the left-over text.
            entryAttributesText = entryAttributesText.Trim();

            // The extra fields are comma-separated
            var headerFields = entryAttributesText.Split(',');

            // The first field is the duration
            if (headerFields.Length >= 1 && long.TryParse(headerFields[0].Trim(), out var duration))
            {
                entry.Duration = TimeSpan.FromSeconds(Convert.ToDouble(duration));
            }

            // The next field is the title
            if (headerFields.Length >= 2)
            {
                entry.Title = headerFields[1].Trim();
            }
        }