Video.cs 26 KB

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