Video.cs 24 KB

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