Video.cs 25 KB

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