FFProbeVideoInfo.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637
  1. #pragma warning disable CS1591
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Globalization;
  5. using System.IO;
  6. using System.Linq;
  7. using System.Threading;
  8. using System.Threading.Tasks;
  9. using DvdLib.Ifo;
  10. using MediaBrowser.Common.Configuration;
  11. using MediaBrowser.Controller.Chapters;
  12. using MediaBrowser.Controller.Configuration;
  13. using MediaBrowser.Controller.Entities;
  14. using MediaBrowser.Controller.Entities.Movies;
  15. using MediaBrowser.Controller.Entities.TV;
  16. using MediaBrowser.Controller.Library;
  17. using MediaBrowser.Controller.MediaEncoding;
  18. using MediaBrowser.Controller.Persistence;
  19. using MediaBrowser.Controller.Providers;
  20. using MediaBrowser.Controller.Subtitles;
  21. using MediaBrowser.Model.Configuration;
  22. using MediaBrowser.Model.Dlna;
  23. using MediaBrowser.Model.Dto;
  24. using MediaBrowser.Model.Entities;
  25. using MediaBrowser.Model.Globalization;
  26. using MediaBrowser.Model.MediaInfo;
  27. using MediaBrowser.Model.Providers;
  28. using Microsoft.Extensions.Logging;
  29. namespace MediaBrowser.Providers.MediaInfo
  30. {
  31. public class FFProbeVideoInfo
  32. {
  33. private readonly ILogger _logger;
  34. private readonly IMediaEncoder _mediaEncoder;
  35. private readonly IItemRepository _itemRepo;
  36. private readonly IBlurayExaminer _blurayExaminer;
  37. private readonly ILocalizationManager _localization;
  38. private readonly IEncodingManager _encodingManager;
  39. private readonly IServerConfigurationManager _config;
  40. private readonly ISubtitleManager _subtitleManager;
  41. private readonly IChapterManager _chapterManager;
  42. private readonly ILibraryManager _libraryManager;
  43. private readonly IMediaSourceManager _mediaSourceManager;
  44. private readonly long _dummyChapterDuration = TimeSpan.FromMinutes(5).Ticks;
  45. public FFProbeVideoInfo(
  46. ILogger logger,
  47. IMediaSourceManager mediaSourceManager,
  48. IMediaEncoder mediaEncoder,
  49. IItemRepository itemRepo,
  50. IBlurayExaminer blurayExaminer,
  51. ILocalizationManager localization,
  52. IEncodingManager encodingManager,
  53. IServerConfigurationManager config,
  54. ISubtitleManager subtitleManager,
  55. IChapterManager chapterManager,
  56. ILibraryManager libraryManager)
  57. {
  58. _logger = logger;
  59. _mediaEncoder = mediaEncoder;
  60. _itemRepo = itemRepo;
  61. _blurayExaminer = blurayExaminer;
  62. _localization = localization;
  63. _encodingManager = encodingManager;
  64. _config = config;
  65. _subtitleManager = subtitleManager;
  66. _chapterManager = chapterManager;
  67. _libraryManager = libraryManager;
  68. _mediaSourceManager = mediaSourceManager;
  69. }
  70. public async Task<ItemUpdateType> ProbeVideo<T>(
  71. T item,
  72. MetadataRefreshOptions options,
  73. CancellationToken cancellationToken)
  74. where T : Video
  75. {
  76. BlurayDiscInfo blurayDiscInfo = null;
  77. Model.MediaInfo.MediaInfo mediaInfoResult = null;
  78. if (!item.IsShortcut || options.EnableRemoteContentProbe)
  79. {
  80. string[] streamFileNames = null;
  81. if (item.VideoType == VideoType.Dvd)
  82. {
  83. streamFileNames = FetchFromDvdLib(item);
  84. if (streamFileNames.Length == 0)
  85. {
  86. _logger.LogError("No playable vobs found in dvd structure, skipping ffprobe.");
  87. return ItemUpdateType.MetadataImport;
  88. }
  89. }
  90. else if (item.VideoType == VideoType.BluRay)
  91. {
  92. var inputPath = item.Path;
  93. blurayDiscInfo = GetBDInfo(inputPath);
  94. streamFileNames = blurayDiscInfo.Files;
  95. if (streamFileNames.Length == 0)
  96. {
  97. _logger.LogError("No playable vobs found in bluray structure, skipping ffprobe.");
  98. return ItemUpdateType.MetadataImport;
  99. }
  100. }
  101. if (streamFileNames == null)
  102. {
  103. streamFileNames = Array.Empty<string>();
  104. }
  105. mediaInfoResult = await GetMediaInfo(item, streamFileNames, cancellationToken).ConfigureAwait(false);
  106. cancellationToken.ThrowIfCancellationRequested();
  107. }
  108. await Fetch(item, cancellationToken, mediaInfoResult, blurayDiscInfo, options).ConfigureAwait(false);
  109. return ItemUpdateType.MetadataImport;
  110. }
  111. private Task<Model.MediaInfo.MediaInfo> GetMediaInfo(
  112. Video item,
  113. string[] streamFileNames,
  114. CancellationToken cancellationToken)
  115. {
  116. cancellationToken.ThrowIfCancellationRequested();
  117. var path = item.Path;
  118. var protocol = item.PathProtocol ?? MediaProtocol.File;
  119. if (item.IsShortcut)
  120. {
  121. path = item.ShortcutPath;
  122. protocol = _mediaSourceManager.GetPathProtocol(path);
  123. }
  124. return _mediaEncoder.GetMediaInfo(
  125. new MediaInfoRequest
  126. {
  127. PlayableStreamFileNames = streamFileNames,
  128. ExtractChapters = true,
  129. MediaType = DlnaProfileType.Video,
  130. MediaSource = new MediaSourceInfo
  131. {
  132. Path = path,
  133. Protocol = protocol,
  134. VideoType = item.VideoType
  135. }
  136. },
  137. cancellationToken);
  138. }
  139. protected async Task Fetch(
  140. Video video,
  141. CancellationToken cancellationToken,
  142. Model.MediaInfo.MediaInfo mediaInfo,
  143. BlurayDiscInfo blurayInfo,
  144. MetadataRefreshOptions options)
  145. {
  146. List<MediaStream> mediaStreams;
  147. IReadOnlyList<MediaAttachment> mediaAttachments;
  148. ChapterInfo[] chapters;
  149. if (mediaInfo != null)
  150. {
  151. mediaStreams = mediaInfo.MediaStreams;
  152. mediaAttachments = mediaInfo.MediaAttachments;
  153. video.TotalBitrate = mediaInfo.Bitrate;
  154. // video.FormatName = (mediaInfo.Container ?? string.Empty)
  155. // .Replace("matroska", "mkv", StringComparison.OrdinalIgnoreCase);
  156. // For dvd's this may not always be accurate, so don't set the runtime if the item already has one
  157. var needToSetRuntime = video.VideoType != VideoType.Dvd || video.RunTimeTicks == null || video.RunTimeTicks.Value == 0;
  158. if (needToSetRuntime)
  159. {
  160. video.RunTimeTicks = mediaInfo.RunTimeTicks;
  161. }
  162. video.Size = mediaInfo.Size;
  163. if (video.VideoType == VideoType.VideoFile)
  164. {
  165. var extension = (Path.GetExtension(video.Path) ?? string.Empty).TrimStart('.');
  166. video.Container = extension;
  167. }
  168. else
  169. {
  170. video.Container = null;
  171. }
  172. video.Container = mediaInfo.Container;
  173. chapters = mediaInfo.Chapters == null ? Array.Empty<ChapterInfo>() : mediaInfo.Chapters;
  174. if (blurayInfo != null)
  175. {
  176. FetchBdInfo(video, ref chapters, mediaStreams, blurayInfo);
  177. }
  178. }
  179. else
  180. {
  181. mediaStreams = new List<MediaStream>();
  182. mediaAttachments = Array.Empty<MediaAttachment>();
  183. chapters = Array.Empty<ChapterInfo>();
  184. }
  185. await AddExternalSubtitles(video, mediaStreams, options, cancellationToken).ConfigureAwait(false);
  186. var libraryOptions = _libraryManager.GetLibraryOptions(video);
  187. if (mediaInfo != null)
  188. {
  189. FetchEmbeddedInfo(video, mediaInfo, options, libraryOptions);
  190. FetchPeople(video, mediaInfo, options);
  191. video.Timestamp = mediaInfo.Timestamp;
  192. video.Video3DFormat ??= mediaInfo.Video3DFormat;
  193. }
  194. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  195. video.Height = videoStream?.Height ?? 0;
  196. video.Width = videoStream?.Width ?? 0;
  197. video.DefaultVideoStreamIndex = videoStream == null ? (int?)null : videoStream.Index;
  198. video.HasSubtitles = mediaStreams.Any(i => i.Type == MediaStreamType.Subtitle);
  199. _itemRepo.SaveMediaStreams(video.Id, mediaStreams, cancellationToken);
  200. _itemRepo.SaveMediaAttachments(video.Id, mediaAttachments, cancellationToken);
  201. if (options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh ||
  202. options.MetadataRefreshMode == MetadataRefreshMode.Default)
  203. {
  204. if (chapters.Length == 0 && mediaStreams.Any(i => i.Type == MediaStreamType.Video))
  205. {
  206. chapters = CreateDummyChapters(video);
  207. }
  208. NormalizeChapterNames(chapters);
  209. var extractDuringScan = false;
  210. if (libraryOptions != null)
  211. {
  212. extractDuringScan = libraryOptions.ExtractChapterImagesDuringLibraryScan;
  213. }
  214. await _encodingManager.RefreshChapterImages(video, options.DirectoryService, chapters, extractDuringScan, false, cancellationToken).ConfigureAwait(false);
  215. _chapterManager.SaveChapters(video.Id, chapters);
  216. }
  217. }
  218. private void NormalizeChapterNames(ChapterInfo[] chapters)
  219. {
  220. for (int i = 0; i < chapters.Length; i++)
  221. {
  222. string name = chapters[i].Name;
  223. // Check if the name is empty and/or if the name is a time
  224. // Some ripping programs do that.
  225. if (string.IsNullOrWhiteSpace(name) ||
  226. TimeSpan.TryParse(name, out _))
  227. {
  228. chapters[i].Name = string.Format(
  229. CultureInfo.InvariantCulture,
  230. _localization.GetLocalizedString("ChapterNameValue"),
  231. (i + 1).ToString(CultureInfo.InvariantCulture));
  232. }
  233. }
  234. }
  235. private void FetchBdInfo(BaseItem item, ref ChapterInfo[] chapters, List<MediaStream> mediaStreams, BlurayDiscInfo blurayInfo)
  236. {
  237. var video = (Video)item;
  238. // video.PlayableStreamFileNames = blurayInfo.Files.ToList();
  239. // Use BD Info if it has multiple m2ts. Otherwise, treat it like a video file and rely more on ffprobe output
  240. if (blurayInfo.Files.Length > 1)
  241. {
  242. int? currentHeight = null;
  243. int? currentWidth = null;
  244. int? currentBitRate = null;
  245. var videoStream = mediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video);
  246. // Grab the values that ffprobe recorded
  247. if (videoStream != null)
  248. {
  249. currentBitRate = videoStream.BitRate;
  250. currentWidth = videoStream.Width;
  251. currentHeight = videoStream.Height;
  252. }
  253. // Fill video properties from the BDInfo result
  254. mediaStreams.Clear();
  255. mediaStreams.AddRange(blurayInfo.MediaStreams);
  256. if (blurayInfo.RunTimeTicks.HasValue && blurayInfo.RunTimeTicks.Value > 0)
  257. {
  258. video.RunTimeTicks = blurayInfo.RunTimeTicks;
  259. }
  260. if (blurayInfo.Chapters != null)
  261. {
  262. double[] brChapter = blurayInfo.Chapters;
  263. chapters = new ChapterInfo[brChapter.Length];
  264. for (int i = 0; i < brChapter.Length; i++)
  265. {
  266. chapters[i] = new ChapterInfo
  267. {
  268. StartPositionTicks = TimeSpan.FromSeconds(brChapter[i]).Ticks
  269. };
  270. }
  271. }
  272. videoStream = mediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video);
  273. // Use the ffprobe values if these are empty
  274. if (videoStream != null)
  275. {
  276. videoStream.BitRate = IsEmpty(videoStream.BitRate) ? currentBitRate : videoStream.BitRate;
  277. videoStream.Width = IsEmpty(videoStream.Width) ? currentWidth : videoStream.Width;
  278. videoStream.Height = IsEmpty(videoStream.Height) ? currentHeight : videoStream.Height;
  279. }
  280. }
  281. }
  282. private bool IsEmpty(int? num)
  283. {
  284. return !num.HasValue || num.Value == 0;
  285. }
  286. /// <summary>
  287. /// Gets information about the longest playlist on a bdrom.
  288. /// </summary>
  289. /// <param name="path">The path.</param>
  290. /// <returns>VideoStream.</returns>
  291. private BlurayDiscInfo GetBDInfo(string path)
  292. {
  293. if (string.IsNullOrWhiteSpace(path))
  294. {
  295. throw new ArgumentNullException(nameof(path));
  296. }
  297. try
  298. {
  299. return _blurayExaminer.GetDiscInfo(path);
  300. }
  301. catch (Exception ex)
  302. {
  303. _logger.LogError(ex, "Error getting BDInfo");
  304. return null;
  305. }
  306. }
  307. private void FetchEmbeddedInfo(Video video, Model.MediaInfo.MediaInfo data, MetadataRefreshOptions refreshOptions, LibraryOptions libraryOptions)
  308. {
  309. var isFullRefresh = refreshOptions.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;
  310. if (!video.IsLocked && !video.LockedFields.Contains(MetadataField.OfficialRating))
  311. {
  312. if (!string.IsNullOrWhiteSpace(data.OfficialRating) || isFullRefresh)
  313. {
  314. video.OfficialRating = data.OfficialRating;
  315. }
  316. }
  317. if (!video.IsLocked && !video.LockedFields.Contains(MetadataField.Genres))
  318. {
  319. if (video.Genres.Length == 0 || isFullRefresh)
  320. {
  321. video.Genres = Array.Empty<string>();
  322. foreach (var genre in data.Genres)
  323. {
  324. video.AddGenre(genre);
  325. }
  326. }
  327. }
  328. if (!video.IsLocked && !video.LockedFields.Contains(MetadataField.Studios))
  329. {
  330. if (video.Studios.Length == 0 || isFullRefresh)
  331. {
  332. video.SetStudios(data.Studios);
  333. }
  334. }
  335. if (data.ProductionYear.HasValue)
  336. {
  337. if (!video.ProductionYear.HasValue || isFullRefresh)
  338. {
  339. video.ProductionYear = data.ProductionYear;
  340. }
  341. }
  342. if (data.PremiereDate.HasValue)
  343. {
  344. if (!video.PremiereDate.HasValue || isFullRefresh)
  345. {
  346. video.PremiereDate = data.PremiereDate;
  347. }
  348. }
  349. if (data.IndexNumber.HasValue)
  350. {
  351. if (!video.IndexNumber.HasValue || isFullRefresh)
  352. {
  353. video.IndexNumber = data.IndexNumber;
  354. }
  355. }
  356. if (data.ParentIndexNumber.HasValue)
  357. {
  358. if (!video.ParentIndexNumber.HasValue || isFullRefresh)
  359. {
  360. video.ParentIndexNumber = data.ParentIndexNumber;
  361. }
  362. }
  363. if (!video.IsLocked && !video.LockedFields.Contains(MetadataField.Name))
  364. {
  365. if (!string.IsNullOrWhiteSpace(data.Name) && libraryOptions.EnableEmbeddedTitles)
  366. {
  367. // Don't use the embedded name for extras because it will often be the same name as the movie
  368. if (!video.ExtraType.HasValue)
  369. {
  370. video.Name = data.Name;
  371. }
  372. }
  373. }
  374. // If we don't have a ProductionYear try and get it from PremiereDate
  375. if (video.PremiereDate.HasValue && !video.ProductionYear.HasValue)
  376. {
  377. video.ProductionYear = video.PremiereDate.Value.ToLocalTime().Year;
  378. }
  379. if (!video.IsLocked && !video.LockedFields.Contains(MetadataField.Overview))
  380. {
  381. if (string.IsNullOrWhiteSpace(video.Overview) || isFullRefresh)
  382. {
  383. video.Overview = data.Overview;
  384. }
  385. }
  386. }
  387. private void FetchPeople(Video video, Model.MediaInfo.MediaInfo data, MetadataRefreshOptions options)
  388. {
  389. var isFullRefresh = options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;
  390. if (!video.IsLocked && !video.LockedFields.Contains(MetadataField.Cast))
  391. {
  392. if (isFullRefresh || _libraryManager.GetPeople(video).Count == 0)
  393. {
  394. var people = new List<PersonInfo>();
  395. foreach (var person in data.People)
  396. {
  397. PeopleHelper.AddPerson(people, new PersonInfo
  398. {
  399. Name = person.Name,
  400. Type = person.Type,
  401. Role = person.Role
  402. });
  403. }
  404. _libraryManager.UpdatePeople(video, people);
  405. }
  406. }
  407. }
  408. private SubtitleOptions GetOptions()
  409. {
  410. return _config.GetConfiguration<SubtitleOptions>("subtitles");
  411. }
  412. /// <summary>
  413. /// Adds the external subtitles.
  414. /// </summary>
  415. /// <param name="video">The video.</param>
  416. /// <param name="currentStreams">The current streams.</param>
  417. /// <param name="options">The refreshOptions.</param>
  418. /// <param name="cancellationToken">The cancellation token.</param>
  419. /// <returns>Task.</returns>
  420. private async Task AddExternalSubtitles(
  421. Video video,
  422. List<MediaStream> currentStreams,
  423. MetadataRefreshOptions options,
  424. CancellationToken cancellationToken)
  425. {
  426. var subtitleResolver = new SubtitleResolver(_localization);
  427. var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1);
  428. var externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, false);
  429. var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.Default ||
  430. options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;
  431. var subtitleOptions = GetOptions();
  432. var libraryOptions = _libraryManager.GetLibraryOptions(video);
  433. string[] subtitleDownloadLanguages;
  434. bool skipIfEmbeddedSubtitlesPresent;
  435. bool skipIfAudioTrackMatches;
  436. bool requirePerfectMatch;
  437. bool enabled;
  438. if (libraryOptions.SubtitleDownloadLanguages == null)
  439. {
  440. subtitleDownloadLanguages = subtitleOptions.DownloadLanguages;
  441. skipIfEmbeddedSubtitlesPresent = subtitleOptions.SkipIfEmbeddedSubtitlesPresent;
  442. skipIfAudioTrackMatches = subtitleOptions.SkipIfAudioTrackMatches;
  443. requirePerfectMatch = subtitleOptions.RequirePerfectMatch;
  444. enabled = (subtitleOptions.DownloadEpisodeSubtitles &&
  445. video is Episode) ||
  446. (subtitleOptions.DownloadMovieSubtitles &&
  447. video is Movie);
  448. }
  449. else
  450. {
  451. subtitleDownloadLanguages = libraryOptions.SubtitleDownloadLanguages;
  452. skipIfEmbeddedSubtitlesPresent = libraryOptions.SkipSubtitlesIfEmbeddedSubtitlesPresent;
  453. skipIfAudioTrackMatches = libraryOptions.SkipSubtitlesIfAudioTrackMatches;
  454. requirePerfectMatch = libraryOptions.RequirePerfectSubtitleMatch;
  455. enabled = true;
  456. }
  457. if (enableSubtitleDownloading && enabled)
  458. {
  459. var downloadedLanguages = await new SubtitleDownloader(
  460. _logger,
  461. _subtitleManager).DownloadSubtitles(
  462. video,
  463. currentStreams.Concat(externalSubtitleStreams).ToList(),
  464. skipIfEmbeddedSubtitlesPresent,
  465. skipIfAudioTrackMatches,
  466. requirePerfectMatch,
  467. subtitleDownloadLanguages,
  468. libraryOptions.DisabledSubtitleFetchers,
  469. libraryOptions.SubtitleFetcherOrder,
  470. cancellationToken).ConfigureAwait(false);
  471. // Rescan
  472. if (downloadedLanguages.Count > 0)
  473. {
  474. externalSubtitleStreams = subtitleResolver.GetExternalSubtitleStreams(video, startIndex, options.DirectoryService, true);
  475. }
  476. }
  477. video.SubtitleFiles = externalSubtitleStreams.Select(i => i.Path).ToArray();
  478. currentStreams.AddRange(externalSubtitleStreams);
  479. }
  480. /// <summary>
  481. /// Creates dummy chapters.
  482. /// </summary>
  483. /// <param name="video">The video.</param>
  484. /// <returns>An array of dummy chapters.</returns>
  485. private ChapterInfo[] CreateDummyChapters(Video video)
  486. {
  487. var runtime = video.RunTimeTicks ?? 0;
  488. if (runtime < 0)
  489. {
  490. throw new ArgumentException(
  491. string.Format(
  492. CultureInfo.InvariantCulture,
  493. "{0} has invalid runtime of {1}",
  494. video.Name,
  495. runtime));
  496. }
  497. if (runtime < _dummyChapterDuration)
  498. {
  499. return Array.Empty<ChapterInfo>();
  500. }
  501. // Limit to 100 chapters just in case there's some incorrect metadata here
  502. int chapterCount = (int)Math.Min(runtime / _dummyChapterDuration, 100);
  503. var chapters = new ChapterInfo[chapterCount];
  504. long currentChapterTicks = 0;
  505. for (int i = 0; i < chapterCount; i++)
  506. {
  507. chapters[i] = new ChapterInfo
  508. {
  509. StartPositionTicks = currentChapterTicks
  510. };
  511. currentChapterTicks += _dummyChapterDuration;
  512. }
  513. return chapters;
  514. }
  515. private string[] FetchFromDvdLib(Video item)
  516. {
  517. var path = item.Path;
  518. var dvd = new Dvd(path);
  519. var primaryTitle = dvd.Titles.OrderByDescending(GetRuntime).FirstOrDefault();
  520. byte? titleNumber = null;
  521. if (primaryTitle != null)
  522. {
  523. titleNumber = primaryTitle.VideoTitleSetNumber;
  524. item.RunTimeTicks = GetRuntime(primaryTitle);
  525. }
  526. return _mediaEncoder.GetPrimaryPlaylistVobFiles(item.Path, null, titleNumber)
  527. .Select(Path.GetFileName)
  528. .ToArray();
  529. }
  530. private long GetRuntime(Title title)
  531. {
  532. return title.ProgramChains
  533. .Select(i => (TimeSpan)i.PlaybackTime)
  534. .Select(i => i.Ticks)
  535. .Sum();
  536. }
  537. }
  538. }