Video.cs 26 KB

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