Video.cs 26 KB

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