AppSyncProvider.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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, IHasDuplicateCheck
  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. deviceProfile.MaxStaticBitrate = SyncHelper.AdjustBitrate(deviceProfile.MaxStaticBitrate, quality);
  35. return deviceProfile;
  36. }
  37. public string Name
  38. {
  39. get { return "Mobile Sync"; }
  40. }
  41. public IEnumerable<SyncTarget> GetAllSyncTargets()
  42. {
  43. return _deviceManager.GetDevices(new DeviceQuery
  44. {
  45. SupportsSync = true
  46. }).Items.Select(i => new SyncTarget
  47. {
  48. Id = i.Id,
  49. Name = i.Name
  50. });
  51. }
  52. public IEnumerable<SyncQualityOption> GetQualityOptions(SyncTarget target)
  53. {
  54. return new List<SyncQualityOption>
  55. {
  56. new SyncQualityOption
  57. {
  58. Name = "Original",
  59. Id = "original",
  60. Description = "Syncs original files as-is, regardless of whether the device is capable of playing them or not."
  61. },
  62. new SyncQualityOption
  63. {
  64. Name = "High",
  65. Id = "high",
  66. IsDefault = true
  67. },
  68. new SyncQualityOption
  69. {
  70. Name = "Medium",
  71. Id = "medium"
  72. },
  73. new SyncQualityOption
  74. {
  75. Name = "Low",
  76. Id = "low"
  77. },
  78. new SyncQualityOption
  79. {
  80. Name = "Custom",
  81. Id = "custom"
  82. }
  83. };
  84. }
  85. public IEnumerable<SyncProfileOption> GetProfileOptions(SyncTarget target)
  86. {
  87. return new List<SyncProfileOption>();
  88. }
  89. public SyncJobOptions GetSyncJobOptions(SyncTarget target, string profile, string quality)
  90. {
  91. var isConverting = !string.Equals(quality, "original", StringComparison.OrdinalIgnoreCase);
  92. return new SyncJobOptions
  93. {
  94. DeviceProfile = GetDeviceProfile(target, profile, quality),
  95. IsConverting = isConverting
  96. };
  97. }
  98. public bool AllowDuplicateJobItem(SyncJobItem original, SyncJobItem duplicate)
  99. {
  100. return false;
  101. }
  102. }
  103. }