mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-08 20:38:24 +02:00
105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using MediaBrowser.Controller.Devices;
|
|
using MediaBrowser.Controller.Sync;
|
|
using MediaBrowser.Model.Devices;
|
|
using MediaBrowser.Model.Dlna;
|
|
using MediaBrowser.Model.Sync;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace MediaBrowser.Server.Implementations.Sync
|
|
{
|
|
public class AppSyncProvider : ISyncProvider, IHasUniqueTargetIds, IHasSyncQuality
|
|
{
|
|
private readonly IDeviceManager _deviceManager;
|
|
|
|
public AppSyncProvider(IDeviceManager deviceManager)
|
|
{
|
|
_deviceManager = deviceManager;
|
|
}
|
|
|
|
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
|
|
});
|
|
}
|
|
|
|
public DeviceProfile GetDeviceProfile(SyncTarget target, string quality)
|
|
{
|
|
var caps = _deviceManager.GetCapabilities(target.Id);
|
|
|
|
var profile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
|
|
var maxBitrate = profile.MaxStaticBitrate;
|
|
|
|
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);
|
|
}
|
|
|
|
profile.MaxStaticBitrate = maxBitrate;
|
|
}
|
|
|
|
return profile;
|
|
}
|
|
|
|
public string Name
|
|
{
|
|
get { return "App Sync"; }
|
|
}
|
|
|
|
public IEnumerable<SyncTarget> GetAllSyncTargets()
|
|
{
|
|
return _deviceManager.GetDevices(new DeviceQuery
|
|
{
|
|
SupportsSync = true
|
|
|
|
}).Items.Select(i => new SyncTarget
|
|
{
|
|
Id = i.Id,
|
|
Name = i.Name
|
|
});
|
|
}
|
|
|
|
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()
|
|
}
|
|
};
|
|
}
|
|
}
|
|
}
|