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