Video.cs 25 KB

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