Video.cs 24 KB

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