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. using MediaBrowser.Model.Extensions;
  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. {
  29. [IgnoreDataMember]
  30. public string PrimaryVersionId { get; set; }
  31. public string[] AdditionalParts { get; set; }
  32. public string[] LocalAlternateVersions { get; set; }
  33. public LinkedChild[] LinkedAlternateVersions { get; set; }
  34. [IgnoreDataMember]
  35. public override bool SupportsPlayedStatus
  36. {
  37. get
  38. {
  39. return true;
  40. }
  41. }
  42. [IgnoreDataMember]
  43. public override bool SupportsInheritedParentImages
  44. {
  45. get
  46. {
  47. return true;
  48. }
  49. }
  50. [IgnoreDataMember]
  51. public override bool SupportsPositionTicksResume
  52. {
  53. get
  54. {
  55. var extraType = ExtraType;
  56. if (extraType.HasValue)
  57. {
  58. if (extraType.Value == Model.Entities.ExtraType.Sample)
  59. {
  60. return false;
  61. }
  62. if (extraType.Value == Model.Entities.ExtraType.ThemeVideo)
  63. {
  64. return false;
  65. }
  66. if (extraType.Value == Model.Entities.ExtraType.Trailer)
  67. {
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73. }
  74. public override string CreatePresentationUniqueKey()
  75. {
  76. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  77. {
  78. return PrimaryVersionId;
  79. }
  80. return base.CreatePresentationUniqueKey();
  81. }
  82. [IgnoreDataMember]
  83. public override bool EnableRefreshOnDateModifiedChange
  84. {
  85. get
  86. {
  87. return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso;
  88. }
  89. }
  90. [IgnoreDataMember]
  91. public override bool SupportsThemeMedia
  92. {
  93. get { return true; }
  94. }
  95. /// <summary>
  96. /// Gets or sets the timestamp.
  97. /// </summary>
  98. /// <value>The timestamp.</value>
  99. public TransportStreamTimestamp? Timestamp { get; set; }
  100. /// <summary>
  101. /// Gets or sets the subtitle paths.
  102. /// </summary>
  103. /// <value>The subtitle paths.</value>
  104. public string[] SubtitleFiles { get; set; }
  105. /// <summary>
  106. /// Gets or sets a value indicating whether this instance has subtitles.
  107. /// </summary>
  108. /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
  109. public bool HasSubtitles { get; set; }
  110. public bool IsPlaceHolder { get; set; }
  111. public bool IsShortcut { get; set; }
  112. public string ShortcutPath { get; set; }
  113. /// <summary>
  114. /// Gets or sets the default index of the video stream.
  115. /// </summary>
  116. /// <value>The default index of the video stream.</value>
  117. public int? DefaultVideoStreamIndex { get; set; }
  118. /// <summary>
  119. /// Gets or sets the type of the video.
  120. /// </summary>
  121. /// <value>The type of the video.</value>
  122. public VideoType VideoType { get; set; }
  123. /// <summary>
  124. /// Gets or sets the type of the iso.
  125. /// </summary>
  126. /// <value>The type of the iso.</value>
  127. public IsoType? IsoType { get; set; }
  128. /// <summary>
  129. /// Gets or sets the video3 D format.
  130. /// </summary>
  131. /// <value>The video3 D format.</value>
  132. public Video3DFormat? Video3DFormat { get; set; }
  133. /// <summary>
  134. /// Gets the playable stream files.
  135. /// </summary>
  136. /// <returns>List{System.String}.</returns>
  137. public string[] GetPlayableStreamFiles()
  138. {
  139. return GetPlayableStreamFiles(Path);
  140. }
  141. public string[] GetPlayableStreamFileNames()
  142. {
  143. return GetPlayableStreamFiles().Select(System.IO.Path.GetFileName).ToArray();
  144. }
  145. /// <summary>
  146. /// Gets or sets the aspect ratio.
  147. /// </summary>
  148. /// <value>The aspect ratio.</value>
  149. public string AspectRatio { get; set; }
  150. public Video()
  151. {
  152. AdditionalParts = EmptyStringArray;
  153. LocalAlternateVersions = EmptyStringArray;
  154. SubtitleFiles = EmptyStringArray;
  155. LinkedAlternateVersions = EmptyLinkedChildArray;
  156. }
  157. public override bool CanDownload()
  158. {
  159. if (VideoType == VideoType.Dvd || 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.Length + LocalAlternateVersions.Length + 1;
  186. }
  187. }
  188. [IgnoreDataMember]
  189. public bool IsStacked
  190. {
  191. get { return AdditionalParts.Length > 0; }
  192. }
  193. [IgnoreDataMember]
  194. public bool HasLocalAlternateVersions
  195. {
  196. get { return LocalAlternateVersions.Length > 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. {
  291. return Path;
  292. }
  293. }
  294. return base.ContainingFolderPath;
  295. }
  296. }
  297. [IgnoreDataMember]
  298. public override string FileNameWithoutExtension
  299. {
  300. get
  301. {
  302. if (LocationType == LocationType.FileSystem)
  303. {
  304. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
  305. {
  306. return System.IO.Path.GetFileName(Path);
  307. }
  308. return System.IO.Path.GetFileNameWithoutExtension(Path);
  309. }
  310. return null;
  311. }
  312. }
  313. internal override bool IsValidFromResolver(BaseItem newItem)
  314. {
  315. var current = this;
  316. var newAsVideo = newItem as Video;
  317. if (newAsVideo != null)
  318. {
  319. if (!current.AdditionalParts.SequenceEqual(newAsVideo.AdditionalParts, StringComparer.OrdinalIgnoreCase))
  320. {
  321. return false;
  322. }
  323. if (!current.LocalAlternateVersions.SequenceEqual(newAsVideo.LocalAlternateVersions, StringComparer.OrdinalIgnoreCase))
  324. {
  325. return false;
  326. }
  327. if (newAsVideo.VideoType != VideoType)
  328. {
  329. return false;
  330. }
  331. }
  332. return base.IsValidFromResolver(newItem);
  333. }
  334. /// <summary>
  335. /// Gets the playable stream files.
  336. /// </summary>
  337. /// <param name="rootPath">The root path.</param>
  338. /// <returns>List{System.String}.</returns>
  339. public string[] GetPlayableStreamFiles(string rootPath)
  340. {
  341. if (VideoType == VideoType.VideoFile)
  342. {
  343. return new string[] { };
  344. }
  345. var allFiles = FileSystem.GetFilePaths(rootPath, true).ToList();
  346. var videoType = VideoType;
  347. if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.BluRay)
  348. {
  349. videoType = VideoType.BluRay;
  350. }
  351. else if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.Dvd)
  352. {
  353. videoType = VideoType.Dvd;
  354. }
  355. return QueryPlayableStreamFiles(rootPath, videoType).Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  356. .Where(f => !string.IsNullOrEmpty(f))
  357. .ToArray();
  358. }
  359. public static string[] QueryPlayableStreamFiles(string rootPath, VideoType videoType)
  360. {
  361. if (videoType == VideoType.Dvd)
  362. {
  363. return FileSystem.GetFiles(rootPath, new[] { ".vob" }, false, true)
  364. .OrderByDescending(i => i.Length)
  365. .ThenBy(i => i.FullName)
  366. .Take(1)
  367. .Select(i => i.FullName)
  368. .ToArray();
  369. }
  370. if (videoType == VideoType.BluRay)
  371. {
  372. return FileSystem.GetFiles(rootPath, new[] { ".m2ts" }, false, true)
  373. .OrderByDescending(i => i.Length)
  374. .ThenBy(i => i.FullName)
  375. .Take(1)
  376. .Select(i => i.FullName)
  377. .ToArray();
  378. }
  379. return new string[] { };
  380. }
  381. /// <summary>
  382. /// Gets a value indicating whether [is3 D].
  383. /// </summary>
  384. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  385. [IgnoreDataMember]
  386. public bool Is3D
  387. {
  388. get { return Video3DFormat.HasValue; }
  389. }
  390. /// <summary>
  391. /// Gets the type of the media.
  392. /// </summary>
  393. /// <value>The type of the media.</value>
  394. [IgnoreDataMember]
  395. public override string MediaType
  396. {
  397. get
  398. {
  399. return Model.Entities.MediaType.Video;
  400. }
  401. }
  402. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  403. {
  404. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  405. if (IsStacked)
  406. {
  407. var tasks = AdditionalParts
  408. .Select(i => RefreshMetadataForOwnedVideo(options, true, i, cancellationToken));
  409. await Task.WhenAll(tasks).ConfigureAwait(false);
  410. }
  411. // Must have a parent to have additional parts or alternate versions
  412. // In other words, it must be part of the Parent/Child tree
  413. // The additional parts won't have additional parts themselves
  414. if (LocationType == LocationType.FileSystem && GetParent() != null)
  415. {
  416. if (!IsStacked)
  417. {
  418. RefreshLinkedAlternateVersions();
  419. var tasks = LocalAlternateVersions
  420. .Select(i => RefreshMetadataForOwnedVideo(options, false, i, cancellationToken));
  421. await Task.WhenAll(tasks).ConfigureAwait(false);
  422. }
  423. }
  424. return hasChanges;
  425. }
  426. private void RefreshLinkedAlternateVersions()
  427. {
  428. foreach (var child in LinkedAlternateVersions)
  429. {
  430. // Reset the cached value
  431. if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
  432. {
  433. child.ItemId = null;
  434. }
  435. }
  436. }
  437. public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  438. {
  439. await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
  440. var localAlternates = GetLocalAlternateVersionIds()
  441. .Select(i => LibraryManager.GetItemById(i))
  442. .Where(i => i != null);
  443. foreach (var item in localAlternates)
  444. {
  445. item.ImageInfos = ImageInfos;
  446. item.Overview = Overview;
  447. item.ProductionYear = ProductionYear;
  448. item.PremiereDate = PremiereDate;
  449. item.CommunityRating = CommunityRating;
  450. item.OfficialRating = OfficialRating;
  451. item.Genres = Genres;
  452. item.ProviderIds = ProviderIds;
  453. await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
  454. }
  455. }
  456. public override IEnumerable<FileSystemMetadata> GetDeletePaths()
  457. {
  458. if (!IsInMixedFolder)
  459. {
  460. return new[] {
  461. new FileSystemMetadata
  462. {
  463. FullName = ContainingFolderPath,
  464. IsDirectory = true
  465. }
  466. };
  467. }
  468. return base.GetDeletePaths();
  469. }
  470. public List<MediaStream> GetMediaStreams()
  471. {
  472. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  473. {
  474. ItemId = Id
  475. });
  476. }
  477. public virtual MediaStream GetDefaultVideoStream()
  478. {
  479. if (!DefaultVideoStreamIndex.HasValue)
  480. {
  481. return null;
  482. }
  483. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  484. {
  485. ItemId = Id,
  486. Index = DefaultVideoStreamIndex.Value
  487. }).FirstOrDefault();
  488. }
  489. private List<Tuple<Video, MediaSourceType>> GetAllVideosForMediaSources()
  490. {
  491. var list = new List<Tuple<Video, MediaSourceType>>();
  492. list.Add(new Tuple<Video, MediaSourceType>(this, MediaSourceType.Default));
  493. list.AddRange(GetLinkedAlternateVersions().Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  494. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  495. {
  496. var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  497. if (primary != null)
  498. {
  499. var existingIds = list.Select(i => i.Item1.Id).ToList();
  500. list.Add(new Tuple<Video, MediaSourceType>(primary, MediaSourceType.Grouping));
  501. list.AddRange(primary.GetLinkedAlternateVersions().Where(i => !existingIds.Contains(i.Id)).Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  502. }
  503. }
  504. var localAlternates = list
  505. .SelectMany(i => i.Item1.GetLocalAlternateVersionIds())
  506. .Select(LibraryManager.GetItemById)
  507. .Where(i => i != null)
  508. .OfType<Video>()
  509. .ToList();
  510. list.AddRange(localAlternates.Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Default)));
  511. return list;
  512. }
  513. public virtual List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  514. {
  515. if (SourceType == SourceType.Channel)
  516. {
  517. var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
  518. .ToList();
  519. if (sources.Count > 0)
  520. {
  521. return sources;
  522. }
  523. return new List<MediaSourceInfo>
  524. {
  525. GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder)
  526. };
  527. }
  528. var list = GetAllVideosForMediaSources();
  529. var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList();
  530. return result.OrderBy(i =>
  531. {
  532. if (i.VideoType == VideoType.VideoFile)
  533. {
  534. return 0;
  535. }
  536. return 1;
  537. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  538. .ThenByDescending(i =>
  539. {
  540. var stream = i.VideoStream;
  541. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  542. })
  543. .ToList();
  544. }
  545. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type)
  546. {
  547. if (media == null)
  548. {
  549. throw new ArgumentNullException("media");
  550. }
  551. var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id);
  552. var locationType = media.LocationType;
  553. var info = new MediaSourceInfo
  554. {
  555. Id = media.Id.ToString("N"),
  556. IsoType = media.IsoType,
  557. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  558. MediaStreams = mediaStreams,
  559. Name = GetMediaSourceName(media, mediaStreams),
  560. Path = enablePathSubstitution ? GetMappedPath(media, media.Path, locationType) : media.Path,
  561. RunTimeTicks = media.RunTimeTicks,
  562. Video3DFormat = media.Video3DFormat,
  563. VideoType = media.VideoType,
  564. Container = media.Container,
  565. Size = media.Size,
  566. Timestamp = media.Timestamp,
  567. Type = type,
  568. SupportsDirectStream = media.VideoType == VideoType.VideoFile,
  569. IsRemote = media.IsShortcut
  570. };
  571. if (info.Protocol == MediaProtocol.File)
  572. {
  573. info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
  574. }
  575. if (media.IsShortcut)
  576. {
  577. info.Path = media.ShortcutPath;
  578. if (!string.IsNullOrWhiteSpace(info.Path))
  579. {
  580. if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
  581. {
  582. info.Protocol = MediaProtocol.Http;
  583. info.SupportsDirectStream = false;
  584. }
  585. else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
  586. {
  587. info.Protocol = MediaProtocol.Rtmp;
  588. info.SupportsDirectStream = false;
  589. }
  590. else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
  591. {
  592. info.Protocol = MediaProtocol.Rtsp;
  593. info.SupportsDirectStream = false;
  594. }
  595. else
  596. {
  597. info.Protocol = MediaProtocol.File;
  598. }
  599. }
  600. }
  601. if (string.IsNullOrEmpty(info.Container))
  602. {
  603. if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso)
  604. {
  605. if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  606. {
  607. info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.');
  608. }
  609. }
  610. }
  611. info.Bitrate = media.TotalBitrate;
  612. info.InferTotalBitrate();
  613. return info;
  614. }
  615. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  616. {
  617. var terms = new List<string>();
  618. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  619. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  620. if (video.Video3DFormat.HasValue)
  621. {
  622. terms.Add("3D");
  623. }
  624. if (video.VideoType == VideoType.BluRay)
  625. {
  626. terms.Add("Bluray");
  627. }
  628. else if (video.VideoType == VideoType.Dvd)
  629. {
  630. terms.Add("DVD");
  631. }
  632. else if (video.VideoType == VideoType.Iso)
  633. {
  634. if (video.IsoType.HasValue)
  635. {
  636. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  637. {
  638. terms.Add("Bluray");
  639. }
  640. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  641. {
  642. terms.Add("DVD");
  643. }
  644. }
  645. else
  646. {
  647. terms.Add("ISO");
  648. }
  649. }
  650. if (videoStream != null)
  651. {
  652. if (videoStream.Width.HasValue)
  653. {
  654. if (videoStream.Width.Value >= 3800)
  655. {
  656. terms.Add("4K");
  657. }
  658. else if (videoStream.Width.Value >= 1900)
  659. {
  660. terms.Add("1080P");
  661. }
  662. else if (videoStream.Width.Value >= 1270)
  663. {
  664. terms.Add("720P");
  665. }
  666. else if (videoStream.Width.Value >= 700)
  667. {
  668. terms.Add("480P");
  669. }
  670. else
  671. {
  672. terms.Add("SD");
  673. }
  674. }
  675. }
  676. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  677. {
  678. terms.Add(videoStream.Codec.ToUpper());
  679. }
  680. if (audioStream != null)
  681. {
  682. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  683. ? audioStream.Profile
  684. : audioStream.Codec;
  685. if (!string.IsNullOrEmpty(audioCodec))
  686. {
  687. terms.Add(audioCodec.ToUpper());
  688. }
  689. }
  690. return string.Join("/", terms.ToArray(terms.Count));
  691. }
  692. }
  693. }