Video.cs 24 KB

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