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
|
|
|
|
|
{
|
|
|
|
|
Name = SyncQuality.Original.ToString(),
|
|
|
|
|
Id = SyncQuality.Original.ToString()
|
|
|
|
|
},
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
|
|
|
|
Name = SyncQuality.High.ToString(),
|
|
|
|
|
Id = SyncQuality.High.ToString(),
|
|
|
|
|
IsDefault = true
|
|
|
|
|
},
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
|
|
|
|
Name = SyncQuality.Medium.ToString(),
|
|
|
|
|
Id = SyncQuality.Medium.ToString()
|
|
|
|
|
},
|
|
|
|
|
new SyncQualityOption
|
|
|
|
|
{
|
|
|
|
|
Name = SyncQuality.Low.ToString(),
|
|
|
|
|
Id = SyncQuality.Low.ToString()
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2015-03-14 18:42:09 -07:00
|
|
|
|
|
|
|
|
|
public IEnumerable<SyncQualityOption> GetProfileOptions(SyncTarget target)
|
|
|
|
|
{
|
|
|
|
|
return new List<SyncQualityOption>();
|
|
|
|
|
}
|
2014-07-21 18:29:06 -07:00
|
|
|
|
}
|
|
|
|
|
}
|