Video.cs 24 KB

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