Video.cs 24 KB

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