Video.cs 25 KB

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