Video.cs 24 KB

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