Video.cs 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734
  1. using MediaBrowser.Controller.Library;
  2. using MediaBrowser.Controller.Persistence;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Controller.Resolvers;
  5. using MediaBrowser.Model.Dto;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.MediaInfo;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Runtime.Serialization;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace MediaBrowser.Controller.Entities
  17. {
  18. /// <summary>
  19. /// Class Video
  20. /// </summary>
  21. public class Video : BaseItem,
  22. IHasAspectRatio,
  23. IHasTags,
  24. ISupportsPlaceHolders,
  25. IHasMediaSources,
  26. IHasShortOverview,
  27. IHasPreferredMetadataLanguage,
  28. IThemeMedia
  29. {
  30. public bool IsMultiPart { get; set; }
  31. public bool HasLocalAlternateVersions { get; set; }
  32. public Guid? PrimaryVersionId { get; set; }
  33. public List<Guid> AdditionalPartIds { get; set; }
  34. public List<Guid> LocalAlternateVersionIds { get; set; }
  35. public bool IsThemeMedia { get; set; }
  36. public string FormatName { get; set; }
  37. public long? Size { get; set; }
  38. public string Container { get; set; }
  39. public int? TotalBitrate { get; set; }
  40. public string ShortOverview { get; set; }
  41. public ExtraType ExtraType { get; set; }
  42. /// <summary>
  43. /// Gets or sets the preferred metadata country code.
  44. /// </summary>
  45. /// <value>The preferred metadata country code.</value>
  46. public string PreferredMetadataCountryCode { get; set; }
  47. public string PreferredMetadataLanguage { get; set; }
  48. /// <summary>
  49. /// Gets or sets the timestamp.
  50. /// </summary>
  51. /// <value>The timestamp.</value>
  52. public TransportStreamTimestamp? Timestamp { get; set; }
  53. public Video()
  54. {
  55. PlayableStreamFileNames = new List<string>();
  56. AdditionalPartIds = new List<Guid>();
  57. LocalAlternateVersionIds = new List<Guid>();
  58. Tags = new List<string>();
  59. SubtitleFiles = new List<string>();
  60. LinkedAlternateVersions = new List<LinkedChild>();
  61. }
  62. [IgnoreDataMember]
  63. public override bool SupportsAddingToPlaylist
  64. {
  65. get { return LocationType == LocationType.FileSystem && RunTimeTicks.HasValue; }
  66. }
  67. [IgnoreDataMember]
  68. public int MediaSourceCount
  69. {
  70. get
  71. {
  72. return LinkedAlternateVersions.Count + LocalAlternateVersionIds.Count + 1;
  73. }
  74. }
  75. public List<LinkedChild> LinkedAlternateVersions { get; set; }
  76. /// <summary>
  77. /// Gets the linked children.
  78. /// </summary>
  79. /// <returns>IEnumerable{BaseItem}.</returns>
  80. public IEnumerable<Video> GetAlternateVersions()
  81. {
  82. var filesWithinSameDirectory = LocalAlternateVersionIds
  83. .Select(i => LibraryManager.GetItemById(i))
  84. .Where(i => i != null)
  85. .OfType<Video>();
  86. return filesWithinSameDirectory.Concat(GetLinkedAlternateVersions())
  87. .OrderBy(i => i.SortName);
  88. }
  89. public IEnumerable<Video> GetLinkedAlternateVersions()
  90. {
  91. var linkedVersions = LinkedAlternateVersions
  92. .Select(GetLinkedChild)
  93. .Where(i => i != null)
  94. .OfType<Video>();
  95. return linkedVersions
  96. .OrderBy(i => i.SortName);
  97. }
  98. /// <summary>
  99. /// Gets the additional parts.
  100. /// </summary>
  101. /// <returns>IEnumerable{Video}.</returns>
  102. public IEnumerable<Video> GetAdditionalParts()
  103. {
  104. return AdditionalPartIds
  105. .Select(i => LibraryManager.GetItemById(i))
  106. .Where(i => i != null)
  107. .OfType<Video>()
  108. .OrderBy(i => i.SortName);
  109. }
  110. /// <summary>
  111. /// Gets or sets the subtitle paths.
  112. /// </summary>
  113. /// <value>The subtitle paths.</value>
  114. public List<string> SubtitleFiles { get; set; }
  115. /// <summary>
  116. /// Gets or sets a value indicating whether this instance has subtitles.
  117. /// </summary>
  118. /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
  119. public bool HasSubtitles { get; set; }
  120. public bool IsPlaceHolder { get; set; }
  121. public bool IsShortcut { get; set; }
  122. public string ShortcutPath { get; set; }
  123. /// <summary>
  124. /// Gets or sets the tags.
  125. /// </summary>
  126. /// <value>The tags.</value>
  127. public List<string> Tags { get; set; }
  128. /// <summary>
  129. /// Gets or sets the video bit rate.
  130. /// </summary>
  131. /// <value>The video bit rate.</value>
  132. public int? VideoBitRate { get; set; }
  133. /// <summary>
  134. /// Gets or sets the default index of the video stream.
  135. /// </summary>
  136. /// <value>The default index of the video stream.</value>
  137. public int? DefaultVideoStreamIndex { get; set; }
  138. /// <summary>
  139. /// Gets or sets the type of the video.
  140. /// </summary>
  141. /// <value>The type of the video.</value>
  142. public VideoType VideoType { get; set; }
  143. /// <summary>
  144. /// Gets or sets the type of the iso.
  145. /// </summary>
  146. /// <value>The type of the iso.</value>
  147. public IsoType? IsoType { get; set; }
  148. /// <summary>
  149. /// Gets or sets the video3 D format.
  150. /// </summary>
  151. /// <value>The video3 D format.</value>
  152. public Video3DFormat? Video3DFormat { get; set; }
  153. /// <summary>
  154. /// If the video is a folder-rip, this will hold the file list for the largest playlist
  155. /// </summary>
  156. public List<string> PlayableStreamFileNames { get; set; }
  157. /// <summary>
  158. /// Gets the playable stream files.
  159. /// </summary>
  160. /// <returns>List{System.String}.</returns>
  161. public List<string> GetPlayableStreamFiles()
  162. {
  163. return GetPlayableStreamFiles(Path);
  164. }
  165. /// <summary>
  166. /// Gets or sets the aspect ratio.
  167. /// </summary>
  168. /// <value>The aspect ratio.</value>
  169. public string AspectRatio { get; set; }
  170. [IgnoreDataMember]
  171. public override string ContainingFolderPath
  172. {
  173. get
  174. {
  175. if (IsMultiPart)
  176. {
  177. return System.IO.Path.GetDirectoryName(Path);
  178. }
  179. if (!IsPlaceHolder)
  180. {
  181. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd ||
  182. VideoType == VideoType.HdDvd)
  183. {
  184. return Path;
  185. }
  186. }
  187. return base.ContainingFolderPath;
  188. }
  189. }
  190. public string MainFeaturePlaylistName { get; set; }
  191. /// <summary>
  192. /// Gets the playable stream files.
  193. /// </summary>
  194. /// <param name="rootPath">The root path.</param>
  195. /// <returns>List{System.String}.</returns>
  196. public List<string> GetPlayableStreamFiles(string rootPath)
  197. {
  198. var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();
  199. return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  200. .Where(f => !string.IsNullOrEmpty(f))
  201. .ToList();
  202. }
  203. /// <summary>
  204. /// Gets a value indicating whether [is3 D].
  205. /// </summary>
  206. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  207. [IgnoreDataMember]
  208. public bool Is3D
  209. {
  210. get { return Video3DFormat.HasValue; }
  211. }
  212. public bool IsHD { get; set; }
  213. /// <summary>
  214. /// Gets the type of the media.
  215. /// </summary>
  216. /// <value>The type of the media.</value>
  217. [IgnoreDataMember]
  218. public override string MediaType
  219. {
  220. get
  221. {
  222. return Model.Entities.MediaType.Video;
  223. }
  224. }
  225. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  226. {
  227. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  228. // Must have a parent to have additional parts or alternate versions
  229. // In other words, it must be part of the Parent/Child tree
  230. // The additional parts won't have additional parts themselves
  231. if (LocationType == LocationType.FileSystem && Parent != null)
  232. {
  233. if (IsMultiPart)
  234. {
  235. var additionalPartsChanged = await RefreshAdditionalParts(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  236. if (additionalPartsChanged)
  237. {
  238. hasChanges = true;
  239. }
  240. }
  241. else
  242. {
  243. RefreshLinkedAlternateVersions();
  244. var additionalPartsChanged = await RefreshAlternateVersionsWithinSameDirectory(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  245. if (additionalPartsChanged)
  246. {
  247. hasChanges = true;
  248. }
  249. }
  250. }
  251. return hasChanges;
  252. }
  253. private bool RefreshLinkedAlternateVersions()
  254. {
  255. foreach (var child in LinkedAlternateVersions)
  256. {
  257. // Reset the cached value
  258. if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
  259. {
  260. child.ItemId = null;
  261. }
  262. }
  263. return false;
  264. }
  265. /// <summary>
  266. /// Refreshes the additional parts.
  267. /// </summary>
  268. /// <param name="options">The options.</param>
  269. /// <param name="fileSystemChildren">The file system children.</param>
  270. /// <param name="cancellationToken">The cancellation token.</param>
  271. /// <returns>Task{System.Boolean}.</returns>
  272. private async Task<bool> RefreshAdditionalParts(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  273. {
  274. var newItems = LoadAdditionalParts(fileSystemChildren, options.DirectoryService).ToList();
  275. var newItemIds = newItems.Select(i => i.Id).ToList();
  276. var itemsChanged = !AdditionalPartIds.SequenceEqual(newItemIds);
  277. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  278. await Task.WhenAll(tasks).ConfigureAwait(false);
  279. AdditionalPartIds = newItemIds;
  280. return itemsChanged;
  281. }
  282. /// <summary>
  283. /// Loads the additional parts.
  284. /// </summary>
  285. /// <returns>IEnumerable{Video}.</returns>
  286. private IEnumerable<Video> LoadAdditionalParts(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
  287. {
  288. IEnumerable<FileSystemInfo> files;
  289. var path = Path;
  290. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
  291. {
  292. files = fileSystemChildren.Where(i =>
  293. {
  294. if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  295. {
  296. return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFolder(i.FullName);
  297. }
  298. return false;
  299. });
  300. }
  301. else
  302. {
  303. files = fileSystemChildren.Where(i =>
  304. {
  305. if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  306. {
  307. return false;
  308. }
  309. return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name);
  310. });
  311. }
  312. return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
  313. {
  314. // Try to retrieve it from the db. If we don't find it, use the resolved version
  315. var dbItem = LibraryManager.GetItemById(video.Id) as Video;
  316. if (dbItem != null)
  317. {
  318. video = dbItem;
  319. }
  320. return video;
  321. // Sort them so that the list can be easily compared for changes
  322. }).OrderBy(i => i.Path).ToList();
  323. }
  324. private async Task<bool> RefreshAlternateVersionsWithinSameDirectory(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  325. {
  326. var newItems = HasLocalAlternateVersions ?
  327. LoadAlternateVersionsWithinSameDirectory(fileSystemChildren, options.DirectoryService).ToList() :
  328. new List<Video>();
  329. var newItemIds = newItems.Select(i => i.Id).ToList();
  330. var itemsChanged = !LocalAlternateVersionIds.SequenceEqual(newItemIds);
  331. var tasks = newItems.Select(i => RefreshAlternateVersion(options, i, cancellationToken));
  332. await Task.WhenAll(tasks).ConfigureAwait(false);
  333. LocalAlternateVersionIds = newItemIds;
  334. return itemsChanged;
  335. }
  336. private Task RefreshAlternateVersion(MetadataRefreshOptions options, Video video, CancellationToken cancellationToken)
  337. {
  338. var currentImagePath = video.GetImagePath(ImageType.Primary);
  339. var ownerImagePath = this.GetImagePath(ImageType.Primary);
  340. var newOptions = new MetadataRefreshOptions(options.DirectoryService)
  341. {
  342. ImageRefreshMode = options.ImageRefreshMode,
  343. MetadataRefreshMode = options.MetadataRefreshMode,
  344. ReplaceAllMetadata = options.ReplaceAllMetadata
  345. };
  346. if (!string.Equals(currentImagePath, ownerImagePath, StringComparison.OrdinalIgnoreCase))
  347. {
  348. newOptions.ForceSave = true;
  349. if (string.IsNullOrWhiteSpace(ownerImagePath))
  350. {
  351. video.ImageInfos.Clear();
  352. }
  353. else
  354. {
  355. video.SetImagePath(ImageType.Primary, ownerImagePath);
  356. }
  357. }
  358. return video.RefreshMetadata(newOptions, cancellationToken);
  359. }
  360. public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  361. {
  362. await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
  363. foreach (var item in LocalAlternateVersionIds.Select(i => LibraryManager.GetItemById(i)))
  364. {
  365. item.ImageInfos = ImageInfos;
  366. item.Overview = Overview;
  367. item.ProductionYear = ProductionYear;
  368. item.PremiereDate = PremiereDate;
  369. item.CommunityRating = CommunityRating;
  370. item.OfficialRating = OfficialRating;
  371. item.Genres = Genres;
  372. item.ProviderIds = ProviderIds;
  373. await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
  374. }
  375. }
  376. /// <summary>
  377. /// Loads the additional parts.
  378. /// </summary>
  379. /// <returns>IEnumerable{Video}.</returns>
  380. private IEnumerable<Video> LoadAlternateVersionsWithinSameDirectory(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
  381. {
  382. IEnumerable<FileSystemInfo> files;
  383. // Only support this for video files. For folder rips, they'll have to use the linking feature
  384. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  385. {
  386. var path = Path;
  387. var filenamePrefix = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(path));
  388. files = fileSystemChildren.Where(i =>
  389. {
  390. if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  391. {
  392. return false;
  393. }
  394. return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) &&
  395. EntityResolutionHelper.IsVideoFile(i.FullName) &&
  396. i.Name.StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase);
  397. });
  398. }
  399. else
  400. {
  401. files = new List<FileSystemInfo>();
  402. }
  403. return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
  404. {
  405. // Try to retrieve it from the db. If we don't find it, use the resolved version
  406. var dbItem = LibraryManager.GetItemById(video.Id) as Video;
  407. if (dbItem != null)
  408. {
  409. video = dbItem;
  410. }
  411. video.PrimaryVersionId = Id;
  412. return video;
  413. // Sort them so that the list can be easily compared for changes
  414. }).OrderBy(i => i.Path).ToList();
  415. }
  416. public override IEnumerable<string> GetDeletePaths()
  417. {
  418. if (!IsInMixedFolder)
  419. {
  420. return new[] { ContainingFolderPath };
  421. }
  422. return base.GetDeletePaths();
  423. }
  424. public virtual IEnumerable<MediaStream> GetMediaStreams()
  425. {
  426. return ItemRepository.GetMediaStreams(new MediaStreamQuery
  427. {
  428. ItemId = Id
  429. });
  430. }
  431. public virtual MediaStream GetDefaultVideoStream()
  432. {
  433. if (!DefaultVideoStreamIndex.HasValue)
  434. {
  435. return null;
  436. }
  437. return ItemRepository.GetMediaStreams(new MediaStreamQuery
  438. {
  439. ItemId = Id,
  440. Index = DefaultVideoStreamIndex.Value
  441. }).FirstOrDefault();
  442. }
  443. public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  444. {
  445. var item = this;
  446. var result = item.GetAlternateVersions()
  447. .Select(i => GetVersionInfo(enablePathSubstitution, i, MediaSourceType.Grouping))
  448. .ToList();
  449. result.Add(GetVersionInfo(enablePathSubstitution, item, MediaSourceType.Default));
  450. return result.OrderBy(i =>
  451. {
  452. if (item.VideoType == VideoType.VideoFile)
  453. {
  454. return 0;
  455. }
  456. return 1;
  457. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  458. .ThenByDescending(i =>
  459. {
  460. var stream = i.VideoStream;
  461. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  462. })
  463. .ToList();
  464. }
  465. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video i, MediaSourceType type)
  466. {
  467. var mediaStreams = ItemRepository.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList();
  468. var locationType = i.LocationType;
  469. var info = new MediaSourceInfo
  470. {
  471. Id = i.Id.ToString("N"),
  472. IsoType = i.IsoType,
  473. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  474. MediaStreams = mediaStreams,
  475. Name = GetMediaSourceName(i, mediaStreams),
  476. Path = enablePathSubstitution ? GetMappedPath(i.Path, locationType) : i.Path,
  477. RunTimeTicks = i.RunTimeTicks,
  478. Video3DFormat = i.Video3DFormat,
  479. VideoType = i.VideoType,
  480. Container = i.Container,
  481. Size = i.Size,
  482. Formats = (i.FormatName ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
  483. Timestamp = i.Timestamp,
  484. Type = type,
  485. PlayableStreamFileNames = i.PlayableStreamFileNames.ToList()
  486. };
  487. if (i.IsShortcut)
  488. {
  489. info.Path = i.ShortcutPath;
  490. if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
  491. {
  492. info.Protocol = MediaProtocol.Http;
  493. }
  494. else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
  495. {
  496. info.Protocol = MediaProtocol.Rtmp;
  497. }
  498. else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
  499. {
  500. info.Protocol = MediaProtocol.Rtsp;
  501. }
  502. else
  503. {
  504. info.Protocol = MediaProtocol.File;
  505. }
  506. }
  507. if (string.IsNullOrEmpty(info.Container))
  508. {
  509. if (i.VideoType == VideoType.VideoFile || i.VideoType == VideoType.Iso)
  510. {
  511. if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  512. {
  513. info.Container = System.IO.Path.GetExtension(i.Path).TrimStart('.');
  514. }
  515. }
  516. }
  517. try
  518. {
  519. var bitrate = i.TotalBitrate ??
  520. info.MediaStreams.Where(m => m.Type != MediaStreamType.Subtitle && !string.Equals(m.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase))
  521. .Select(m => m.BitRate ?? 0)
  522. .Sum();
  523. if (bitrate > 0)
  524. {
  525. info.Bitrate = bitrate;
  526. }
  527. }
  528. catch (OverflowException ex)
  529. {
  530. Logger.ErrorException("Error calculating total bitrate", ex);
  531. }
  532. return info;
  533. }
  534. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  535. {
  536. var terms = new List<string>();
  537. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  538. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  539. if (video.Video3DFormat.HasValue)
  540. {
  541. terms.Add("3D");
  542. }
  543. if (video.VideoType == VideoType.BluRay)
  544. {
  545. terms.Add("Bluray");
  546. }
  547. else if (video.VideoType == VideoType.Dvd)
  548. {
  549. terms.Add("DVD");
  550. }
  551. else if (video.VideoType == VideoType.HdDvd)
  552. {
  553. terms.Add("HD-DVD");
  554. }
  555. else if (video.VideoType == VideoType.Iso)
  556. {
  557. if (video.IsoType.HasValue)
  558. {
  559. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  560. {
  561. terms.Add("Bluray");
  562. }
  563. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  564. {
  565. terms.Add("DVD");
  566. }
  567. }
  568. else
  569. {
  570. terms.Add("ISO");
  571. }
  572. }
  573. if (videoStream != null)
  574. {
  575. if (videoStream.Width.HasValue)
  576. {
  577. if (videoStream.Width.Value >= 3800)
  578. {
  579. terms.Add("4K");
  580. }
  581. else if (videoStream.Width.Value >= 1900)
  582. {
  583. terms.Add("1080P");
  584. }
  585. else if (videoStream.Width.Value >= 1270)
  586. {
  587. terms.Add("720P");
  588. }
  589. else if (videoStream.Width.Value >= 700)
  590. {
  591. terms.Add("480P");
  592. }
  593. else
  594. {
  595. terms.Add("SD");
  596. }
  597. }
  598. }
  599. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  600. {
  601. terms.Add(videoStream.Codec.ToUpper());
  602. }
  603. if (audioStream != null)
  604. {
  605. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  606. ? audioStream.Profile
  607. : audioStream.Codec;
  608. if (!string.IsNullOrEmpty(audioCodec))
  609. {
  610. terms.Add(audioCodec.ToUpper());
  611. }
  612. }
  613. return string.Join("/", terms.ToArray());
  614. }
  615. }
  616. }