Video.cs 24 KB

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