Video.cs 26 KB

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