Video.cs 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831
  1. using MediaBrowser.Controller.Library;
  2. using MediaBrowser.Controller.Persistence;
  3. using MediaBrowser.Controller.Providers;
  4. using MediaBrowser.Model.Dto;
  5. using MediaBrowser.Model.Entities;
  6. using MediaBrowser.Model.MediaInfo;
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Globalization;
  10. using System.Linq;
  11. using System.Threading;
  12. using System.Threading.Tasks;
  13. using MediaBrowser.Common.Extensions;
  14. using MediaBrowser.Controller.Channels;
  15. using MediaBrowser.Controller.IO;
  16. using MediaBrowser.Model.IO;
  17. using MediaBrowser.Model.Serialization;
  18. using MediaBrowser.Model.Extensions;
  19. namespace MediaBrowser.Controller.Entities
  20. {
  21. /// <summary>
  22. /// Class Video
  23. /// </summary>
  24. public class Video : BaseItem,
  25. IHasAspectRatio,
  26. ISupportsPlaceHolders,
  27. IHasMediaSources
  28. {
  29. [IgnoreDataMember]
  30. public string PrimaryVersionId { get; set; }
  31. public string[] AdditionalParts { get; set; }
  32. public string[] LocalAlternateVersions { get; set; }
  33. public LinkedChild[] LinkedAlternateVersions { get; set; }
  34. [IgnoreDataMember]
  35. public override bool SupportsPlayedStatus
  36. {
  37. get
  38. {
  39. return true;
  40. }
  41. }
  42. [IgnoreDataMember]
  43. public override bool SupportsInheritedParentImages
  44. {
  45. get
  46. {
  47. return true;
  48. }
  49. }
  50. [IgnoreDataMember]
  51. public override bool SupportsPositionTicksResume
  52. {
  53. get
  54. {
  55. var extraType = ExtraType;
  56. if (extraType.HasValue)
  57. {
  58. if (extraType.Value == Model.Entities.ExtraType.Sample)
  59. {
  60. return false;
  61. }
  62. if (extraType.Value == Model.Entities.ExtraType.ThemeVideo)
  63. {
  64. return false;
  65. }
  66. if (extraType.Value == Model.Entities.ExtraType.Trailer)
  67. {
  68. return false;
  69. }
  70. }
  71. return true;
  72. }
  73. }
  74. public override double? GetDefaultPrimaryImageAspectRatio()
  75. {
  76. double value = 16;
  77. value /= 9;
  78. return value;
  79. }
  80. public override string CreatePresentationUniqueKey()
  81. {
  82. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  83. {
  84. return PrimaryVersionId;
  85. }
  86. return base.CreatePresentationUniqueKey();
  87. }
  88. [IgnoreDataMember]
  89. public override bool EnableRefreshOnDateModifiedChange
  90. {
  91. get
  92. {
  93. return VideoType == VideoType.VideoFile || VideoType == VideoType.Iso;
  94. }
  95. }
  96. [IgnoreDataMember]
  97. public override bool SupportsThemeMedia
  98. {
  99. get { return true; }
  100. }
  101. /// <summary>
  102. /// Gets or sets the timestamp.
  103. /// </summary>
  104. /// <value>The timestamp.</value>
  105. public TransportStreamTimestamp? Timestamp { get; set; }
  106. /// <summary>
  107. /// Gets or sets the subtitle paths.
  108. /// </summary>
  109. /// <value>The subtitle paths.</value>
  110. public string[] SubtitleFiles { get; set; }
  111. /// <summary>
  112. /// Gets or sets a value indicating whether this instance has subtitles.
  113. /// </summary>
  114. /// <value><c>true</c> if this instance has subtitles; otherwise, <c>false</c>.</value>
  115. public bool HasSubtitles { get; set; }
  116. public bool IsPlaceHolder { get; set; }
  117. public bool IsShortcut { get; set; }
  118. public string ShortcutPath { get; set; }
  119. /// <summary>
  120. /// Gets or sets the default index of the video stream.
  121. /// </summary>
  122. /// <value>The default index of the video stream.</value>
  123. public int? DefaultVideoStreamIndex { get; set; }
  124. /// <summary>
  125. /// Gets or sets the type of the video.
  126. /// </summary>
  127. /// <value>The type of the video.</value>
  128. public VideoType VideoType { get; set; }
  129. /// <summary>
  130. /// Gets or sets the type of the iso.
  131. /// </summary>
  132. /// <value>The type of the iso.</value>
  133. public IsoType? IsoType { get; set; }
  134. /// <summary>
  135. /// Gets or sets the video3 D format.
  136. /// </summary>
  137. /// <value>The video3 D format.</value>
  138. public Video3DFormat? Video3DFormat { get; set; }
  139. public string[] GetPlayableStreamFileNames()
  140. {
  141. var videoType = VideoType;
  142. if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.BluRay)
  143. {
  144. videoType = VideoType.BluRay;
  145. }
  146. else if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.Dvd)
  147. {
  148. videoType = VideoType.Dvd;
  149. }
  150. else
  151. {
  152. return new string[] { };
  153. }
  154. return MediaEncoder.GetPlayableStreamFileNames(Path, videoType);
  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. public Video()
  162. {
  163. AdditionalParts = EmptyStringArray;
  164. LocalAlternateVersions = EmptyStringArray;
  165. SubtitleFiles = EmptyStringArray;
  166. LinkedAlternateVersions = EmptyLinkedChildArray;
  167. }
  168. public override bool CanDownload()
  169. {
  170. if (VideoType == VideoType.Dvd || VideoType == VideoType.BluRay)
  171. {
  172. return false;
  173. }
  174. var locationType = LocationType;
  175. return locationType != LocationType.Remote &&
  176. locationType != LocationType.Virtual;
  177. }
  178. [IgnoreDataMember]
  179. public override bool SupportsAddingToPlaylist
  180. {
  181. get { return true; }
  182. }
  183. [IgnoreDataMember]
  184. public int MediaSourceCount
  185. {
  186. get
  187. {
  188. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  189. {
  190. var item = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  191. if (item != null)
  192. {
  193. return item.MediaSourceCount;
  194. }
  195. }
  196. return LinkedAlternateVersions.Length + LocalAlternateVersions.Length + 1;
  197. }
  198. }
  199. [IgnoreDataMember]
  200. public bool IsStacked
  201. {
  202. get { return AdditionalParts.Length > 0; }
  203. }
  204. [IgnoreDataMember]
  205. public bool HasLocalAlternateVersions
  206. {
  207. get { return LocalAlternateVersions.Length > 0; }
  208. }
  209. public IEnumerable<Guid> GetAdditionalPartIds()
  210. {
  211. return AdditionalParts.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
  212. }
  213. public IEnumerable<Guid> GetLocalAlternateVersionIds()
  214. {
  215. return LocalAlternateVersions.Select(i => LibraryManager.GetNewItemId(i, typeof(Video)));
  216. }
  217. [IgnoreDataMember]
  218. public override SourceType SourceType
  219. {
  220. get
  221. {
  222. if (IsActiveRecording())
  223. {
  224. return SourceType.LiveTV;
  225. }
  226. return base.SourceType;
  227. }
  228. }
  229. protected bool IsActiveRecording()
  230. {
  231. return LiveTvManager.GetActiveRecordingInfo(Path) != null;
  232. }
  233. public override bool CanDelete()
  234. {
  235. if (IsActiveRecording())
  236. {
  237. return false;
  238. }
  239. return base.CanDelete();
  240. }
  241. [IgnoreDataMember]
  242. public bool IsCompleteMedia
  243. {
  244. get { return !IsActiveRecording(); }
  245. }
  246. [IgnoreDataMember]
  247. protected virtual bool EnableDefaultVideoUserDataKeys
  248. {
  249. get
  250. {
  251. return true;
  252. }
  253. }
  254. public override List<string> GetUserDataKeys()
  255. {
  256. var list = base.GetUserDataKeys();
  257. if (EnableDefaultVideoUserDataKeys)
  258. {
  259. if (ExtraType.HasValue)
  260. {
  261. var key = this.GetProviderId(MetadataProviders.Tmdb);
  262. if (!string.IsNullOrWhiteSpace(key))
  263. {
  264. list.Insert(0, GetUserDataKey(key));
  265. }
  266. key = this.GetProviderId(MetadataProviders.Imdb);
  267. if (!string.IsNullOrWhiteSpace(key))
  268. {
  269. list.Insert(0, GetUserDataKey(key));
  270. }
  271. }
  272. else
  273. {
  274. var key = this.GetProviderId(MetadataProviders.Imdb);
  275. if (!string.IsNullOrWhiteSpace(key))
  276. {
  277. list.Insert(0, key);
  278. }
  279. key = this.GetProviderId(MetadataProviders.Tmdb);
  280. if (!string.IsNullOrWhiteSpace(key))
  281. {
  282. list.Insert(0, key);
  283. }
  284. }
  285. }
  286. return list;
  287. }
  288. private string GetUserDataKey(string providerId)
  289. {
  290. var key = providerId + "-" + ExtraType.ToString().ToLower();
  291. // Make sure different trailers have their own data.
  292. if (RunTimeTicks.HasValue)
  293. {
  294. key += "-" + RunTimeTicks.Value.ToString(CultureInfo.InvariantCulture);
  295. }
  296. return key;
  297. }
  298. public IEnumerable<Video> GetLinkedAlternateVersions()
  299. {
  300. return LinkedAlternateVersions
  301. .Select(GetLinkedChild)
  302. .Where(i => i != null)
  303. .OfType<Video>()
  304. .OrderBy(i => i.SortName);
  305. }
  306. /// <summary>
  307. /// Gets the additional parts.
  308. /// </summary>
  309. /// <returns>IEnumerable{Video}.</returns>
  310. public IEnumerable<Video> GetAdditionalParts()
  311. {
  312. return GetAdditionalPartIds()
  313. .Select(i => LibraryManager.GetItemById(i))
  314. .Where(i => i != null)
  315. .OfType<Video>()
  316. .OrderBy(i => i.SortName);
  317. }
  318. [IgnoreDataMember]
  319. public override string ContainingFolderPath
  320. {
  321. get
  322. {
  323. if (IsStacked)
  324. {
  325. return FileSystem.GetDirectoryName(Path);
  326. }
  327. if (!IsPlaceHolder)
  328. {
  329. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
  330. {
  331. return Path;
  332. }
  333. }
  334. return base.ContainingFolderPath;
  335. }
  336. }
  337. [IgnoreDataMember]
  338. public override string FileNameWithoutExtension
  339. {
  340. get
  341. {
  342. if (LocationType == LocationType.FileSystem)
  343. {
  344. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd)
  345. {
  346. return System.IO.Path.GetFileName(Path);
  347. }
  348. return System.IO.Path.GetFileNameWithoutExtension(Path);
  349. }
  350. return null;
  351. }
  352. }
  353. internal override bool IsValidFromResolver(BaseItem newItem)
  354. {
  355. var current = this;
  356. var newAsVideo = newItem as Video;
  357. if (newAsVideo != null)
  358. {
  359. if (!current.AdditionalParts.SequenceEqual(newAsVideo.AdditionalParts, StringComparer.OrdinalIgnoreCase))
  360. {
  361. return false;
  362. }
  363. if (!current.LocalAlternateVersions.SequenceEqual(newAsVideo.LocalAlternateVersions, StringComparer.OrdinalIgnoreCase))
  364. {
  365. return false;
  366. }
  367. if (newAsVideo.VideoType != VideoType)
  368. {
  369. return false;
  370. }
  371. }
  372. return base.IsValidFromResolver(newItem);
  373. }
  374. public static string[] QueryPlayableStreamFiles(string rootPath, VideoType videoType)
  375. {
  376. if (videoType == VideoType.Dvd)
  377. {
  378. return FileSystem.GetFiles(rootPath, new[] { ".vob" }, false, true)
  379. .OrderByDescending(i => i.Length)
  380. .ThenBy(i => i.FullName)
  381. .Take(1)
  382. .Select(i => i.FullName)
  383. .ToArray();
  384. }
  385. if (videoType == VideoType.BluRay)
  386. {
  387. return FileSystem.GetFiles(rootPath, new[] { ".m2ts" }, false, true)
  388. .OrderByDescending(i => i.Length)
  389. .ThenBy(i => i.FullName)
  390. .Take(1)
  391. .Select(i => i.FullName)
  392. .ToArray();
  393. }
  394. return new string[] { };
  395. }
  396. /// <summary>
  397. /// Gets a value indicating whether [is3 D].
  398. /// </summary>
  399. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  400. [IgnoreDataMember]
  401. public bool Is3D
  402. {
  403. get { return Video3DFormat.HasValue; }
  404. }
  405. /// <summary>
  406. /// Gets the type of the media.
  407. /// </summary>
  408. /// <value>The type of the media.</value>
  409. [IgnoreDataMember]
  410. public override string MediaType
  411. {
  412. get
  413. {
  414. return Model.Entities.MediaType.Video;
  415. }
  416. }
  417. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  418. {
  419. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  420. if (IsStacked)
  421. {
  422. var tasks = AdditionalParts
  423. .Select(i => RefreshMetadataForOwnedVideo(options, true, i, cancellationToken));
  424. await Task.WhenAll(tasks).ConfigureAwait(false);
  425. }
  426. // Must have a parent to have additional parts or alternate versions
  427. // In other words, it must be part of the Parent/Child tree
  428. // The additional parts won't have additional parts themselves
  429. if (LocationType == LocationType.FileSystem && GetParent() != null)
  430. {
  431. if (!IsStacked)
  432. {
  433. RefreshLinkedAlternateVersions();
  434. var tasks = LocalAlternateVersions
  435. .Select(i => RefreshMetadataForOwnedVideo(options, false, i, cancellationToken));
  436. await Task.WhenAll(tasks).ConfigureAwait(false);
  437. }
  438. }
  439. return hasChanges;
  440. }
  441. private void RefreshLinkedAlternateVersions()
  442. {
  443. foreach (var child in LinkedAlternateVersions)
  444. {
  445. // Reset the cached value
  446. if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
  447. {
  448. child.ItemId = null;
  449. }
  450. }
  451. }
  452. public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  453. {
  454. await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
  455. var localAlternates = GetLocalAlternateVersionIds()
  456. .Select(i => LibraryManager.GetItemById(i))
  457. .Where(i => i != null);
  458. foreach (var item in localAlternates)
  459. {
  460. item.ImageInfos = ImageInfos;
  461. item.Overview = Overview;
  462. item.ProductionYear = ProductionYear;
  463. item.PremiereDate = PremiereDate;
  464. item.CommunityRating = CommunityRating;
  465. item.OfficialRating = OfficialRating;
  466. item.Genres = Genres;
  467. item.ProviderIds = ProviderIds;
  468. await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
  469. }
  470. }
  471. public override IEnumerable<FileSystemMetadata> GetDeletePaths()
  472. {
  473. if (!IsInMixedFolder)
  474. {
  475. return new[] {
  476. new FileSystemMetadata
  477. {
  478. FullName = ContainingFolderPath,
  479. IsDirectory = true
  480. }
  481. };
  482. }
  483. return base.GetDeletePaths();
  484. }
  485. public List<MediaStream> GetMediaStreams()
  486. {
  487. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  488. {
  489. ItemId = Id
  490. });
  491. }
  492. public virtual MediaStream GetDefaultVideoStream()
  493. {
  494. if (!DefaultVideoStreamIndex.HasValue)
  495. {
  496. return null;
  497. }
  498. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  499. {
  500. ItemId = Id,
  501. Index = DefaultVideoStreamIndex.Value
  502. }).FirstOrDefault();
  503. }
  504. private List<Tuple<Video, MediaSourceType>> GetAllVideosForMediaSources()
  505. {
  506. var list = new List<Tuple<Video, MediaSourceType>>();
  507. list.Add(new Tuple<Video, MediaSourceType>(this, MediaSourceType.Default));
  508. list.AddRange(GetLinkedAlternateVersions().Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  509. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  510. {
  511. var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  512. if (primary != null)
  513. {
  514. var existingIds = list.Select(i => i.Item1.Id).ToList();
  515. list.Add(new Tuple<Video, MediaSourceType>(primary, MediaSourceType.Grouping));
  516. list.AddRange(primary.GetLinkedAlternateVersions().Where(i => !existingIds.Contains(i.Id)).Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  517. }
  518. }
  519. var localAlternates = list
  520. .SelectMany(i => i.Item1.GetLocalAlternateVersionIds())
  521. .Select(LibraryManager.GetItemById)
  522. .Where(i => i != null)
  523. .OfType<Video>()
  524. .ToList();
  525. list.AddRange(localAlternates.Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Default)));
  526. return list;
  527. }
  528. public virtual List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  529. {
  530. if (SourceType == SourceType.Channel)
  531. {
  532. var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
  533. .ToList();
  534. if (sources.Count > 0)
  535. {
  536. return sources;
  537. }
  538. return new List<MediaSourceInfo>
  539. {
  540. GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder)
  541. };
  542. }
  543. var list = GetAllVideosForMediaSources();
  544. var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList();
  545. if (IsActiveRecording())
  546. {
  547. foreach (var mediaSource in result)
  548. {
  549. mediaSource.Type = MediaSourceType.Placeholder;
  550. }
  551. }
  552. return result.OrderBy(i =>
  553. {
  554. if (i.VideoType == VideoType.VideoFile)
  555. {
  556. return 0;
  557. }
  558. return 1;
  559. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  560. .ThenByDescending(i =>
  561. {
  562. var stream = i.VideoStream;
  563. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  564. })
  565. .ToList();
  566. }
  567. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type)
  568. {
  569. if (media == null)
  570. {
  571. throw new ArgumentNullException("media");
  572. }
  573. var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id);
  574. var locationType = media.LocationType;
  575. var info = new MediaSourceInfo
  576. {
  577. Id = media.Id.ToString("N"),
  578. IsoType = media.IsoType,
  579. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  580. MediaStreams = mediaStreams,
  581. Name = GetMediaSourceName(media, mediaStreams),
  582. Path = enablePathSubstitution ? GetMappedPath(media, media.Path, locationType) : media.Path,
  583. RunTimeTicks = media.RunTimeTicks,
  584. Video3DFormat = media.Video3DFormat,
  585. VideoType = media.VideoType,
  586. Container = media.Container,
  587. Size = media.Size,
  588. Timestamp = media.Timestamp,
  589. Type = type,
  590. SupportsDirectStream = media.VideoType == VideoType.VideoFile,
  591. IsRemote = media.IsShortcut
  592. };
  593. if (info.Protocol == MediaProtocol.File)
  594. {
  595. info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
  596. }
  597. if (media.IsShortcut)
  598. {
  599. info.Path = media.ShortcutPath;
  600. if (!string.IsNullOrWhiteSpace(info.Path))
  601. {
  602. if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
  603. {
  604. info.Protocol = MediaProtocol.Http;
  605. info.SupportsDirectStream = false;
  606. }
  607. else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
  608. {
  609. info.Protocol = MediaProtocol.Rtmp;
  610. info.SupportsDirectStream = false;
  611. }
  612. else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
  613. {
  614. info.Protocol = MediaProtocol.Rtsp;
  615. info.SupportsDirectStream = false;
  616. }
  617. else
  618. {
  619. info.Protocol = MediaProtocol.File;
  620. }
  621. }
  622. }
  623. if (string.IsNullOrEmpty(info.Container))
  624. {
  625. if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso)
  626. {
  627. if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  628. {
  629. info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.');
  630. }
  631. }
  632. }
  633. info.Bitrate = media.TotalBitrate;
  634. info.InferTotalBitrate();
  635. return info;
  636. }
  637. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  638. {
  639. var terms = new List<string>();
  640. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  641. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  642. if (video.Video3DFormat.HasValue)
  643. {
  644. terms.Add("3D");
  645. }
  646. if (video.VideoType == VideoType.BluRay)
  647. {
  648. terms.Add("Bluray");
  649. }
  650. else if (video.VideoType == VideoType.Dvd)
  651. {
  652. terms.Add("DVD");
  653. }
  654. else if (video.VideoType == VideoType.Iso)
  655. {
  656. if (video.IsoType.HasValue)
  657. {
  658. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  659. {
  660. terms.Add("Bluray");
  661. }
  662. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  663. {
  664. terms.Add("DVD");
  665. }
  666. }
  667. else
  668. {
  669. terms.Add("ISO");
  670. }
  671. }
  672. if (videoStream != null)
  673. {
  674. if (videoStream.Width.HasValue)
  675. {
  676. if (videoStream.Width.Value >= 3800)
  677. {
  678. terms.Add("4K");
  679. }
  680. else if (videoStream.Width.Value >= 1900)
  681. {
  682. terms.Add("1080P");
  683. }
  684. else if (videoStream.Width.Value >= 1270)
  685. {
  686. terms.Add("720P");
  687. }
  688. else if (videoStream.Width.Value >= 700)
  689. {
  690. terms.Add("480P");
  691. }
  692. else
  693. {
  694. terms.Add("SD");
  695. }
  696. }
  697. }
  698. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  699. {
  700. terms.Add(videoStream.Codec.ToUpper());
  701. }
  702. if (audioStream != null)
  703. {
  704. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  705. ? audioStream.Profile
  706. : audioStream.Codec;
  707. if (!string.IsNullOrEmpty(audioCodec))
  708. {
  709. terms.Add(audioCodec.ToUpper());
  710. }
  711. }
  712. return string.Join("/", terms.ToArray(terms.Count));
  713. }
  714. }
  715. }