2
0

Video.cs 25 KB

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