Video.cs 25 KB

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