2014-12-14 22:49:04 -07:00
|
|
|
|
using MediaBrowser.Controller.Devices;
|
|
|
|
|
using MediaBrowser.Controller.Sync;
|
|
|
|
|
using MediaBrowser.Model.Devices;
|
2014-07-21 18:29:06 -07:00
|
|
|
|
using MediaBrowser.Model.Dlna;
|
|
|
|
|
using MediaBrowser.Model.Sync;
|
2015-03-11 21:55:06 -07:00
|
|
|
|
using System;
|
2014-07-21 18:29:06 -07:00
|
|
|
|
using System.Collections.Generic;
|
2014-12-14 22:49:04 -07:00
|
|
|
|
using System.Linq;
|
2014-07-21 18:29:06 -07:00
|
|
|
|
|
|
|
|
|
namespace MediaBrowser.Server.Implementations.Sync
|
|
|
|
|
{
|
2015-03-11 21:47:16 -07:00
|
|
|
|
public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncQuality
|
2014-07-21 18:29:06 -07:00
|
|
|
|
{
|
2014-12-14 22:49:04 -07:00
|
|
|
|
private readonly IDeviceManager _deviceManager;
|
|
|
|
|
|
|
|
|
|
public AppSyncProvider(IDeviceManager deviceManager)
|
|
|
|
|
{
|
|
|
|
|
_deviceManager = deviceManager;
|
|
|
|
|
}
|
|
|
|
|
|
2014-12-30 23:24:49 -07:00
|
|
|
|
public IEnumerable<SyncTarget> GetSyncTargets(string userId)
|
|
|
|
|
{
|
|
|
|
|
return _deviceManager.GetDevices(new DeviceQuery
|
|
|
|
|
{
|
|
|
|
|
SupportsSync = true,
|
|
|
|
|
UserId = userId
|
|
|
|
|
|
|
|
|
|
}).Items.Select(i => new SyncTarget
|
|
|
|
|
{
|
|
|
|
|
Id = i.Id,
|
|
|
|
|
Name = i.Name
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 18:42:09 -07:00
|
|
|
|
public DeviceProfile GetDeviceProfile(SyncTarget target, string profile, string quality)
|
2014-07-21 18:29:06 -07:00
|
|
|
|
{
|
2015-01-01 22:36:27 -07:00
|
|
|
|
var caps = _deviceManager.GetCapabilities(target.Id);
|
|
|
|
|
|
2015-03-14 18:42:09 -07:00
|
|
|
|
var deviceProfile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
|
|
|
|
|
var maxBitrate = deviceProfile.MaxStaticBitrate;
|
2015-03-11 21:55:06 -07:00
|
|
|
|
|
|
|
|
|
if (maxBitrate.HasValue)
|
|
|
|
|
{
|
|
|
|
|
if (string.Equals(quality, "medium", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
maxBitrate = Convert.ToInt32(maxBitrate.Value * .75);
|
|
|
|
|
}
|
|
|
|
|
else if (string.Equals(quality, "low", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
maxBitrate = Convert.ToInt32(maxBitrate.Value * .5);
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 18:42:09 -07:00
|
|
|
|
deviceProfile.MaxStaticBitrate = maxBitrate;
|
2015-03-11 21:55:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 18:42:09 -07:00
|
|
|
|
return deviceProfile;
|
2014-07-21 18:29:06 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get { return "App Sync"; }
|
|
|
|
|
}
|
2015-02-28 07:35:12 -07:00
|
|
|
|
|
|
|
|
|
public IEnumerable<SyncTarget> GetAllSyncTargets()
|
|
|
|
|
{
|
|
|
|
|
return _deviceManager.GetDevices(new DeviceQuery
|
|
|
|
|
{
|
|
|
|
|
SupportsSync = true
|
|
|
|
|
|
|
|
|
|
}).Items.Select(i => new SyncTarget
|
|
|
|
|
{
|
|
|
|
|
Id = i.Id,
|
|
|
|
|
Name = i.Name
|
|
|
|
|
});
|
|
|
|
|
}
|
2015-03-11 21:47:16 -07:00
|
|
|
|
|
|
|
|
|
public IEnumerable<SyncQualityOption> GetQualityOptions(SyncTarget target)
|
|
|
|
|
{
|
|
|
|
|
return new List<SyncQualityOption>
|
|
|
|
|
{
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
2015-03-14 21:17:35 -07:00
|
|
|
|
Name = "Original",
|
|
|
|
|
Id = "original",
|
|
|
|
|
Description = "Syncs original files as-is, regardless of whether the device is capable of playing them or not."
|
2015-03-11 21:47:16 -07:00
|
|
|
|
},
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
2015-03-14 21:17:35 -07:00
|
|
|
|
Name = "High",
|
|
|
|
|
Id = "high",
|
2015-03-11 21:47:16 -07:00
|
|
|
|
IsDefault = true
|
|
|
|
|
},
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
2015-03-14 21:17:35 -07:00
|
|
|
|
Name = "Medium",
|
|
|
|
|
Id = "medium"
|
2015-03-11 21:47:16 -07:00
|
|
|
|
},
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
2015-03-14 21:17:35 -07:00
|
|
|
|
Name = "Low",
|
|
|
|
|
Id = "low"
|
2015-03-11 21:47:16 -07:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-03-14 18:42:09 -07:00
|
|
|
|
|
2015-03-14 21:17:35 -07:00
|
|
|
|
public IEnumerable<SyncProfileOption> GetProfileOptions(SyncTarget target)
|
2015-03-14 18:42:09 -07:00
|
|
|
|
{
|
2015-03-14 21:17:35 -07:00
|
|
|
|
return new List<SyncProfileOption>();
|
2015-03-14 18:42:09 -07:00
|
|
|
|
}
|
2014-07-21 18:29:06 -07:00
|
|
|
|
}
|
|
|
|
|
}
|