Video.cs 25 KB

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