Video.cs 24 KB

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