Video.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  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. [IgnoreDataMember]
  35. public override bool SupportsPlayedStatus
  36. {
  37. get
  38. {
  39. return true;
  40. }
  41. }
  42. [IgnoreDataMember]
  43. public override bool SupportsPositionTicksResume
  44. {
  45. get
  46. {
  47. return true;
  48. }
  49. }
  50. [IgnoreDataMember]
  51. protected override bool SupportsIsInMixedFolderDetection
  52. {
  53. get
  54. {
  55. return true;
  56. }
  57. }
  58. public override string CreatePresentationUniqueKey()
  59. {
  60. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  61. {
  62. return PrimaryVersionId;
  63. }
  64. return base.CreatePresentationUniqueKey();
  65. }
  66. [IgnoreDataMember]
  67. public override bool EnableRefreshOnDateModifiedChange
  68. {
  69. get
  70. {
  71. return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso;
  72. }
  73. }
  74. [IgnoreDataMember]
  75. public override bool SupportsThemeMedia
  76. {
  77. get { return true; }
  78. }
  79. /// <summary>
  80. /// Gets or sets the timestamp.
  81. /// </summary>
  82. /// <value>The timestamp.</value>
  83. public TransportStreamTimestamp? Timestamp { get; set; }
  84. /// <summary>
  85. /// Gets or sets the subtitle paths.
  86. /// </summary>
  87. /// <value>The subtitle paths.</value>
  88. public List<string> SubtitleFiles { get; set; }
  89. /// <summary>
  90. /// Gets or sets a value indicating whether this instance has subtitles.
  91. /// </summary>
  92. /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
  93. public bool HasSubtitles { get; set; }
  94. public bool IsPlaceHolder { get; set; }
  95. public bool IsShortcut { get; set; }
  96. public string ShortcutPath { get; set; }
  97. /// <summary>
  98. /// Gets or sets the default index of the video stream.
  99. /// </summary>
  100. /// <value>The default index of the video stream.</value>
  101. public int? DefaultVideoStreamIndex { get; set; }
  102. /// <summary>
  103. /// Gets or sets the type of the video.
  104. /// </summary>
  105. /// <value>The type of the video.</value>
  106. public VideoType VideoType { get; set; }
  107. /// <summary>
  108. /// Gets or sets the type of the iso.
  109. /// </summary>
  110. /// <value>The type of the iso.</value>
  111. public IsoType? IsoType { get; set; }
  112. /// <summary>
  113. /// Gets or sets the video3 D format.
  114. /// </summary>
  115. /// <value>The video3 D format.</value>
  116. public Video3DFormat? Video3DFormat { get; set; }
  117. /// <summary>
  118. /// If the video is a folder-rip, this will hold the file list for the largest playlist
  119. /// </summary>
  120. public List<string> PlayableStreamFileNames { get; set; }
  121. /// <summary>
  122. /// Gets the playable stream files.
  123. /// </summary>
  124. /// <returns>List{System.String}.</returns>
  125. public List<string> GetPlayableStreamFiles()
  126. {
  127. return GetPlayableStreamFiles(Path);
  128. }
  129. /// <summary>
  130. /// Gets or sets the aspect ratio.
  131. /// </summary>
  132. /// <value>The aspect ratio.</value>
  133. public string AspectRatio { get; set; }
  134. public Video()
  135. {
  136. PlayableStreamFileNames = new List<string>();
  137. AdditionalParts = new List<string>();
  138. LocalAlternateVersions = new List<string>();
  139. SubtitleFiles = new List<string>();
  140. LinkedAlternateVersions = new List<LinkedChild>();
  141. }
  142. public override bool CanDownload()
  143. {
  144. if (VideoType == VideoType.HdDvd || VideoType == VideoType.Dvd ||
  145. VideoType == VideoType.BluRay)
  146. {
  147. return false;
  148. }
  149. var locationType = LocationType;
  150. return locationType != LocationType.Remote &&
  151. locationType != LocationType.Virtual;
  152. }
  153. [IgnoreDataMember]
  154. public override bool SupportsAddingToPlaylist
  155. {
  156. get { return true; }
  157. }
  158. [IgnoreDataMember]
  159. public int MediaSourceCount
  160. {
  161. get
  162. {
  163. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  164. {
  165. var item = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  166. if (item != null)
  167. {
  168. return item.MediaSourceCount;
  169. }
  170. }
  171. return LinkedAlternateVersions.Count + LocalAlternateVersions.Count + 1;
  172. }
  173. }
  174. [IgnoreDataMember]
  175. public bool IsStacked
  176. {
  177. get { return AdditionalParts.Count > 0; }
  178. }
  179. [IgnoreDataMember]
  180. public bool HasLocalAlternateVersions
  181. {
  182. get { return LocalAlternateVersions.Count > 0; }
  183. }
  184. public IEnumerable<Guid> GetAdditionalPartIds()
  185. {
  186. return AdditionalParts.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
  187. }
  188. public IEnumerable<Guid> GetLocalAlternateVersionIds()
  189. {
  190. return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
  191. }
  192. [IgnoreDataMember]
  193. protected virtual bool EnableDefaultVideoUserDataKeys
  194. {
  195. get
  196. {
  197. return true;
  198. }
  199. }
  200. public override List<string> GetUserDataKeys()
  201. {
  202. var list = base.GetUserDataKeys();
  203. if (EnableDefaultVideoUserDataKeys)
  204. {
  205. if (ExtraType.HasValue)
  206. {
  207. var key = this.GetProviderId(MetadataProviders.Tmdb);
  208. if (!string.IsNullOrWhiteSpace(key))
  209. {
  210. list.Insert(0, GetUserDataKey(key));
  211. }
  212. key = this.GetProviderId(MetadataProviders.Imdb);
  213. if (!string.IsNullOrWhiteSpace(key))
  214. {
  215. list.Insert(0, GetUserDataKey(key));
  216. }
  217. }
  218. else
  219. {
  220. var key = this.GetProviderId(MetadataProviders.Imdb);
  221. if (!string.IsNullOrWhiteSpace(key))
  222. {
  223. list.Insert(0, key);
  224. }
  225. key = this.GetProviderId(MetadataProviders.Tmdb);
  226. if (!string.IsNullOrWhiteSpace(key))
  227. {
  228. list.Insert(0, key);
  229. }
  230. }
  231. }
  232. return list;
  233. }
  234. private string GetUserDataKey(string providerId)
  235. {
  236. var key = providerId + "-" + ExtraType.ToString().ToLower();
  237. // Make sure different trailers have their own data.
  238. if (RunTimeTicks.HasValue)
  239. {
  240. key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
  241. }
  242. return key;
  243. }
  244. public IEnumerable<Video> GetLinkedAlternateVersions()
  245. {
  246. var linkedVersions = LinkedAlternateVersions
  247. .Select(GetLinkedChild)
  248. .Where(i => i != null)
  249. .OfType<Video>();
  250. return linkedVersions
  251. .OrderBy(i => i.SortName);
  252. }
  253. /// <summary>
  254. /// Gets the additional parts.
  255. /// </summary>
  256. /// <returns>IEnumerable{Video}.</returns>
  257. public IEnumerable<Video> GetAdditionalParts()
  258. {
  259. return GetAdditionalPartIds()
  260. .Select(i => LibraryManager.GetItemById(i))
  261. .Where(i => i != null)
  262. .OfType<Video>()
  263. .OrderBy(i => i.SortName);
  264. }
  265. [IgnoreDataMember]
  266. public override string ContainingFolderPath
  267. {
  268. get
  269. {
  270. if (IsStacked)
  271. {
  272. return FileSystem.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, true, 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, false, 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<FileSystemMetadata> GetDeletePaths()
  410. {
  411. if (!DetectIsInMixedFolder())
  412. {
  413. return new[] {
  414. new FileSystemMetadata
  415. {
  416. FullName = ContainingFolderPath,
  417. IsDirectory = true
  418. }
  419. };
  420. }
  421. return base.GetDeletePaths();
  422. }
  423. public IEnumerable<MediaStream> GetMediaStreams()
  424. {
  425. var mediaSource = GetMediaSources(false)
  426. .FirstOrDefault();
  427. if (mediaSource == null)
  428. {
  429. return new List<MediaStream>();
  430. }
  431. return mediaSource.MediaStreams;
  432. }
  433. public virtual MediaStream GetDefaultVideoStream()
  434. {
  435. if (!DefaultVideoStreamIndex.HasValue)
  436. {
  437. return null;
  438. }
  439. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  440. {
  441. ItemId = Id,
  442. Index = DefaultVideoStreamIndex.Value
  443. }).FirstOrDefault();
  444. }
  445. private List<Tuple<Video, MediaSourceType>> GetAllVideosForMediaSources()
  446. {
  447. var list = new List<Tuple<Video, MediaSourceType>>();
  448. list.Add(new Tuple<Video, MediaSourceType>(this, MediaSourceType.Default));
  449. list.AddRange(GetLinkedAlternateVersions().Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  450. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  451. {
  452. var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  453. if (primary != null)
  454. {
  455. var existingIds = list.Select(i => i.Item1.Id).ToList();
  456. list.Add(new Tuple<Video, MediaSourceType>(primary, MediaSourceType.Grouping));
  457. list.AddRange(primary.GetLinkedAlternateVersions().Where(i => !existingIds.Contains(i.Id)).Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  458. }
  459. }
  460. var localAlternates = list
  461. .SelectMany(i => i.Item1.GetLocalAlternateVersionIds())
  462. .Select(LibraryManager.GetItemById)
  463. .Where(i => i != null)
  464. .OfType<Video>()
  465. .ToList();
  466. list.AddRange(localAlternates.Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Default)));
  467. return list;
  468. }
  469. public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  470. {
  471. if (SourceType == SourceType.Channel)
  472. {
  473. var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
  474. .Result.ToList();
  475. if (sources.Count > 0)
  476. {
  477. return sources;
  478. }
  479. return new List<MediaSourceInfo>
  480. {
  481. GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder)
  482. };
  483. }
  484. var list = GetAllVideosForMediaSources();
  485. var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList();
  486. return result.OrderBy(i =>
  487. {
  488. if (i.VideoType == VideoType.VideoFile)
  489. {
  490. return 0;
  491. }
  492. return 1;
  493. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  494. .ThenByDescending(i =>
  495. {
  496. var stream = i.VideoStream;
  497. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  498. })
  499. .ToList();
  500. }
  501. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type)
  502. {
  503. if (media == null)
  504. {
  505. throw new ArgumentNullException("media");
  506. }
  507. var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id)
  508. .ToList();
  509. var locationType = media.LocationType;
  510. var info = new MediaSourceInfo
  511. {
  512. Id = media.Id.ToString("N"),
  513. IsoType = media.IsoType,
  514. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  515. MediaStreams = mediaStreams,
  516. Name = GetMediaSourceName(media, mediaStreams),
  517. Path = enablePathSubstitution ? GetMappedPath(media, media.Path, locationType) : media.Path,
  518. RunTimeTicks = media.RunTimeTicks,
  519. Video3DFormat = media.Video3DFormat,
  520. VideoType = media.VideoType,
  521. Container = media.Container,
  522. Size = media.Size,
  523. Timestamp = media.Timestamp,
  524. Type = type,
  525. PlayableStreamFileNames = media.PlayableStreamFileNames.ToList(),
  526. SupportsDirectStream = media.VideoType == VideoType.VideoFile,
  527. IsRemote = media.IsShortcut
  528. };
  529. if (info.Protocol == MediaProtocol.File)
  530. {
  531. info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
  532. }
  533. if (media.IsShortcut)
  534. {
  535. info.Path = media.ShortcutPath;
  536. if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
  537. {
  538. info.Protocol = MediaProtocol.Http;
  539. }
  540. else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
  541. {
  542. info.Protocol = MediaProtocol.Rtmp;
  543. }
  544. else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
  545. {
  546. info.Protocol = MediaProtocol.Rtsp;
  547. }
  548. else
  549. {
  550. info.Protocol = MediaProtocol.File;
  551. }
  552. }
  553. if (string.IsNullOrEmpty(info.Container))
  554. {
  555. if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso)
  556. {
  557. if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  558. {
  559. info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.');
  560. }
  561. }
  562. }
  563. info.Bitrate = media.TotalBitrate;
  564. info.InferTotalBitrate();
  565. return info;
  566. }
  567. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  568. {
  569. var terms = new List<string>();
  570. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  571. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  572. if (video.Video3DFormat.HasValue)
  573. {
  574. terms.Add("3D");
  575. }
  576. if (video.VideoType == VideoType.BluRay)
  577. {
  578. terms.Add("Bluray");
  579. }
  580. else if (video.VideoType == VideoType.Dvd)
  581. {
  582. terms.Add("DVD");
  583. }
  584. else if (video.VideoType == VideoType.HdDvd)
  585. {
  586. terms.Add("HD-DVD");
  587. }
  588. else if (video.VideoType == VideoType.Iso)
  589. {
  590. if (video.IsoType.HasValue)
  591. {
  592. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  593. {
  594. terms.Add("Bluray");
  595. }
  596. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  597. {
  598. terms.Add("DVD");
  599. }
  600. }
  601. else
  602. {
  603. terms.Add("ISO");
  604. }
  605. }
  606. if (videoStream != null)
  607. {
  608. if (videoStream.Width.HasValue)
  609. {
  610. if (videoStream.Width.Value >= 3800)
  611. {
  612. terms.Add("4K");
  613. }
  614. else if (videoStream.Width.Value >= 1900)
  615. {
  616. terms.Add("1080P");
  617. }
  618. else if (videoStream.Width.Value >= 1270)
  619. {
  620. terms.Add("720P");
  621. }
  622. else if (videoStream.Width.Value >= 700)
  623. {
  624. terms.Add("480P");
  625. }
  626. else
  627. {
  628. terms.Add("SD");
  629. }
  630. }
  631. }
  632. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  633. {
  634. terms.Add(videoStream.Codec.ToUpper());
  635. }
  636. if (audioStream != null)
  637. {
  638. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  639. ? audioStream.Profile
  640. : audioStream.Codec;
  641. if (!string.IsNullOrEmpty(audioCodec))
  642. {
  643. terms.Add(audioCodec.ToUpper());
  644. }
  645. }
  646. return string.Join("/", terms.ToArray());
  647. }
  648. }
  649. }