Video.cs 25 KB

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