Video.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704
  1. using MediaBrowser.Controller.Library;
  2. using MediaBrowser.Controller.Persistence;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Controller.Resolvers;
  5. using MediaBrowser.Model.Dto;
  6. using MediaBrowser.Model.Entities;
  7. using MediaBrowser.Model.MediaInfo;
  8. using System;
  9. using System.Collections;
  10. using System.Collections.Generic;
  11. using System.IO;
  12. using System.Linq;
  13. using System.Runtime.Serialization;
  14. using System.Threading;
  15. using System.Threading.Tasks;
  16. namespace MediaBrowser.Controller.Entities
  17. {
  18. /// <summary>
  19. /// Class Video
  20. /// </summary>
  21. public class Video : BaseItem,
  22. IHasAspectRatio,
  23. IHasTags,
  24. ISupportsPlaceHolders,
  25. IHasMediaSources,
  26. IHasShortOverview,
  27. IThemeMedia
  28. {
  29. public bool IsMultiPart { get; set; }
  30. public bool HasLocalAlternateVersions { get; set; }
  31. public Guid? PrimaryVersionId { get; set; }
  32. public List<Guid> AdditionalPartIds { get; set; }
  33. public List<Guid> LocalAlternateVersionIds { get; set; }
  34. public bool IsThemeMedia { get; set; }
  35. public string FormatName { get; set; }
  36. public long? Size { get; set; }
  37. public string Container { get; set; }
  38. public int? TotalBitrate { get; set; }
  39. public string ShortOverview { get; set; }
  40. public ExtraType ExtraType { get; set; }
  41. /// <summary>
  42. /// Gets or sets the timestamp.
  43. /// </summary>
  44. /// <value>The timestamp.</value>
  45. public TransportStreamTimestamp? Timestamp { get; set; }
  46. public Video()
  47. {
  48. PlayableStreamFileNames = new List<string>();
  49. AdditionalPartIds = new List<Guid>();
  50. LocalAlternateVersionIds = new List<Guid>();
  51. Tags = new List<string>();
  52. SubtitleFiles = new List<string>();
  53. LinkedAlternateVersions = new List<LinkedChild>();
  54. }
  55. [IgnoreDataMember]
  56. public override bool SupportsAddingToPlaylist
  57. {
  58. get { return LocationType == LocationType.FileSystem && RunTimeTicks.HasValue; }
  59. }
  60. [IgnoreDataMember]
  61. public int MediaSourceCount
  62. {
  63. get
  64. {
  65. return LinkedAlternateVersions.Count + LocalAlternateVersionIds.Count + 1;
  66. }
  67. }
  68. public List<LinkedChild> LinkedAlternateVersions { get; set; }
  69. /// <summary>
  70. /// Gets the linked children.
  71. /// </summary>
  72. /// <returns>IEnumerable{BaseItem}.</returns>
  73. public IEnumerable<Video> GetAlternateVersions()
  74. {
  75. var filesWithinSameDirectory = LocalAlternateVersionIds
  76. .Select(i => LibraryManager.GetItemById(i))
  77. .Where(i => i != null)
  78. .OfType<Video>();
  79. return filesWithinSameDirectory.Concat(GetLinkedAlternateVersions())
  80. .OrderBy(i => i.SortName);
  81. }
  82. public IEnumerable<Video> GetLinkedAlternateVersions()
  83. {
  84. var linkedVersions = LinkedAlternateVersions
  85. .Select(GetLinkedChild)
  86. .Where(i => i != null)
  87. .OfType<Video>();
  88. return linkedVersions
  89. .OrderBy(i => i.SortName);
  90. }
  91. /// <summary>
  92. /// Gets the additional parts.
  93. /// </summary>
  94. /// <returns>IEnumerable{Video}.</returns>
  95. public IEnumerable<Video> GetAdditionalParts()
  96. {
  97. return AdditionalPartIds
  98. .Select(i => LibraryManager.GetItemById(i))
  99. .Where(i => i != null)
  100. .OfType<Video>()
  101. .OrderBy(i => i.SortName);
  102. }
  103. /// <summary>
  104. /// Gets or sets the subtitle paths.
  105. /// </summary>
  106. /// <value>The subtitle paths.</value>
  107. public List<string> SubtitleFiles { get; set; }
  108. /// <summary>
  109. /// Gets or sets a value indicating whether this instance has subtitles.
  110. /// </summary>
  111. /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
  112. public bool HasSubtitles { get; set; }
  113. public bool IsPlaceHolder { get; set; }
  114. public bool IsShortcut { get; set; }
  115. /// <summary>
  116. /// Gets or sets the tags.
  117. /// </summary>
  118. /// <value>The tags.</value>
  119. public List<string> Tags { get; set; }
  120. /// <summary>
  121. /// Gets or sets the video bit rate.
  122. /// </summary>
  123. /// <value>The video bit rate.</value>
  124. public int? VideoBitRate { get; set; }
  125. /// <summary>
  126. /// Gets or sets the default index of the video stream.
  127. /// </summary>
  128. /// <value>The default index of the video stream.</value>
  129. public int? DefaultVideoStreamIndex { get; set; }
  130. /// <summary>
  131. /// Gets or sets the type of the video.
  132. /// </summary>
  133. /// <value>The type of the video.</value>
  134. public VideoType VideoType { get; set; }
  135. /// <summary>
  136. /// Gets or sets the type of the iso.
  137. /// </summary>
  138. /// <value>The type of the iso.</value>
  139. public IsoType? IsoType { get; set; }
  140. /// <summary>
  141. /// Gets or sets the video3 D format.
  142. /// </summary>
  143. /// <value>The video3 D format.</value>
  144. public Video3DFormat? Video3DFormat { get; set; }
  145. /// <summary>
  146. /// If the video is a folder-rip, this will hold the file list for the largest playlist
  147. /// </summary>
  148. public List<string> PlayableStreamFileNames { get; set; }
  149. /// <summary>
  150. /// Gets the playable stream files.
  151. /// </summary>
  152. /// <returns>List{System.String}.</returns>
  153. public List<string> GetPlayableStreamFiles()
  154. {
  155. return GetPlayableStreamFiles(Path);
  156. }
  157. /// <summary>
  158. /// Gets or sets the aspect ratio.
  159. /// </summary>
  160. /// <value>The aspect ratio.</value>
  161. public string AspectRatio { get; set; }
  162. [IgnoreDataMember]
  163. public override string ContainingFolderPath
  164. {
  165. get
  166. {
  167. if (IsMultiPart)
  168. {
  169. return System.IO.Path.GetDirectoryName(Path);
  170. }
  171. if (!IsPlaceHolder)
  172. {
  173. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd ||
  174. VideoType == VideoType.HdDvd)
  175. {
  176. return Path;
  177. }
  178. }
  179. return base.ContainingFolderPath;
  180. }
  181. }
  182. public string MainFeaturePlaylistName { get; set; }
  183. /// <summary>
  184. /// Gets the playable stream files.
  185. /// </summary>
  186. /// <param name="rootPath">The root path.</param>
  187. /// <returns>List{System.String}.</returns>
  188. public List<string> GetPlayableStreamFiles(string rootPath)
  189. {
  190. var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();
  191. return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  192. .Where(f => !string.IsNullOrEmpty(f))
  193. .ToList();
  194. }
  195. /// <summary>
  196. /// Gets a value indicating whether [is3 D].
  197. /// </summary>
  198. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  199. [IgnoreDataMember]
  200. public bool Is3D
  201. {
  202. get { return Video3DFormat.HasValue; }
  203. }
  204. public bool IsHD { get; set; }
  205. /// <summary>
  206. /// Gets the type of the media.
  207. /// </summary>
  208. /// <value>The type of the media.</value>
  209. [IgnoreDataMember]
  210. public override string MediaType
  211. {
  212. get
  213. {
  214. return Model.Entities.MediaType.Video;
  215. }
  216. }
  217. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  218. {
  219. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  220. // Must have a parent to have additional parts or alternate versions
  221. // In other words, it must be part of the Parent/Child tree
  222. // The additional parts won't have additional parts themselves
  223. if (LocationType == LocationType.FileSystem && Parent != null)
  224. {
  225. if (IsMultiPart)
  226. {
  227. var additionalPartsChanged = await RefreshAdditionalParts(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  228. if (additionalPartsChanged)
  229. {
  230. hasChanges = true;
  231. }
  232. }
  233. else
  234. {
  235. RefreshLinkedAlternateVersions();
  236. var additionalPartsChanged = await RefreshAlternateVersionsWithinSameDirectory(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  237. if (additionalPartsChanged)
  238. {
  239. hasChanges = true;
  240. }
  241. }
  242. }
  243. return hasChanges;
  244. }
  245. private bool RefreshLinkedAlternateVersions()
  246. {
  247. foreach (var child in LinkedAlternateVersions)
  248. {
  249. // Reset the cached value
  250. if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
  251. {
  252. child.ItemId = null;
  253. }
  254. }
  255. return false;
  256. }
  257. /// <summary>
  258. /// Refreshes the additional parts.
  259. /// </summary>
  260. /// <param name="options">The options.</param>
  261. /// <param name="fileSystemChildren">The file system children.</param>
  262. /// <param name="cancellationToken">The cancellation token.</param>
  263. /// <returns>Task{System.Boolean}.</returns>
  264. private async Task<bool> RefreshAdditionalParts(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  265. {
  266. var newItems = LoadAdditionalParts(fileSystemChildren, options.DirectoryService).ToList();
  267. var newItemIds = newItems.Select(i => i.Id).ToList();
  268. var itemsChanged = !AdditionalPartIds.SequenceEqual(newItemIds);
  269. var tasks = newItems.Select(i => i.RefreshMetadata(options, cancellationToken));
  270. await Task.WhenAll(tasks).ConfigureAwait(false);
  271. AdditionalPartIds = newItemIds;
  272. return itemsChanged;
  273. }
  274. /// <summary>
  275. /// Loads the additional parts.
  276. /// </summary>
  277. /// <returns>IEnumerable{Video}.</returns>
  278. private IEnumerable<Video> LoadAdditionalParts(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
  279. {
  280. IEnumerable<FileSystemInfo> files;
  281. var path = Path;
  282. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
  283. {
  284. files = fileSystemChildren.Where(i =>
  285. {
  286. if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  287. {
  288. return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsMultiPartFolder(i.FullName);
  289. }
  290. return false;
  291. });
  292. }
  293. else
  294. {
  295. files = fileSystemChildren.Where(i =>
  296. {
  297. if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  298. {
  299. return false;
  300. }
  301. return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) && EntityResolutionHelper.IsVideoFile(i.FullName) && EntityResolutionHelper.IsMultiPartFile(i.Name);
  302. });
  303. }
  304. return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
  305. {
  306. // Try to retrieve it from the db. If we don't find it, use the resolved version
  307. var dbItem = LibraryManager.GetItemById(video.Id) as Video;
  308. if (dbItem != null)
  309. {
  310. video = dbItem;
  311. }
  312. return video;
  313. // Sort them so that the list can be easily compared for changes
  314. }).OrderBy(i => i.Path).ToList();
  315. }
  316. private async Task<bool> RefreshAlternateVersionsWithinSameDirectory(MetadataRefreshOptions options, IEnumerable<FileSystemInfo> fileSystemChildren, CancellationToken cancellationToken)
  317. {
  318. var newItems = HasLocalAlternateVersions ?
  319. LoadAlternateVersionsWithinSameDirectory(fileSystemChildren, options.DirectoryService).ToList() :
  320. new List<Video>();
  321. var newItemIds = newItems.Select(i => i.Id).ToList();
  322. var itemsChanged = !LocalAlternateVersionIds.SequenceEqual(newItemIds);
  323. var tasks = newItems.Select(i => RefreshAlternateVersion(options, i, cancellationToken));
  324. await Task.WhenAll(tasks).ConfigureAwait(false);
  325. LocalAlternateVersionIds = newItemIds;
  326. return itemsChanged;
  327. }
  328. private Task RefreshAlternateVersion(MetadataRefreshOptions options, Video video, CancellationToken cancellationToken)
  329. {
  330. var currentImagePath = video.GetImagePath(ImageType.Primary);
  331. var ownerImagePath = this.GetImagePath(ImageType.Primary);
  332. var newOptions = new MetadataRefreshOptions
  333. {
  334. DirectoryService = options.DirectoryService,
  335. ImageRefreshMode = options.ImageRefreshMode,
  336. MetadataRefreshMode = options.MetadataRefreshMode,
  337. ReplaceAllMetadata = options.ReplaceAllMetadata
  338. };
  339. if (!string.Equals(currentImagePath, ownerImagePath, StringComparison.OrdinalIgnoreCase))
  340. {
  341. newOptions.ForceSave = true;
  342. if (string.IsNullOrWhiteSpace(ownerImagePath))
  343. {
  344. video.ImageInfos.Clear();
  345. }
  346. else
  347. {
  348. video.SetImagePath(ImageType.Primary, ownerImagePath);
  349. }
  350. }
  351. return video.RefreshMetadata(newOptions, cancellationToken);
  352. }
  353. public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  354. {
  355. await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
  356. foreach (var item in LocalAlternateVersionIds.Select(i => LibraryManager.GetItemById(i)))
  357. {
  358. item.ImageInfos = ImageInfos;
  359. item.Overview = Overview;
  360. item.ProductionYear = ProductionYear;
  361. item.PremiereDate = PremiereDate;
  362. item.CommunityRating = CommunityRating;
  363. item.OfficialRating = OfficialRating;
  364. item.Genres = Genres;
  365. item.ProviderIds = ProviderIds;
  366. await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
  367. }
  368. }
  369. /// <summary>
  370. /// Loads the additional parts.
  371. /// </summary>
  372. /// <returns>IEnumerable{Video}.</returns>
  373. private IEnumerable<Video> LoadAlternateVersionsWithinSameDirectory(IEnumerable<FileSystemInfo> fileSystemChildren, IDirectoryService directoryService)
  374. {
  375. IEnumerable<FileSystemInfo> files;
  376. // Only support this for video files. For folder rips, they'll have to use the linking feature
  377. if (VideoType == VideoType.VideoFile || VideoType == VideoType.Iso)
  378. {
  379. var path = Path;
  380. var filenamePrefix = System.IO.Path.GetFileName(System.IO.Path.GetDirectoryName(path));
  381. files = fileSystemChildren.Where(i =>
  382. {
  383. if ((i.Attributes & FileAttributes.Directory) == FileAttributes.Directory)
  384. {
  385. return false;
  386. }
  387. return !string.Equals(i.FullName, path, StringComparison.OrdinalIgnoreCase) &&
  388. EntityResolutionHelper.IsVideoFile(i.FullName) &&
  389. i.Name.StartsWith(filenamePrefix + " - ", StringComparison.OrdinalIgnoreCase);
  390. });
  391. }
  392. else
  393. {
  394. files = new List<FileSystemInfo>();
  395. }
  396. return LibraryManager.ResolvePaths<Video>(files, directoryService, null).Select(video =>
  397. {
  398. // Try to retrieve it from the db. If we don't find it, use the resolved version
  399. var dbItem = LibraryManager.GetItemById(video.Id) as Video;
  400. if (dbItem != null)
  401. {
  402. video = dbItem;
  403. }
  404. video.PrimaryVersionId = Id;
  405. return video;
  406. // Sort them so that the list can be easily compared for changes
  407. }).OrderBy(i => i.Path).ToList();
  408. }
  409. public override IEnumerable<string> GetDeletePaths()
  410. {
  411. if (!IsInMixedFolder)
  412. {
  413. return new[] { ContainingFolderPath };
  414. }
  415. return base.GetDeletePaths();
  416. }
  417. public virtual IEnumerable<MediaStream> GetMediaStreams()
  418. {
  419. return ItemRepository.GetMediaStreams(new MediaStreamQuery
  420. {
  421. ItemId = Id
  422. });
  423. }
  424. public virtual MediaStream GetDefaultVideoStream()
  425. {
  426. if (!DefaultVideoStreamIndex.HasValue)
  427. {
  428. return null;
  429. }
  430. return ItemRepository.GetMediaStreams(new MediaStreamQuery
  431. {
  432. ItemId = Id,
  433. Index = DefaultVideoStreamIndex.Value
  434. }).FirstOrDefault();
  435. }
  436. public virtual IEnumerable<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  437. {
  438. var item = this;
  439. var result = item.GetAlternateVersions()
  440. .Select(i => GetVersionInfo(enablePathSubstitution, i, MediaSourceType.Grouping))
  441. .ToList();
  442. result.Add(GetVersionInfo(enablePathSubstitution, item, MediaSourceType.Default));
  443. return result.OrderBy(i =>
  444. {
  445. if (item.VideoType == VideoType.VideoFile)
  446. {
  447. return 0;
  448. }
  449. return 1;
  450. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  451. .ThenByDescending(i =>
  452. {
  453. var stream = i.VideoStream;
  454. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  455. })
  456. .ToList();
  457. }
  458. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video i, MediaSourceType type)
  459. {
  460. var mediaStreams = ItemRepository.GetMediaStreams(new MediaStreamQuery { ItemId = i.Id }).ToList();
  461. var locationType = i.LocationType;
  462. var info = new MediaSourceInfo
  463. {
  464. Id = i.Id.ToString("N"),
  465. IsoType = i.IsoType,
  466. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  467. MediaStreams = mediaStreams,
  468. Name = GetMediaSourceName(i, mediaStreams),
  469. Path = enablePathSubstitution ? GetMappedPath(i.Path, locationType) : i.Path,
  470. RunTimeTicks = i.RunTimeTicks,
  471. Video3DFormat = i.Video3DFormat,
  472. VideoType = i.VideoType,
  473. Container = i.Container,
  474. Size = i.Size,
  475. Formats = (i.FormatName ?? string.Empty).Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(),
  476. Timestamp = i.Timestamp,
  477. Type = type,
  478. PlayableStreamFileNames = i.PlayableStreamFileNames.ToList()
  479. };
  480. if (string.IsNullOrEmpty(info.Container))
  481. {
  482. if (i.VideoType == VideoType.VideoFile || i.VideoType == VideoType.Iso)
  483. {
  484. if (!string.IsNullOrWhiteSpace(i.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  485. {
  486. info.Container = System.IO.Path.GetExtension(i.Path).TrimStart('.');
  487. }
  488. }
  489. }
  490. try
  491. {
  492. var bitrate = i.TotalBitrate ??
  493. info.MediaStreams.Where(m => m.Type != MediaStreamType.Subtitle && !string.Equals(m.Codec, "mjpeg", StringComparison.OrdinalIgnoreCase))
  494. .Select(m => m.BitRate ?? 0)
  495. .Sum();
  496. if (bitrate > 0)
  497. {
  498. info.Bitrate = bitrate;
  499. }
  500. }
  501. catch (OverflowException ex)
  502. {
  503. Logger.ErrorException("Error calculating total bitrate", ex);
  504. }
  505. return info;
  506. }
  507. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  508. {
  509. var terms = new List<string>();
  510. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  511. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  512. if (video.Video3DFormat.HasValue)
  513. {
  514. terms.Add("3D");
  515. }
  516. if (video.VideoType == VideoType.BluRay)
  517. {
  518. terms.Add("Bluray");
  519. }
  520. else if (video.VideoType == VideoType.Dvd)
  521. {
  522. terms.Add("DVD");
  523. }
  524. else if (video.VideoType == VideoType.HdDvd)
  525. {
  526. terms.Add("HD-DVD");
  527. }
  528. else if (video.VideoType == VideoType.Iso)
  529. {
  530. if (video.IsoType.HasValue)
  531. {
  532. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  533. {
  534. terms.Add("Bluray");
  535. }
  536. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  537. {
  538. terms.Add("DVD");
  539. }
  540. }
  541. else
  542. {
  543. terms.Add("ISO");
  544. }
  545. }
  546. if (videoStream != null)
  547. {
  548. if (videoStream.Width.HasValue)
  549. {
  550. if (videoStream.Width.Value >= 3800)
  551. {
  552. terms.Add("4K");
  553. }
  554. else if (videoStream.Width.Value >= 1900)
  555. {
  556. terms.Add("1080P");
  557. }
  558. else if (videoStream.Width.Value >= 1270)
  559. {
  560. terms.Add("720P");
  561. }
  562. else if (videoStream.Width.Value >= 700)
  563. {
  564. terms.Add("480P");
  565. }
  566. else
  567. {
  568. terms.Add("SD");
  569. }
  570. }
  571. }
  572. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  573. {
  574. terms.Add(videoStream.Codec.ToUpper());
  575. }
  576. if (audioStream != null)
  577. {
  578. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  579. ? audioStream.Profile
  580. : audioStream.Codec;
  581. if (!string.IsNullOrEmpty(audioCodec))
  582. {
  583. terms.Add(audioCodec.ToUpper());
  584. }
  585. }
  586. return string.Join("/", terms.ToArray());
  587. }
  588. }
  589. }