FFProbeVideoInfoProvider.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. using DvdLib.Ifo;
  2. using MediaBrowser.Controller.Configuration;
  3. using MediaBrowser.Controller.Entities;
  4. using MediaBrowser.Controller.Localization;
  5. using MediaBrowser.Controller.MediaInfo;
  6. using MediaBrowser.Controller.Persistence;
  7. using MediaBrowser.Controller.Providers;
  8. using MediaBrowser.Model.Entities;
  9. using MediaBrowser.Model.IO;
  10. using MediaBrowser.Model.Logging;
  11. using MediaBrowser.Model.MediaInfo;
  12. using MediaBrowser.Model.Serialization;
  13. using System;
  14. using System.Collections.Generic;
  15. using System.Globalization;
  16. using System.IO;
  17. using System.Linq;
  18. using System.Threading;
  19. using System.Threading.Tasks;
  20. namespace MediaBrowser.Providers.MediaInfo
  21. {
  22. /// <summary>
  23. /// Extracts video information using ffprobe
  24. /// </summary>
  25. public class FFProbeVideoInfoProvider : BaseFFProbeProvider<Video>
  26. {
  27. private readonly IItemRepository _itemRepo;
  28. public FFProbeVideoInfoProvider(IIsoManager isoManager, IBlurayExaminer blurayExaminer, IJsonSerializer jsonSerializer, ILogManager logManager, IServerConfigurationManager configurationManager, IMediaEncoder mediaEncoder, ILocalizationManager localization, IItemRepository itemRepo)
  29. : base(logManager, configurationManager, mediaEncoder, jsonSerializer)
  30. {
  31. if (isoManager == null)
  32. {
  33. throw new ArgumentNullException("isoManager");
  34. }
  35. if (blurayExaminer == null)
  36. {
  37. throw new ArgumentNullException("blurayExaminer");
  38. }
  39. _blurayExaminer = blurayExaminer;
  40. _localization = localization;
  41. _itemRepo = itemRepo;
  42. _isoManager = isoManager;
  43. }
  44. /// <summary>
  45. /// Gets or sets the bluray examiner.
  46. /// </summary>
  47. /// <value>The bluray examiner.</value>
  48. private readonly IBlurayExaminer _blurayExaminer;
  49. /// <summary>
  50. /// The _iso manager
  51. /// </summary>
  52. private readonly IIsoManager _isoManager;
  53. private readonly ILocalizationManager _localization;
  54. /// <summary>
  55. /// Returns true or false indicating if the provider should refresh when the contents of it's directory changes
  56. /// </summary>
  57. /// <value><c>true</c> if [refresh on file system stamp change]; otherwise, <c>false</c>.</value>
  58. protected override bool RefreshOnFileSystemStampChange
  59. {
  60. get
  61. {
  62. // Need this in case external subtitle files change
  63. return true;
  64. }
  65. }
  66. /// <summary>
  67. /// Gets the filestamp extensions.
  68. /// </summary>
  69. /// <value>The filestamp extensions.</value>
  70. protected override string[] FilestampExtensions
  71. {
  72. get
  73. {
  74. return new[] { ".srt", ".ssa", ".ass" };
  75. }
  76. }
  77. public override MetadataProviderPriority Priority
  78. {
  79. get
  80. {
  81. return MetadataProviderPriority.Second;
  82. }
  83. }
  84. /// <summary>
  85. /// Supports video files and dvd structures
  86. /// </summary>
  87. /// <param name="item">The item.</param>
  88. /// <returns><c>true</c> if XXXX, <c>false</c> otherwise</returns>
  89. public override bool Supports(BaseItem item)
  90. {
  91. if (item.LocationType != LocationType.FileSystem)
  92. {
  93. return false;
  94. }
  95. var video = item as Video;
  96. if (video != null)
  97. {
  98. if (video.VideoType == VideoType.Iso)
  99. {
  100. return _isoManager.CanMount(item.Path);
  101. }
  102. return video.VideoType == VideoType.VideoFile || video.VideoType == VideoType.Dvd || video.VideoType == VideoType.BluRay;
  103. }
  104. return false;
  105. }
  106. /// <summary>
  107. /// Called when [pre fetch].
  108. /// </summary>
  109. /// <param name="item">The item.</param>
  110. /// <param name="mount">The mount.</param>
  111. protected override void OnPreFetch(Video item, IIsoMount mount)
  112. {
  113. if (item.VideoType == VideoType.Iso)
  114. {
  115. item.IsoType = DetermineIsoType(mount);
  116. }
  117. if (item.VideoType == VideoType.Dvd || (item.IsoType.HasValue && item.IsoType == IsoType.Dvd))
  118. {
  119. FetchFromDvdLib(item, mount);
  120. }
  121. base.OnPreFetch(item, mount);
  122. }
  123. private void FetchFromDvdLib(Video item, IIsoMount mount)
  124. {
  125. var path = mount == null ? item.Path : mount.MountedPath;
  126. var dvd = new Dvd(path);
  127. item.RunTimeTicks = dvd.Titles.Select(GetRuntime).Max();
  128. var primaryTitle = dvd.Titles.OrderByDescending(GetRuntime).FirstOrDefault();
  129. uint? titleNumber = null;
  130. if (primaryTitle != null)
  131. {
  132. titleNumber = primaryTitle.TitleNumber;
  133. }
  134. item.PlayableStreamFileNames = GetPrimaryPlaylistVobFiles(item, mount, titleNumber)
  135. .Select(Path.GetFileName)
  136. .ToList();
  137. }
  138. private long GetRuntime(Title title)
  139. {
  140. return title.ProgramChains
  141. .Select(i => (TimeSpan)i.PlaybackTime)
  142. .Select(i => i.Ticks)
  143. .Sum();
  144. }
  145. public override async Task<bool> FetchAsync(BaseItem item, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken)
  146. {
  147. var video = (Video)item;
  148. var isoMount = await MountIsoIfNeeded(video, cancellationToken).ConfigureAwait(false);
  149. try
  150. {
  151. OnPreFetch(video, isoMount);
  152. // If we didn't find any satisfying the min length, just take them all
  153. if (video.VideoType == VideoType.Dvd || (video.IsoType.HasValue && video.IsoType == IsoType.Dvd))
  154. {
  155. if (video.PlayableStreamFileNames.Count == 0)
  156. {
  157. Logger.Error("No playable vobs found in dvd structure, skipping ffprobe.");
  158. SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
  159. return true;
  160. }
  161. }
  162. var result = await GetMediaInfo(item, isoMount, cancellationToken).ConfigureAwait(false);
  163. cancellationToken.ThrowIfCancellationRequested();
  164. NormalizeFFProbeResult(result);
  165. cancellationToken.ThrowIfCancellationRequested();
  166. await Fetch(video, force, providerInfo, cancellationToken, result, isoMount).ConfigureAwait(false);
  167. }
  168. finally
  169. {
  170. if (isoMount != null)
  171. {
  172. isoMount.Dispose();
  173. }
  174. }
  175. SetLastRefreshed(item, DateTime.UtcNow, providerInfo);
  176. return true;
  177. }
  178. /// <summary>
  179. /// Mounts the iso if needed.
  180. /// </summary>
  181. /// <param name="item">The item.</param>
  182. /// <param name="cancellationToken">The cancellation token.</param>
  183. /// <returns>IsoMount.</returns>
  184. protected override Task<IIsoMount> MountIsoIfNeeded(Video item, CancellationToken cancellationToken)
  185. {
  186. if (item.VideoType == VideoType.Iso)
  187. {
  188. return _isoManager.Mount(item.Path, cancellationToken);
  189. }
  190. return base.MountIsoIfNeeded(item, cancellationToken);
  191. }
  192. /// <summary>
  193. /// Determines the type of the iso.
  194. /// </summary>
  195. /// <param name="isoMount">The iso mount.</param>
  196. /// <returns>System.Nullable{IsoType}.</returns>
  197. private IsoType? DetermineIsoType(IIsoMount isoMount)
  198. {
  199. var folders = Directory.EnumerateDirectories(isoMount.MountedPath).Select(Path.GetFileName).ToList();
  200. if (folders.Contains("video_ts", StringComparer.OrdinalIgnoreCase))
  201. {
  202. return IsoType.Dvd;
  203. }
  204. if (folders.Contains("bdmv", StringComparer.OrdinalIgnoreCase))
  205. {
  206. return IsoType.BluRay;
  207. }
  208. return null;
  209. }
  210. private IEnumerable<string> GetPrimaryPlaylistVobFiles(Video video, IIsoMount isoMount, uint? titleNumber)
  211. {
  212. // min size 300 mb
  213. const long minPlayableSize = 314572800;
  214. var root = isoMount != null ? isoMount.MountedPath : video.Path;
  215. // Try to eliminate menus and intros by skipping all files at the front of the list that are less than the minimum size
  216. // Once we reach a file that is at least the minimum, return all subsequent ones
  217. var allVobs = Directory.EnumerateFiles(root, "*", SearchOption.AllDirectories)
  218. .Where(file => string.Equals(Path.GetExtension(file), ".vob", StringComparison.OrdinalIgnoreCase))
  219. .ToList();
  220. // If we didn't find any satisfying the min length, just take them all
  221. if (allVobs.Count == 0)
  222. {
  223. Logger.Error("No vobs found in dvd structure.");
  224. return new List<string>();
  225. }
  226. if (titleNumber.HasValue)
  227. {
  228. var prefix = string.Format("VTS_0{0}_", titleNumber.Value.ToString(UsCulture));
  229. var vobs = allVobs.Where(i => Path.GetFileName(i).StartsWith(prefix, StringComparison.OrdinalIgnoreCase)).ToList();
  230. if (vobs.Count > 0)
  231. {
  232. return vobs;
  233. }
  234. Logger.Debug("Could not determine vob file list for {0} using DvdLib. Will scan using file sizes.", video.Path);
  235. }
  236. var files = allVobs
  237. .SkipWhile(f => new FileInfo(f).Length < minPlayableSize)
  238. .ToList();
  239. // If we didn't find any satisfying the min length, just take them all
  240. if (files.Count == 0)
  241. {
  242. Logger.Warn("Vob size filter resulted in zero matches. Taking all vobs.");
  243. files = allVobs;
  244. }
  245. // Assuming they're named "vts_05_01", take all files whose second part matches that of the first file
  246. if (files.Count > 0)
  247. {
  248. var parts = Path.GetFileNameWithoutExtension(files[0]).Split('_');
  249. if (parts.Length == 3)
  250. {
  251. var title = parts[1];
  252. files = files.TakeWhile(f =>
  253. {
  254. var fileParts = Path.GetFileNameWithoutExtension(f).Split('_');
  255. return fileParts.Length == 3 && string.Equals(title, fileParts[1], StringComparison.OrdinalIgnoreCase);
  256. }).ToList();
  257. // If this resulted in not getting any vobs, just take them all
  258. if (files.Count == 0)
  259. {
  260. Logger.Warn("Vob filename filter resulted in zero matches. Taking all vobs.");
  261. files = allVobs;
  262. }
  263. }
  264. }
  265. return files;
  266. }
  267. /// <summary>
  268. /// Fetches the specified video.
  269. /// </summary>
  270. /// <param name="video">The video.</param>
  271. /// <param name="force">if set to <c>true</c> [force].</param>
  272. /// <param name="cancellationToken">The cancellation token.</param>
  273. /// <param name="data">The data.</param>
  274. /// <param name="isoMount">The iso mount.</param>
  275. /// <returns>Task.</returns>
  276. protected async Task Fetch(Video video, bool force, BaseProviderInfo providerInfo, CancellationToken cancellationToken, InternalMediaInfoResult data, IIsoMount isoMount)
  277. {
  278. if (data.format != null)
  279. {
  280. // For dvd's this may not always be accurate, so don't set the runtime if the item already has one
  281. var needToSetRuntime = video.VideoType != VideoType.Dvd || video.RunTimeTicks == null || video.RunTimeTicks.Value == 0;
  282. if (needToSetRuntime && !string.IsNullOrEmpty(data.format.duration))
  283. {
  284. video.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration, UsCulture)).Ticks;
  285. }
  286. }
  287. var mediaStreams = MediaEncoderHelpers.GetMediaInfo(data).MediaStreams;
  288. var chapters = data.Chapters ?? new List<ChapterInfo>();
  289. if (video.VideoType == VideoType.BluRay || (video.IsoType.HasValue && video.IsoType.Value == IsoType.BluRay))
  290. {
  291. var inputPath = isoMount != null ? isoMount.MountedPath : video.Path;
  292. FetchBdInfo(video, chapters, mediaStreams, inputPath, cancellationToken);
  293. }
  294. AddExternalSubtitles(video, mediaStreams);
  295. FetchWtvInfo(video, force, data);
  296. video.IsHD = mediaStreams.Any(i => i.Type == MediaStreamType.Video && i.Width.HasValue && i.Width.Value >= 1270);
  297. if (chapters.Count == 0 && mediaStreams.Any(i => i.Type == MediaStreamType.Video))
  298. {
  299. AddDummyChapters(video, chapters);
  300. }
  301. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  302. video.VideoBitRate = videoStream == null ? null : videoStream.BitRate;
  303. video.DefaultVideoStreamIndex = videoStream == null ? (int?)null : videoStream.Index;
  304. video.HasSubtitles = mediaStreams.Any(i => i.Type == MediaStreamType.Subtitle);
  305. await FFMpegManager.Instance.PopulateChapterImages(video, chapters, false, false, cancellationToken).ConfigureAwait(false);
  306. var videoFileChanged = CompareDate(video) > providerInfo.LastRefreshed;
  307. await _itemRepo.SaveMediaStreams(video.Id, mediaStreams, cancellationToken).ConfigureAwait(false);
  308. // Only save chapters if forcing, if the video changed, or if there are not already any saved ones
  309. if (force || videoFileChanged || _itemRepo.GetChapter(video.Id, 0) == null)
  310. {
  311. await _itemRepo.SaveChapters(video.Id, chapters, cancellationToken).ConfigureAwait(false);
  312. }
  313. }
  314. /// <summary>
  315. /// Fetches the WTV info.
  316. /// </summary>
  317. /// <param name="video">The video.</param>
  318. /// <param name="force">if set to <c>true</c> [force].</param>
  319. /// <param name="data">The data.</param>
  320. private void FetchWtvInfo(Video video, bool force, InternalMediaInfoResult data)
  321. {
  322. if (data.format == null || data.format.tags == null)
  323. {
  324. return;
  325. }
  326. if (force || video.Genres.Count == 0)
  327. {
  328. if (!video.LockedFields.Contains(MetadataFields.Genres))
  329. {
  330. var genres = GetDictionaryValue(data.format.tags, "genre");
  331. if (!string.IsNullOrEmpty(genres))
  332. {
  333. video.Genres = genres.Split(new[] { ';', '/', ',' }, StringSplitOptions.RemoveEmptyEntries)
  334. .Where(i => !string.IsNullOrWhiteSpace(i))
  335. .Select(i => i.Trim())
  336. .ToList();
  337. }
  338. }
  339. }
  340. if (force || string.IsNullOrEmpty(video.Overview))
  341. {
  342. if (!video.LockedFields.Contains(MetadataFields.Overview))
  343. {
  344. var overview = GetDictionaryValue(data.format.tags, "WM/SubTitleDescription");
  345. if (!string.IsNullOrWhiteSpace(overview))
  346. {
  347. video.Overview = overview;
  348. }
  349. }
  350. }
  351. if (force || string.IsNullOrEmpty(video.OfficialRating))
  352. {
  353. var officialRating = GetDictionaryValue(data.format.tags, "WM/ParentalRating");
  354. if (!string.IsNullOrWhiteSpace(officialRating))
  355. {
  356. if (!video.LockedFields.Contains(MetadataFields.OfficialRating))
  357. {
  358. video.OfficialRating = officialRating;
  359. }
  360. }
  361. }
  362. if (force || video.People.Count == 0)
  363. {
  364. if (!video.LockedFields.Contains(MetadataFields.Cast))
  365. {
  366. var people = GetDictionaryValue(data.format.tags, "WM/MediaCredits");
  367. if (!string.IsNullOrEmpty(people))
  368. {
  369. video.People = people.Split(new[] { ';', '/' }, StringSplitOptions.RemoveEmptyEntries)
  370. .Where(i => !string.IsNullOrWhiteSpace(i))
  371. .Select(i => new PersonInfo { Name = i.Trim(), Type = PersonType.Actor })
  372. .ToList();
  373. }
  374. }
  375. }
  376. if (force || !video.ProductionYear.HasValue)
  377. {
  378. var year = GetDictionaryValue(data.format.tags, "WM/OriginalReleaseTime");
  379. if (!string.IsNullOrWhiteSpace(year))
  380. {
  381. int val;
  382. if (int.TryParse(year, NumberStyles.Integer, UsCulture, out val))
  383. {
  384. video.ProductionYear = val;
  385. }
  386. }
  387. }
  388. }
  389. /// <summary>
  390. /// Adds the external subtitles.
  391. /// </summary>
  392. /// <param name="video">The video.</param>
  393. /// <param name="currentStreams">The current streams.</param>
  394. private void AddExternalSubtitles(Video video, List<MediaStream> currentStreams)
  395. {
  396. var useParent = !video.ResolveArgs.IsDirectory;
  397. if (useParent && video.Parent == null)
  398. {
  399. return;
  400. }
  401. var fileSystemChildren = useParent
  402. ? video.Parent.ResolveArgs.FileSystemChildren
  403. : video.ResolveArgs.FileSystemChildren;
  404. var startIndex = currentStreams.Count;
  405. var streams = new List<MediaStream>();
  406. var videoFileNameWithoutExtension = Path.GetFileNameWithoutExtension(video.Path);
  407. foreach (var file in fileSystemChildren
  408. .Where(f => !f.Attributes.HasFlag(FileAttributes.Directory) && FilestampExtensions.Contains(Path.GetExtension(f.FullName), StringComparer.OrdinalIgnoreCase)))
  409. {
  410. var fullName = file.FullName;
  411. var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fullName);
  412. // If the subtitle file matches the video file name
  413. if (string.Equals(videoFileNameWithoutExtension, fileNameWithoutExtension, StringComparison.OrdinalIgnoreCase))
  414. {
  415. streams.Add(new MediaStream
  416. {
  417. Index = startIndex++,
  418. Type = MediaStreamType.Subtitle,
  419. IsExternal = true,
  420. Path = fullName,
  421. Codec = Path.GetExtension(fullName).ToLower().TrimStart('.')
  422. });
  423. }
  424. else if (fileNameWithoutExtension.StartsWith(videoFileNameWithoutExtension + ".", StringComparison.OrdinalIgnoreCase))
  425. {
  426. // Support xbmc naming conventions - 300.spanish.srt
  427. var language = fileNameWithoutExtension.Split('.').LastOrDefault();
  428. // Try to translate to three character code
  429. // Be flexible and check against both the full and three character versions
  430. var culture = _localization.GetCultures()
  431. .FirstOrDefault(i => string.Equals(i.DisplayName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.Name, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.ThreeLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase) || string.Equals(i.TwoLetterISOLanguageName, language, StringComparison.OrdinalIgnoreCase));
  432. if (culture != null)
  433. {
  434. language = culture.ThreeLetterISOLanguageName;
  435. }
  436. streams.Add(new MediaStream
  437. {
  438. Index = startIndex++,
  439. Type = MediaStreamType.Subtitle,
  440. IsExternal = true,
  441. Path = fullName,
  442. Codec = Path.GetExtension(fullName).ToLower().TrimStart('.'),
  443. Language = language
  444. });
  445. }
  446. }
  447. currentStreams.AddRange(streams);
  448. }
  449. /// <summary>
  450. /// The dummy chapter duration
  451. /// </summary>
  452. private readonly long _dummyChapterDuration = TimeSpan.FromMinutes(5).Ticks;
  453. /// <summary>
  454. /// Adds the dummy chapters.
  455. /// </summary>
  456. /// <param name="video">The video.</param>
  457. /// <param name="chapters">The chapters.</param>
  458. private void AddDummyChapters(Video video, List<ChapterInfo> chapters)
  459. {
  460. var runtime = video.RunTimeTicks ?? 0;
  461. if (runtime < 0)
  462. {
  463. throw new ArgumentException(string.Format("{0} has invalid runtime of {1}", video.Name, runtime));
  464. }
  465. if (runtime < _dummyChapterDuration)
  466. {
  467. return;
  468. }
  469. long currentChapterTicks = 0;
  470. var index = 1;
  471. // Limit to 100 chapters just in case there's some incorrect metadata here
  472. while (currentChapterTicks < runtime && index < 100)
  473. {
  474. chapters.Add(new ChapterInfo
  475. {
  476. Name = "Chapter " + index,
  477. StartPositionTicks = currentChapterTicks
  478. });
  479. index++;
  480. currentChapterTicks += _dummyChapterDuration;
  481. }
  482. }
  483. /// <summary>
  484. /// Fetches the bd info.
  485. /// </summary>
  486. /// <param name="item">The item.</param>
  487. /// <param name="chapters">The chapters.</param>
  488. /// <param name="mediaStreams">The media streams.</param>
  489. /// <param name="inputPath">The input path.</param>
  490. /// <param name="cancellationToken">The cancellation token.</param>
  491. private void FetchBdInfo(BaseItem item, List<ChapterInfo> chapters, List<MediaStream> mediaStreams, string inputPath, CancellationToken cancellationToken)
  492. {
  493. var video = (Video)item;
  494. var result = GetBDInfo(inputPath);
  495. cancellationToken.ThrowIfCancellationRequested();
  496. int? currentHeight = null;
  497. int? currentWidth = null;
  498. int? currentBitRate = null;
  499. var videoStream = mediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video);
  500. // Grab the values that ffprobe recorded
  501. if (videoStream != null)
  502. {
  503. currentBitRate = videoStream.BitRate;
  504. currentWidth = videoStream.Width;
  505. currentHeight = videoStream.Height;
  506. }
  507. // Fill video properties from the BDInfo result
  508. Fetch(video, mediaStreams, result, chapters);
  509. videoStream = mediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video);
  510. // Use the ffprobe values if these are empty
  511. if (videoStream != null)
  512. {
  513. videoStream.BitRate = IsEmpty(videoStream.BitRate) ? currentBitRate : videoStream.BitRate;
  514. videoStream.Width = IsEmpty(videoStream.Width) ? currentWidth : videoStream.Width;
  515. videoStream.Height = IsEmpty(videoStream.Height) ? currentHeight : videoStream.Height;
  516. }
  517. }
  518. /// <summary>
  519. /// Determines whether the specified num is empty.
  520. /// </summary>
  521. /// <param name="num">The num.</param>
  522. /// <returns><c>true</c> if the specified num is empty; otherwise, <c>false</c>.</returns>
  523. private bool IsEmpty(int? num)
  524. {
  525. return !num.HasValue || num.Value == 0;
  526. }
  527. /// <summary>
  528. /// Fills video properties from the VideoStream of the largest playlist
  529. /// </summary>
  530. /// <param name="video">The video.</param>
  531. /// <param name="mediaStreams">The media streams.</param>
  532. /// <param name="stream">The stream.</param>
  533. /// <param name="chapters">The chapters.</param>
  534. private void Fetch(Video video, List<MediaStream> mediaStreams, BlurayDiscInfo stream, List<ChapterInfo> chapters)
  535. {
  536. // Check all input for null/empty/zero
  537. mediaStreams.Clear();
  538. mediaStreams.AddRange(stream.MediaStreams);
  539. video.MainFeaturePlaylistName = stream.PlaylistName;
  540. if (stream.RunTimeTicks.HasValue && stream.RunTimeTicks.Value > 0)
  541. {
  542. video.RunTimeTicks = stream.RunTimeTicks;
  543. }
  544. video.PlayableStreamFileNames = stream.Files.ToList();
  545. if (stream.Chapters != null)
  546. {
  547. chapters.Clear();
  548. chapters.AddRange(stream.Chapters.Select(c => new ChapterInfo
  549. {
  550. StartPositionTicks = TimeSpan.FromSeconds(c).Ticks
  551. }));
  552. }
  553. }
  554. /// <summary>
  555. /// Gets information about the longest playlist on a bdrom
  556. /// </summary>
  557. /// <param name="path">The path.</param>
  558. /// <returns>VideoStream.</returns>
  559. private BlurayDiscInfo GetBDInfo(string path)
  560. {
  561. return _blurayExaminer.GetDiscInfo(path);
  562. }
  563. }
  564. }