Video.cs 24 KB

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