Video.cs 27 KB

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