Video.cs 24 KB

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