Video.cs 26 KB

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