Video.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760
  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. return LinkedAlternateVersions
  247. .Select(GetLinkedChild)
  248. .Where(i => i != null)
  249. .OfType<Video>()
  250. .OrderBy(i => i.SortName);
  251. }
  252. /// <summary>
  253. /// Gets the additional parts.
  254. /// </summary>
  255. /// <returns>IEnumerable{Video}.</returns>
  256. public IEnumerable<Video> GetAdditionalParts()
  257. {
  258. return GetAdditionalPartIds()
  259. .Select(i => LibraryManager.GetItemById(i))
  260. .Where(i => i != null)
  261. .OfType<Video>()
  262. .OrderBy(i => i.SortName);
  263. }
  264. [IgnoreDataMember]
  265. public override string ContainingFolderPath
  266. {
  267. get
  268. {
  269. if (IsStacked)
  270. {
  271. return FileSystem.GetDirectoryName(Path);
  272. }
  273. if (!IsPlaceHolder)
  274. {
  275. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd ||
  276. VideoType == VideoType.HdDvd)
  277. {
  278. return Path;
  279. }
  280. }
  281. return base.ContainingFolderPath;
  282. }
  283. }
  284. [IgnoreDataMember]
  285. public override string FileNameWithoutExtension
  286. {
  287. get
  288. {
  289. if (LocationType == LocationType.FileSystem)
  290. {
  291. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd || VideoType == VideoType.HdDvd)
  292. {
  293. return System.IO.Path.GetFileName(Path);
  294. }
  295. return System.IO.Path.GetFileNameWithoutExtension(Path);
  296. }
  297. return null;
  298. }
  299. }
  300. internal override bool IsValidFromResolver(BaseItem newItem)
  301. {
  302. var current = this;
  303. var newAsVideo = newItem as Video;
  304. if (newAsVideo != null)
  305. {
  306. if (!current.AdditionalParts.SequenceEqual(newAsVideo.AdditionalParts, StringComparer.OrdinalIgnoreCase))
  307. {
  308. return false;
  309. }
  310. if (!current.LocalAlternateVersions.SequenceEqual(newAsVideo.LocalAlternateVersions, StringComparer.OrdinalIgnoreCase))
  311. {
  312. return false;
  313. }
  314. if (newAsVideo.VideoType != VideoType)
  315. {
  316. return false;
  317. }
  318. }
  319. return base.IsValidFromResolver(newItem);
  320. }
  321. /// <summary>
  322. /// Gets the playable stream files.
  323. /// </summary>
  324. /// <param name="rootPath">The root path.</param>
  325. /// <returns>List{System.String}.</returns>
  326. public List<string> GetPlayableStreamFiles(string rootPath)
  327. {
  328. var allFiles = FileSystem.GetFilePaths(rootPath, true).ToList();
  329. return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  330. .Where(f => !string.IsNullOrEmpty(f))
  331. .ToList();
  332. }
  333. /// <summary>
  334. /// Gets a value indicating whether [is3 D].
  335. /// </summary>
  336. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  337. [IgnoreDataMember]
  338. public bool Is3D
  339. {
  340. get { return Video3DFormat.HasValue; }
  341. }
  342. /// <summary>
  343. /// Gets the type of the media.
  344. /// </summary>
  345. /// <value>The type of the media.</value>
  346. [IgnoreDataMember]
  347. public override string MediaType
  348. {
  349. get
  350. {
  351. return Model.Entities.MediaType.Video;
  352. }
  353. }
  354. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  355. {
  356. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  357. if (IsStacked)
  358. {
  359. var tasks = AdditionalParts
  360. .Select(i => RefreshMetadataForOwnedVideo(options, true, i, cancellationToken));
  361. await Task.WhenAll(tasks).ConfigureAwait(false);
  362. }
  363. // Must have a parent to have additional parts or alternate versions
  364. // In other words, it must be part of the Parent/Child tree
  365. // The additional parts won't have additional parts themselves
  366. if (LocationType == LocationType.FileSystem && GetParent() != null)
  367. {
  368. if (!IsStacked)
  369. {
  370. RefreshLinkedAlternateVersions();
  371. var tasks = LocalAlternateVersions
  372. .Select(i => RefreshMetadataForOwnedVideo(options, false, i, cancellationToken));
  373. await Task.WhenAll(tasks).ConfigureAwait(false);
  374. }
  375. }
  376. return hasChanges;
  377. }
  378. private void RefreshLinkedAlternateVersions()
  379. {
  380. foreach (var child in LinkedAlternateVersions)
  381. {
  382. // Reset the cached value
  383. if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
  384. {
  385. child.ItemId = null;
  386. }
  387. }
  388. }
  389. public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  390. {
  391. await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
  392. var localAlternates = GetLocalAlternateVersionIds()
  393. .Select(i => LibraryManager.GetItemById(i))
  394. .Where(i => i != null);
  395. foreach (var item in localAlternates)
  396. {
  397. item.ImageInfos = ImageInfos;
  398. item.Overview = Overview;
  399. item.ProductionYear = ProductionYear;
  400. item.PremiereDate = PremiereDate;
  401. item.CommunityRating = CommunityRating;
  402. item.OfficialRating = OfficialRating;
  403. item.Genres = Genres;
  404. item.ProviderIds = ProviderIds;
  405. await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
  406. }
  407. }
  408. public override IEnumerable<FileSystemMetadata> GetDeletePaths()
  409. {
  410. if (!DetectIsInMixedFolder())
  411. {
  412. return new[] {
  413. new FileSystemMetadata
  414. {
  415. FullName = ContainingFolderPath,
  416. IsDirectory = true
  417. }
  418. };
  419. }
  420. return base.GetDeletePaths();
  421. }
  422. public IEnumerable<MediaStream> GetMediaStreams()
  423. {
  424. var mediaSource = GetMediaSources(false)
  425. .FirstOrDefault();
  426. if (mediaSource == null)
  427. {
  428. return new List<MediaStream>();
  429. }
  430. return mediaSource.MediaStreams;
  431. }
  432. public virtual MediaStream GetDefaultVideoStream()
  433. {
  434. if (!DefaultVideoStreamIndex.HasValue)
  435. {
  436. return null;
  437. }
  438. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  439. {
  440. ItemId = Id,
  441. Index = DefaultVideoStreamIndex.Value
  442. }).FirstOrDefault();
  443. }
  444. private List<Tuple<Video, MediaSourceType>> GetAllVideosForMediaSources()
  445. {
  446. var list = new List<Tuple<Video, MediaSourceType>>();
  447. list.Add(new Tuple<Video, MediaSourceType>(this, MediaSourceType.Default));
  448. list.AddRange(GetLinkedAlternateVersions().Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  449. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  450. {
  451. var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  452. if (primary != null)
  453. {
  454. var existingIds = list.Select(i => i.Item1.Id).ToList();
  455. list.Add(new Tuple<Video, MediaSourceType>(primary, MediaSourceType.Grouping));
  456. list.AddRange(primary.GetLinkedAlternateVersions().Where(i => !existingIds.Contains(i.Id)).Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  457. }
  458. }
  459. var localAlternates = list
  460. .SelectMany(i => i.Item1.GetLocalAlternateVersionIds())
  461. .Select(LibraryManager.GetItemById)
  462. .Where(i => i != null)
  463. .OfType<Video>()
  464. .ToList();
  465. list.AddRange(localAlternates.Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Default)));
  466. return list;
  467. }
  468. public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  469. {
  470. if (SourceType == SourceType.Channel)
  471. {
  472. var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
  473. .Result.ToList();
  474. if (sources.Count > 0)
  475. {
  476. return sources;
  477. }
  478. return new List<MediaSourceInfo>
  479. {
  480. GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder)
  481. };
  482. }
  483. var list = GetAllVideosForMediaSources();
  484. var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList();
  485. return result.OrderBy(i =>
  486. {
  487. if (i.VideoType == VideoType.VideoFile)
  488. {
  489. return 0;
  490. }
  491. return 1;
  492. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  493. .ThenByDescending(i =>
  494. {
  495. var stream = i.VideoStream;
  496. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  497. })
  498. .ToList();
  499. }
  500. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type)
  501. {
  502. if (media == null)
  503. {
  504. throw new ArgumentNullException("media");
  505. }
  506. var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id)
  507. .ToList();
  508. var locationType = media.LocationType;
  509. var info = new MediaSourceInfo
  510. {
  511. Id = media.Id.ToString("N"),
  512. IsoType = media.IsoType,
  513. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  514. MediaStreams = mediaStreams,
  515. Name = GetMediaSourceName(media, mediaStreams),
  516. Path = enablePathSubstitution ? GetMappedPath(media, media.Path, locationType) : media.Path,
  517. RunTimeTicks = media.RunTimeTicks,
  518. Video3DFormat = media.Video3DFormat,
  519. VideoType = media.VideoType,
  520. Container = media.Container,
  521. Size = media.Size,
  522. Timestamp = media.Timestamp,
  523. Type = type,
  524. PlayableStreamFileNames = media.PlayableStreamFileNames.ToList(),
  525. SupportsDirectStream = media.VideoType == VideoType.VideoFile,
  526. IsRemote = media.IsShortcut
  527. };
  528. if (info.Protocol == MediaProtocol.File)
  529. {
  530. info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
  531. }
  532. if (media.IsShortcut)
  533. {
  534. info.Path = media.ShortcutPath;
  535. if (!string.IsNullOrWhiteSpace(info.Path))
  536. {
  537. if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
  538. {
  539. info.Protocol = MediaProtocol.Http;
  540. }
  541. else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
  542. {
  543. info.Protocol = MediaProtocol.Rtmp;
  544. }
  545. else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
  546. {
  547. info.Protocol = MediaProtocol.Rtsp;
  548. }
  549. else
  550. {
  551. info.Protocol = MediaProtocol.File;
  552. }
  553. }
  554. }
  555. if (string.IsNullOrEmpty(info.Container))
  556. {
  557. if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso)
  558. {
  559. if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  560. {
  561. info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.');
  562. }
  563. }
  564. }
  565. info.Bitrate = media.TotalBitrate;
  566. info.InferTotalBitrate();
  567. return info;
  568. }
  569. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  570. {
  571. var terms = new List<string>();
  572. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  573. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  574. if (video.Video3DFormat.HasValue)
  575. {
  576. terms.Add("3D");
  577. }
  578. if (video.VideoType == VideoType.BluRay)
  579. {
  580. terms.Add("Bluray");
  581. }
  582. else if (video.VideoType == VideoType.Dvd)
  583. {
  584. terms.Add("DVD");
  585. }
  586. else if (video.VideoType == VideoType.HdDvd)
  587. {
  588. terms.Add("HD-DVD");
  589. }
  590. else if (video.VideoType == VideoType.Iso)
  591. {
  592. if (video.IsoType.HasValue)
  593. {
  594. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  595. {
  596. terms.Add("Bluray");
  597. }
  598. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  599. {
  600. terms.Add("DVD");
  601. }
  602. }
  603. else
  604. {
  605. terms.Add("ISO");
  606. }
  607. }
  608. if (videoStream != null)
  609. {
  610. if (videoStream.Width.HasValue)
  611. {
  612. if (videoStream.Width.Value >= 3800)
  613. {
  614. terms.Add("4K");
  615. }
  616. else if (videoStream.Width.Value >= 1900)
  617. {
  618. terms.Add("1080P");
  619. }
  620. else if (videoStream.Width.Value >= 1270)
  621. {
  622. terms.Add("720P");
  623. }
  624. else if (videoStream.Width.Value >= 700)
  625. {
  626. terms.Add("480P");
  627. }
  628. else
  629. {
  630. terms.Add("SD");
  631. }
  632. }
  633. }
  634. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  635. {
  636. terms.Add(videoStream.Codec.ToUpper());
  637. }
  638. if (audioStream != null)
  639. {
  640. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  641. ? audioStream.Profile
  642. : audioStream.Codec;
  643. if (!string.IsNullOrEmpty(audioCodec))
  644. {
  645. terms.Add(audioCodec.ToUpper());
  646. }
  647. }
  648. return string.Join("/", terms.ToArray());
  649. }
  650. }
  651. }