AppSyncProvider.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. using MediaBrowser.Controller.Devices;
  2. using MediaBrowser.Controller.Sync;
  3. using MediaBrowser.Model.Devices;
  4. using MediaBrowser.Model.Dlna;
  5. using MediaBrowser.Model.Sync;
  6. using System;
  7. using System.Collections.Generic;
  8. using System.Linq;
  9. namespace MediaBrowser.Server.Implementations.Sync
  10. {
  11. public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncQuality
  12. {
  13. private readonly IDeviceManager _deviceManager;
  14. public AppSyncProvider(IDeviceManager deviceManager)
  15. {
  16. _deviceManager = deviceManager;
  17. }
  18. public IEnumerable<SyncTarget> GetSyncTargets(string userId)
  19. {
  20. return _deviceManager.GetDevices(new DeviceQuery
  21. {
  22. SupportsSync = true,
  23. UserId = userId
  24. }).Items.Select(i => new SyncTarget
  25. {
  26. Id = i.Id,
  27. Name = i.Name
  28. });
  29. }
  30. public DeviceProfile GetDeviceProfile(SyncTarget target, string profile, string quality)
  31. {
  32. var caps = _deviceManager.GetCapabilities(target.Id);
  33. var deviceProfile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
  34. var maxBitrate = deviceProfile.MaxStaticBitrate;
  35. if (maxBitrate.HasValue)
  36. {
  37. if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase))
  38. {
  39. maxBitrate = Convert.ToInt32(maxBitrate.Value * .75);
  40. }
  41. else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase))
  42. {
  43. maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
  44. }
  45. deviceProfile.MaxStaticBitrate = maxBitrate;
  46. }
  47. return deviceProfile;
  48. }
  49. public string Name
  50. {
  51. get { return "App Sync"; }
  52. }
  53. public IEnumerable<SyncTarget> GetAllSyncTargets()
  54. {
  55. return _deviceManager.GetDevices(new DeviceQuery
  56. {
  57. SupportsSync = true
  58. }).Items.Select(i => new SyncTarget
  59. {
  60. Id = i.Id,
  61. Name = i.Name
  62. });
  63. }
  64. public IEnumerable<SyncQualityOption> GetQualityOptions(SyncTarget target)
  65. {
  66. return new List<SyncQualityOption>
  67. {
  68. new SyncQualityOption
  69. {
  70. Name = "Original",
  71. Id = "original",
  72. Description = "Syncs original files as-is, regardless of whether the device is capable of playing them or not."
  73. },
  74. new SyncQualityOption
  75. {
  76. Name = "High",
  77. Id = "high",
  78. IsDefault = true
  79. },
  80. new SyncQualityOption
  81. {
  82. Name = "Medium",
  83. Id = "medium"
  84. },
  85. new SyncQualityOption
  86. {
  87. Name = "Low",
  88. Id = "low"
  89. }
  90. };
  91. }
  92. public IEnumerable<SyncProfileOption> GetProfileOptions(SyncTarget target)
  93. {
  94. return new List<SyncProfileOption>();
  95. }
  96. }
  97. }