VideoHandler.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Net;
  7. using System.Threading.Tasks;
  8. using MediaBrowser.Common.Logging;
  9. using MediaBrowser.Common.Net;
  10. using MediaBrowser.Common.Net.Handlers;
  11. using MediaBrowser.Controller;
  12. using MediaBrowser.Model.Entities;
  13. namespace MediaBrowser.Api.HttpHandlers
  14. {
  15. class VideoHandler : BaseMediaHandler<Video>
  16. {
  17. public IEnumerable<string> VideoFormats
  18. {
  19. get
  20. {
  21. return QueryString["videoformats"].Split(',');
  22. }
  23. }
  24. /// <summary>
  25. /// Gets the format we'll be converting to
  26. /// </summary>
  27. protected override string GetOutputFormat()
  28. {
  29. return VideoFormats.First();
  30. }
  31. protected override bool RequiresConversion()
  32. {
  33. // If it's not in a format the consumer accepts, return true
  34. if (!VideoFormats.Any(f => LibraryItem.Path.EndsWith(f, StringComparison.OrdinalIgnoreCase)))
  35. {
  36. return true;
  37. }
  38. AudioStream audio = LibraryItem.AudioStreams.FirstOrDefault();
  39. if (audio != null)
  40. {
  41. // If the number of channels is greater than our desired channels, we need to transcode
  42. if (AudioChannels.HasValue && AudioChannels.Value < audio.Channels)
  43. {
  44. return true;
  45. }
  46. }
  47. // Yay
  48. return false;
  49. }
  50. protected override Task WriteResponseToOutputStream(Stream stream)
  51. {
  52. throw new NotImplementedException();
  53. }
  54. }
  55. }