PlaylistItem.cs 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. using MediaBrowser.Controller.Dlna;
  2. using MediaBrowser.Controller.Entities;
  3. using MediaBrowser.Model.Entities;
  4. using System;
  5. using System.IO;
  6. using System.Linq;
  7. namespace MediaBrowser.Dlna.PlayTo
  8. {
  9. public class PlaylistItem
  10. {
  11. public string ItemId { get; set; }
  12. public bool Transcode { get; set; }
  13. public bool IsVideo { get; set; }
  14. public bool IsAudio { get; set; }
  15. public string FileFormat { get; set; }
  16. public string MimeType { get; set; }
  17. public int PlayState { get; set; }
  18. public string StreamUrl { get; set; }
  19. public string DlnaHeaders { get; set; }
  20. public string Didl { get; set; }
  21. public long StartPositionTicks { get; set; }
  22. public static PlaylistItem Create(BaseItem item, DlnaProfile profile)
  23. {
  24. var playlistItem = new PlaylistItem
  25. {
  26. ItemId = item.Id.ToString()
  27. };
  28. DlnaProfileType profileType;
  29. if (string.Equals(item.MediaType, MediaType.Video, StringComparison.OrdinalIgnoreCase))
  30. {
  31. playlistItem.IsVideo = true;
  32. profileType = DlnaProfileType.Video;
  33. }
  34. else
  35. {
  36. playlistItem.IsAudio = true;
  37. profileType = DlnaProfileType.Audio;
  38. }
  39. var path = item.Path;
  40. var directPlay = profile.DirectPlayProfiles.FirstOrDefault(i => i.Type == profileType && IsSupported(i, path));
  41. if (directPlay != null)
  42. {
  43. playlistItem.Transcode = false;
  44. playlistItem.FileFormat = Path.GetExtension(path);
  45. playlistItem.MimeType = directPlay.MimeType;
  46. return playlistItem;
  47. }
  48. var transcodingProfile = profile.TranscodingProfiles.FirstOrDefault(i => i.Type == profileType && IsSupported(profile, i, path));
  49. if (transcodingProfile != null)
  50. {
  51. playlistItem.Transcode = true;
  52. //Just to make sure we have a "." for the url, remove it in case a user adds it or not
  53. playlistItem.FileFormat = "." + transcodingProfile.Container.TrimStart('.');
  54. playlistItem.MimeType = transcodingProfile.MimeType;
  55. }
  56. return playlistItem;
  57. }
  58. private static bool IsSupported(DirectPlayProfile profile, string path)
  59. {
  60. var mediaContainer = Path.GetExtension(path);
  61. if (!profile.Containers.Any(i => string.Equals("." + i.TrimStart('.'), mediaContainer, StringComparison.OrdinalIgnoreCase)))
  62. {
  63. return false;
  64. }
  65. // Placeholder for future conditions
  66. // TODO: Support codec list as additional restriction
  67. return true;
  68. }
  69. private static bool IsSupported(DlnaProfile profile, TranscodingProfile transcodingProfile, string path)
  70. {
  71. // Placeholder for future conditions
  72. return true;
  73. }
  74. }
  75. }