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. 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.HdDvd || VideoType == VideoType.Dvd ||
  164. 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.Count + LocalAlternateVersions.Count + 1;
  191. }
  192. }
  193. [IgnoreDataMember]
  194. public bool IsStacked
  195. {
  196. get { return AdditionalParts.Count > 0; }
  197. }
  198. [IgnoreDataMember]
  199. public bool HasLocalAlternateVersions
  200. {
  201. get { return LocalAlternateVersions.Count > 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. VideoType == VideoType.HdDvd)
  296. {
  297. return Path;
  298. }
  299. }
  300. return base.ContainingFolderPath;
  301. }
  302. }
  303. [IgnoreDataMember]
  304. public override string FileNameWithoutExtension
  305. {
  306. get
  307. {
  308. if (LocationType == LocationType.FileSystem)
  309. {
  310. if (VideoType == VideoType.BluRay || VideoType == VideoType.Dvd || VideoType == VideoType.HdDvd)
  311. {
  312. return System.IO.Path.GetFileName(Path);
  313. }
  314. return System.IO.Path.GetFileNameWithoutExtension(Path);
  315. }
  316. return null;
  317. }
  318. }
  319. internal override bool IsValidFromResolver(BaseItem newItem)
  320. {
  321. var current = this;
  322. var newAsVideo = newItem as Video;
  323. if (newAsVideo != null)
  324. {
  325. if (!current.AdditionalParts.SequenceEqual(newAsVideo.AdditionalParts, StringComparer.OrdinalIgnoreCase))
  326. {
  327. return false;
  328. }
  329. if (!current.LocalAlternateVersions.SequenceEqual(newAsVideo.LocalAlternateVersions, StringComparer.OrdinalIgnoreCase))
  330. {
  331. return false;
  332. }
  333. if (newAsVideo.VideoType != VideoType)
  334. {
  335. return false;
  336. }
  337. }
  338. return base.IsValidFromResolver(newItem);
  339. }
  340. /// <summary>
  341. /// Gets the playable stream files.
  342. /// </summary>
  343. /// <param name="rootPath">The root path.</param>
  344. /// <returns>List{System.String}.</returns>
  345. public List<string> GetPlayableStreamFiles(string rootPath)
  346. {
  347. var allFiles = FileSystem.GetFilePaths(rootPath, true).ToList();
  348. var videoType = VideoType;
  349. if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.BluRay)
  350. {
  351. videoType = VideoType.BluRay;
  352. }
  353. else if (videoType == VideoType.Iso && IsoType == Model.Entities.IsoType.Dvd)
  354. {
  355. videoType = VideoType.Dvd;
  356. }
  357. return QueryPlayableStreamFiles(rootPath, videoType).Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, StringComparison.OrdinalIgnoreCase)))
  358. .Where(f => !string.IsNullOrEmpty(f))
  359. .ToList();
  360. }
  361. public static List<string> QueryPlayableStreamFiles(string rootPath, VideoType videoType)
  362. {
  363. if (videoType == VideoType.Dvd)
  364. {
  365. return FileSystem.GetFiles(rootPath, new[] { ".vob" }, false, true)
  366. .OrderByDescending(i => i.Length)
  367. .ThenBy(i => i.FullName)
  368. .Take(1)
  369. .Select(i => i.FullName)
  370. .ToList();
  371. }
  372. if (videoType == VideoType.BluRay)
  373. {
  374. return FileSystem.GetFiles(rootPath, new[] { ".m2ts" }, false, true)
  375. .OrderByDescending(i => i.Length)
  376. .ThenBy(i => i.FullName)
  377. .Take(1)
  378. .Select(i => i.FullName)
  379. .ToList();
  380. }
  381. return new List<string>();
  382. }
  383. /// <summary>
  384. /// Gets a value indicating whether [is3 D].
  385. /// </summary>
  386. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  387. [IgnoreDataMember]
  388. public bool Is3D
  389. {
  390. get { return Video3DFormat.HasValue; }
  391. }
  392. /// <summary>
  393. /// Gets the type of the media.
  394. /// </summary>
  395. /// <value>The type of the media.</value>
  396. [IgnoreDataMember]
  397. public override string MediaType
  398. {
  399. get
  400. {
  401. return Model.Entities.MediaType.Video;
  402. }
  403. }
  404. protected override async Task<bool> RefreshedOwnedItems(MetadataRefreshOptions options, List<FileSystemMetadata> fileSystemChildren, CancellationToken cancellationToken)
  405. {
  406. var hasChanges = await base.RefreshedOwnedItems(options, fileSystemChildren, cancellationToken).ConfigureAwait(false);
  407. if (IsStacked)
  408. {
  409. var tasks = AdditionalParts
  410. .Select(i => RefreshMetadataForOwnedVideo(options, true, i, cancellationToken));
  411. await Task.WhenAll(tasks).ConfigureAwait(false);
  412. }
  413. // Must have a parent to have additional parts or alternate versions
  414. // In other words, it must be part of the Parent/Child tree
  415. // The additional parts won't have additional parts themselves
  416. if (LocationType == LocationType.FileSystem && GetParent() != null)
  417. {
  418. if (!IsStacked)
  419. {
  420. RefreshLinkedAlternateVersions();
  421. var tasks = LocalAlternateVersions
  422. .Select(i => RefreshMetadataForOwnedVideo(options, false, i, cancellationToken));
  423. await Task.WhenAll(tasks).ConfigureAwait(false);
  424. }
  425. }
  426. return hasChanges;
  427. }
  428. private void RefreshLinkedAlternateVersions()
  429. {
  430. foreach (var child in LinkedAlternateVersions)
  431. {
  432. // Reset the cached value
  433. if (child.ItemId.HasValue && child.ItemId.Value == Guid.Empty)
  434. {
  435. child.ItemId = null;
  436. }
  437. }
  438. }
  439. public override async Task UpdateToRepository(ItemUpdateType updateReason, CancellationToken cancellationToken)
  440. {
  441. await base.UpdateToRepository(updateReason, cancellationToken).ConfigureAwait(false);
  442. var localAlternates = GetLocalAlternateVersionIds()
  443. .Select(i => LibraryManager.GetItemById(i))
  444. .Where(i => i != null);
  445. foreach (var item in localAlternates)
  446. {
  447. item.ImageInfos = ImageInfos;
  448. item.Overview = Overview;
  449. item.ProductionYear = ProductionYear;
  450. item.PremiereDate = PremiereDate;
  451. item.CommunityRating = CommunityRating;
  452. item.OfficialRating = OfficialRating;
  453. item.Genres = Genres;
  454. item.ProviderIds = ProviderIds;
  455. await item.UpdateToRepository(ItemUpdateType.MetadataDownload, cancellationToken).ConfigureAwait(false);
  456. }
  457. }
  458. public override IEnumerable<FileSystemMetadata> GetDeletePaths()
  459. {
  460. if (!IsInMixedFolder)
  461. {
  462. return new[] {
  463. new FileSystemMetadata
  464. {
  465. FullName = ContainingFolderPath,
  466. IsDirectory = true
  467. }
  468. };
  469. }
  470. return base.GetDeletePaths();
  471. }
  472. public List<MediaStream> GetMediaStreams()
  473. {
  474. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  475. {
  476. ItemId = Id
  477. });
  478. }
  479. public virtual MediaStream GetDefaultVideoStream()
  480. {
  481. if (!DefaultVideoStreamIndex.HasValue)
  482. {
  483. return null;
  484. }
  485. return MediaSourceManager.GetMediaStreams(new MediaStreamQuery
  486. {
  487. ItemId = Id,
  488. Index = DefaultVideoStreamIndex.Value
  489. }).FirstOrDefault();
  490. }
  491. private List<Tuple<Video, MediaSourceType>> GetAllVideosForMediaSources()
  492. {
  493. var list = new List<Tuple<Video, MediaSourceType>>();
  494. list.Add(new Tuple<Video, MediaSourceType>(this, MediaSourceType.Default));
  495. list.AddRange(GetLinkedAlternateVersions().Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  496. if (!string.IsNullOrWhiteSpace(PrimaryVersionId))
  497. {
  498. var primary = LibraryManager.GetItemById(PrimaryVersionId) as Video;
  499. if (primary != null)
  500. {
  501. var existingIds = list.Select(i => i.Item1.Id).ToList();
  502. list.Add(new Tuple<Video, MediaSourceType>(primary, MediaSourceType.Grouping));
  503. list.AddRange(primary.GetLinkedAlternateVersions().Where(i => !existingIds.Contains(i.Id)).Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Grouping)));
  504. }
  505. }
  506. var localAlternates = list
  507. .SelectMany(i => i.Item1.GetLocalAlternateVersionIds())
  508. .Select(LibraryManager.GetItemById)
  509. .Where(i => i != null)
  510. .OfType<Video>()
  511. .ToList();
  512. list.AddRange(localAlternates.Select(i => new Tuple<Video, MediaSourceType>(i, MediaSourceType.Default)));
  513. return list;
  514. }
  515. public virtual List<MediaSourceInfo> GetMediaSources(bool enablePathSubstitution)
  516. {
  517. if (SourceType == SourceType.Channel)
  518. {
  519. var sources = ChannelManager.GetStaticMediaSources(this, CancellationToken.None)
  520. .ToList();
  521. if (sources.Count > 0)
  522. {
  523. return sources;
  524. }
  525. return new List<MediaSourceInfo>
  526. {
  527. GetVersionInfo(enablePathSubstitution, this, MediaSourceType.Placeholder)
  528. };
  529. }
  530. var list = GetAllVideosForMediaSources();
  531. var result = list.Select(i => GetVersionInfo(enablePathSubstitution, i.Item1, i.Item2)).ToList();
  532. return result.OrderBy(i =>
  533. {
  534. if (i.VideoType == VideoType.VideoFile)
  535. {
  536. return 0;
  537. }
  538. return 1;
  539. }).ThenBy(i => i.Video3DFormat.HasValue ? 1 : 0)
  540. .ThenByDescending(i =>
  541. {
  542. var stream = i.VideoStream;
  543. return stream == null || stream.Width == null ? 0 : stream.Width.Value;
  544. })
  545. .ToList();
  546. }
  547. private static MediaSourceInfo GetVersionInfo(bool enablePathSubstitution, Video media, MediaSourceType type)
  548. {
  549. if (media == null)
  550. {
  551. throw new ArgumentNullException("media");
  552. }
  553. var mediaStreams = MediaSourceManager.GetMediaStreams(media.Id);
  554. var locationType = media.LocationType;
  555. var info = new MediaSourceInfo
  556. {
  557. Id = media.Id.ToString("N"),
  558. IsoType = media.IsoType,
  559. Protocol = locationType == LocationType.Remote ? MediaProtocol.Http : MediaProtocol.File,
  560. MediaStreams = mediaStreams,
  561. Name = GetMediaSourceName(media, mediaStreams),
  562. Path = enablePathSubstitution ? GetMappedPath(media, media.Path, locationType) : media.Path,
  563. RunTimeTicks = media.RunTimeTicks,
  564. Video3DFormat = media.Video3DFormat,
  565. VideoType = media.VideoType,
  566. Container = media.Container,
  567. Size = media.Size,
  568. Timestamp = media.Timestamp,
  569. Type = type,
  570. SupportsDirectStream = media.VideoType == VideoType.VideoFile,
  571. IsRemote = media.IsShortcut
  572. };
  573. if (info.Protocol == MediaProtocol.File)
  574. {
  575. info.ETag = media.DateModified.Ticks.ToString(CultureInfo.InvariantCulture).GetMD5().ToString("N");
  576. }
  577. if (media.IsShortcut)
  578. {
  579. info.Path = media.ShortcutPath;
  580. if (!string.IsNullOrWhiteSpace(info.Path))
  581. {
  582. if (info.Path.StartsWith("Http", StringComparison.OrdinalIgnoreCase))
  583. {
  584. info.Protocol = MediaProtocol.Http;
  585. info.SupportsDirectStream = false;
  586. }
  587. else if (info.Path.StartsWith("Rtmp", StringComparison.OrdinalIgnoreCase))
  588. {
  589. info.Protocol = MediaProtocol.Rtmp;
  590. info.SupportsDirectStream = false;
  591. }
  592. else if (info.Path.StartsWith("Rtsp", StringComparison.OrdinalIgnoreCase))
  593. {
  594. info.Protocol = MediaProtocol.Rtsp;
  595. info.SupportsDirectStream = false;
  596. }
  597. else
  598. {
  599. info.Protocol = MediaProtocol.File;
  600. }
  601. }
  602. }
  603. if (string.IsNullOrEmpty(info.Container))
  604. {
  605. if (media.VideoType == VideoType.VideoFile || media.VideoType == VideoType.Iso)
  606. {
  607. if (!string.IsNullOrWhiteSpace(media.Path) && locationType != LocationType.Remote && locationType != LocationType.Virtual)
  608. {
  609. info.Container = System.IO.Path.GetExtension(media.Path).TrimStart('.');
  610. }
  611. }
  612. }
  613. info.Bitrate = media.TotalBitrate;
  614. info.InferTotalBitrate();
  615. return info;
  616. }
  617. private static string GetMediaSourceName(Video video, List<MediaStream> mediaStreams)
  618. {
  619. var terms = new List<string>();
  620. var videoStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video);
  621. var audioStream = mediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Audio);
  622. if (video.Video3DFormat.HasValue)
  623. {
  624. terms.Add("3D");
  625. }
  626. if (video.VideoType == VideoType.BluRay)
  627. {
  628. terms.Add("Bluray");
  629. }
  630. else if (video.VideoType == VideoType.Dvd)
  631. {
  632. terms.Add("DVD");
  633. }
  634. else if (video.VideoType == VideoType.HdDvd)
  635. {
  636. terms.Add("HD-DVD");
  637. }
  638. else if (video.VideoType == VideoType.Iso)
  639. {
  640. if (video.IsoType.HasValue)
  641. {
  642. if (video.IsoType.Value == Model.Entities.IsoType.BluRay)
  643. {
  644. terms.Add("Bluray");
  645. }
  646. else if (video.IsoType.Value == Model.Entities.IsoType.Dvd)
  647. {
  648. terms.Add("DVD");
  649. }
  650. }
  651. else
  652. {
  653. terms.Add("ISO");
  654. }
  655. }
  656. if (videoStream != null)
  657. {
  658. if (videoStream.Width.HasValue)
  659. {
  660. if (videoStream.Width.Value >= 3800)
  661. {
  662. terms.Add("4K");
  663. }
  664. else if (videoStream.Width.Value >= 1900)
  665. {
  666. terms.Add("1080P");
  667. }
  668. else if (videoStream.Width.Value >= 1270)
  669. {
  670. terms.Add("720P");
  671. }
  672. else if (videoStream.Width.Value >= 700)
  673. {
  674. terms.Add("480P");
  675. }
  676. else
  677. {
  678. terms.Add("SD");
  679. }
  680. }
  681. }
  682. if (videoStream != null && !string.IsNullOrWhiteSpace(videoStream.Codec))
  683. {
  684. terms.Add(videoStream.Codec.ToUpper());
  685. }
  686. if (audioStream != null)
  687. {
  688. var audioCodec = string.Equals(audioStream.Codec, "dca", StringComparison.OrdinalIgnoreCase)
  689. ? audioStream.Profile
  690. : audioStream.Codec;
  691. if (!string.IsNullOrEmpty(audioCodec))
  692. {
  693. terms.Add(audioCodec.ToUpper());
  694. }
  695. }
  696. return string.Join("/", terms.ToArray());
  697. }
  698. }
  699. }