aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations/Sync/AppSyncProvider.cs
blob: 99d7582333f780e210ea58d9e6837db98d87ec6b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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 profile, string quality)
        {
            var caps = _deviceManager.GetCapabilities(target.Id);

            var deviceProfile = caps == null || caps.DeviceProfile == null ? new DeviceProfile() : caps.DeviceProfile;
            deviceProfile.MaxStaticBitrate = SyncHelper.AdjustBitrate(deviceProfile.MaxStaticBitrate, quality);

            return deviceProfile;
        }

        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 = "Original",
                    Id = "original",
                    Description = "Syncs original files as-is, regardless of whether the device is capable of playing them or not."
                },
                new SyncQualityOption
                {
                    Name = "High",
                    Id = "high",
                    IsDefault = true
                },
                new SyncQualityOption
                {
                    Name = "Medium",
                    Id = "medium"
                },
                new SyncQualityOption
                {
                    Name = "Low",
                    Id = "low"
                }
            };
        }

        public IEnumerable<SyncProfileOption> GetProfileOptions(SyncTarget target)
        {
            return new List<SyncProfileOption>();
        }

        public SyncJobOptions GetSyncJobOptions(SyncTarget target, string profile, string quality)
        {
            var isConverting = !string.Equals(quality, "original", StringComparison.OrdinalIgnoreCase);

            return new SyncJobOptions
            {
                DeviceProfile = GetDeviceProfile(target, profile, quality),
                IsConverting = isConverting
            };
        }
    }
}