/// <summary> /// Adds the chapters. /// </summary> /// <param name="result">The result.</param> /// <param name="standardError">The standard error.</param> private void AddChapters(MediaInfoResult result, string standardError) { var lines = standardError.Split('\n').Select(l => l.TrimStart()); var chapters = new List<ChapterInfo>(); ChapterInfo lastChapter = null; foreach (var line in lines) { if (line.StartsWith("Chapter", StringComparison.OrdinalIgnoreCase)) { // Example: // Chapter #0.2: start 400.534, end 4565.435 const string srch = "start "; var start = line.IndexOf(srch, StringComparison.OrdinalIgnoreCase); if (start == -1) { continue; } var subString = line.Substring(start + srch.Length); subString = subString.Substring(0, subString.IndexOf(',')); double seconds; if (double.TryParse(subString, NumberStyles.Any, UsCulture, out seconds)) { lastChapter = new ChapterInfo { StartPositionTicks = TimeSpan.FromSeconds(seconds).Ticks }; chapters.Add(lastChapter); } } else if (line.StartsWith("title", StringComparison.OrdinalIgnoreCase)) { if (lastChapter != null && string.IsNullOrEmpty(lastChapter.Name)) { var index = line.IndexOf(':'); if (index != -1) { lastChapter.Name = line.Substring(index + 1).Trim().TrimEnd('\r'); } } } } result.Chapters = chapters; }
private ChapterInfo GetChapterInfo(MediaChapter chapter) { var info = new ChapterInfo(); if (chapter.tags != null) { string name; if (chapter.tags.TryGetValue("title", out name)) { info.Name = name; } } // Limit accuracy to milliseconds to match xml saving var secondsString = chapter.start_time; double seconds; if (double.TryParse(secondsString, NumberStyles.Any, CultureInfo.InvariantCulture, out seconds)) { var ms = Math.Round(TimeSpan.FromSeconds(seconds).TotalMilliseconds); info.StartPositionTicks = TimeSpan.FromMilliseconds(ms).Ticks; } return info; }
/// <summary> /// Gets the chapter. /// </summary> /// <param name="reader">The reader.</param> /// <returns>ChapterInfo.</returns> private ChapterInfo GetChapter(IDataReader reader) { var chapter = new ChapterInfo { StartPositionTicks = reader.GetInt64(0) }; if (!reader.IsDBNull(1)) { chapter.Name = reader.GetString(1); } if (!reader.IsDBNull(2)) { chapter.ImagePath = reader.GetString(2); } return chapter; }
/// <summary> /// Gets chapters for an item /// </summary> /// <param name="id">The id.</param> /// <returns>IEnumerable{ChapterInfo}.</returns> /// <exception cref="System.ArgumentNullException">id</exception> public IEnumerable<ChapterInfo> GetChapters(Guid id) { if (id == Guid.Empty) { throw new ArgumentNullException("id"); } using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "select StartPositionTicks,Name,ImagePath from Chapters where ItemId = @ItemId order by ChapterIndex asc"; cmd.Parameters.Add("@ItemId", DbType.Guid).Value = id; using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess | CommandBehavior.SingleResult)) { while (reader.Read()) { var chapter = new ChapterInfo { StartPositionTicks = reader.GetInt64(0) }; if (!reader.IsDBNull(1)) { chapter.Name = reader.GetString(1); } if (!reader.IsDBNull(2)) { chapter.ImagePath = reader.GetString(2); } yield return chapter; } } } }
/// <summary> /// Gets the chapter info dto. /// </summary> /// <param name="chapterInfo">The chapter info.</param> /// <param name="item">The item.</param> /// <returns>ChapterInfoDto.</returns> private ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item) { var dto = new ChapterInfoDto { Name = chapterInfo.Name, StartPositionTicks = chapterInfo.StartPositionTicks }; if (!string.IsNullOrEmpty(chapterInfo.ImagePath)) { dto.ImageTag = GetImageCacheTag(item, ImageType.Chapter, chapterInfo.ImagePath); } return dto; }
/// <summary> /// Gets the chapter info dto. /// </summary> /// <param name="chapterInfo">The chapter info.</param> /// <param name="item">The item.</param> /// <returns>ChapterInfoDto.</returns> private ChapterInfoDto GetChapterInfoDto(ChapterInfo chapterInfo, BaseItem item) { var dto = new ChapterInfoDto { Name = chapterInfo.Name, StartPositionTicks = chapterInfo.StartPositionTicks }; if (!string.IsNullOrEmpty(chapterInfo.ImagePath)) { dto.ImageTag = GetImageCacheTag(item, new ItemImageInfo { Path = chapterInfo.ImagePath, Type = ImageType.Chapter, DateModified = _fileSystem.GetLastWriteTimeUtc(chapterInfo.ImagePath) }); } return dto; }
/// <summary> /// Gets the chapter. /// </summary> /// <param name="reader">The reader.</param> /// <returns>ChapterInfo.</returns> private ChapterInfo GetChapter(IDataReader reader) { var chapter = new ChapterInfo { StartPositionTicks = reader.GetInt64(0) }; if (!reader.IsDBNull(1)) { chapter.Name = reader.GetString(1); } if (!reader.IsDBNull(2)) { chapter.ImagePath = reader.GetString(2); } if (!reader.IsDBNull(3)) { chapter.ImageDateModified = reader.GetDateTime(3).ToUniversalTime(); } return chapter; }