Video.cs 25 KB

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