Video.cs 26 KB

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