Video.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using MediaBrowser.Model.Entities;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Runtime.Serialization;
  6. namespace MediaBrowser.Controller.Entities
  7. {
  8. /// <summary>
  9. /// Class Video
  10. /// </summary>
  11. public class Video : BaseItem, IHasMediaStreams
  12. {
  13. public Video()
  14. {
  15. MediaStreams = new List<MediaStream>();
  16. Chapters = new List<ChapterInfo>();
  17. PlayableStreamFileNames = new List<string>();
  18. }
  19. /// <summary>
  20. /// Gets or sets the type of the video.
  21. /// </summary>
  22. /// <value>The type of the video.</value>
  23. public VideoType VideoType { get; set; }
  24. /// <summary>
  25. /// Gets or sets the type of the iso.
  26. /// </summary>
  27. /// <value>The type of the iso.</value>
  28. public IsoType? IsoType { get; set; }
  29. /// <summary>
  30. /// Gets or sets the format of the video.
  31. /// </summary>
  32. /// <value>The format of the video.</value>
  33. public VideoFormat VideoFormat { get; set; }
  34. /// <summary>
  35. /// Gets or sets the media streams.
  36. /// </summary>
  37. /// <value>The media streams.</value>
  38. public List<MediaStream> MediaStreams { get; set; }
  39. /// <summary>
  40. /// Gets or sets the chapters.
  41. /// </summary>
  42. /// <value>The chapters.</value>
  43. public List<ChapterInfo> Chapters { get; set; }
  44. /// <summary>
  45. /// If the video is a folder-rip, this will hold the file list for the largest playlist
  46. /// </summary>
  47. public List<string> PlayableStreamFileNames { get; set; }
  48. /// <summary>
  49. /// Gets the playable stream files.
  50. /// </summary>
  51. /// <returns>List{System.String}.</returns>
  52. public List<string> GetPlayableStreamFiles()
  53. {
  54. return GetPlayableStreamFiles(Path);
  55. }
  56. /// <summary>
  57. /// Gets the playable stream files.
  58. /// </summary>
  59. /// <param name="rootPath">The root path.</param>
  60. /// <returns>List{System.String}.</returns>
  61. public List<string> GetPlayableStreamFiles(string rootPath)
  62. {
  63. if (PlayableStreamFileNames == null)
  64. {
  65. return null;
  66. }
  67. var allFiles = Directory.EnumerateFiles(rootPath, "*", SearchOption.AllDirectories).ToList();
  68. return PlayableStreamFileNames.Select(name => allFiles.FirstOrDefault(f => string.Equals(System.IO.Path.GetFileName(f), name, System.StringComparison.OrdinalIgnoreCase)))
  69. .Where(f => !string.IsNullOrEmpty(f))
  70. .ToList();
  71. }
  72. /// <summary>
  73. /// The default video stream for this video. Use this to determine media info for this item.
  74. /// </summary>
  75. /// <value>The default video stream.</value>
  76. [IgnoreDataMember]
  77. public MediaStream DefaultVideoStream
  78. {
  79. get { return MediaStreams != null ? MediaStreams.FirstOrDefault(s => s.Type == MediaStreamType.Video) : null; }
  80. }
  81. /// <summary>
  82. /// Gets a value indicating whether [is3 D].
  83. /// </summary>
  84. /// <value><c>true</c> if [is3 D]; otherwise, <c>false</c>.</value>
  85. [IgnoreDataMember]
  86. public bool Is3D
  87. {
  88. get { return VideoFormat > 0; }
  89. }
  90. /// <summary>
  91. /// Gets the type of the media.
  92. /// </summary>
  93. /// <value>The type of the media.</value>
  94. public override string MediaType
  95. {
  96. get
  97. {
  98. return Model.Entities.MediaType.Video;
  99. }
  100. }
  101. }
  102. }