Video.cs 25 KB

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