|
@@ -1,37 +1,190 @@
|
|
|
-namespace MediaBrowser.Dlna.Channels
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Linq;
|
|
|
+using System.Threading;
|
|
|
+using System.Threading.Tasks;
|
|
|
+using MediaBrowser.Common.Net;
|
|
|
+using MediaBrowser.Controller.Channels;
|
|
|
+using MediaBrowser.Controller.Configuration;
|
|
|
+using MediaBrowser.Controller.Dlna;
|
|
|
+using MediaBrowser.Controller.Providers;
|
|
|
+using MediaBrowser.Dlna.ContentDirectory;
|
|
|
+using MediaBrowser.Dlna.PlayTo;
|
|
|
+using MediaBrowser.Model.Channels;
|
|
|
+using MediaBrowser.Model.Entities;
|
|
|
+using MediaBrowser.Model.Logging;
|
|
|
+
|
|
|
+namespace MediaBrowser.Dlna.Channels
|
|
|
{
|
|
|
- //public class DlnaChannelFactory : IChannelFactory, IDisposable
|
|
|
+ //public class DlnaChannel : IChannel, IDisposable
|
|
|
//{
|
|
|
- // private readonly IServerConfigurationManager _config;
|
|
|
// private readonly ILogger _logger;
|
|
|
// private readonly IHttpClient _httpClient;
|
|
|
+ // private readonly IServerConfigurationManager _config;
|
|
|
+ // private List<Device> _servers = new List<Device>();
|
|
|
|
|
|
// private readonly IDeviceDiscovery _deviceDiscovery;
|
|
|
-
|
|
|
// private readonly SemaphoreSlim _syncLock = new SemaphoreSlim(1, 1);
|
|
|
- // private List<Device> _servers = new List<Device>();
|
|
|
-
|
|
|
- // public static DlnaChannelFactory Instance;
|
|
|
-
|
|
|
// private Func<List<string>> _localServersLookup;
|
|
|
|
|
|
- // public DlnaChannelFactory(IServerConfigurationManager config, IHttpClient httpClient, ILogger logger, IDeviceDiscovery deviceDiscovery)
|
|
|
+ // public static DlnaChannel Current;
|
|
|
+
|
|
|
+ // public DlnaChannel(ILogger logger, IHttpClient httpClient, IDeviceDiscovery deviceDiscovery, IServerConfigurationManager config)
|
|
|
// {
|
|
|
- // _config = config;
|
|
|
- // _httpClient = httpClient;
|
|
|
// _logger = logger;
|
|
|
+ // _httpClient = httpClient;
|
|
|
// _deviceDiscovery = deviceDiscovery;
|
|
|
- // Instance = this;
|
|
|
+ // _config = config;
|
|
|
+ // Current = this;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public string Name
|
|
|
+ // {
|
|
|
+ // get { return "Devices"; }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public string Description
|
|
|
+ // {
|
|
|
+ // get { return string.Empty; }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public string DataVersion
|
|
|
+ // {
|
|
|
+ // get { return DateTime.UtcNow.Ticks.ToString(); }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public string HomePageUrl
|
|
|
+ // {
|
|
|
+ // get { return string.Empty; }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public ChannelParentalRating ParentalRating
|
|
|
+ // {
|
|
|
+ // get { return ChannelParentalRating.GeneralAudience; }
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public InternalChannelFeatures GetChannelFeatures()
|
|
|
+ // {
|
|
|
+ // return new InternalChannelFeatures
|
|
|
+ // {
|
|
|
+ // ContentTypes = new List<ChannelMediaContentType>
|
|
|
+ // {
|
|
|
+ // ChannelMediaContentType.Song,
|
|
|
+ // ChannelMediaContentType.Clip
|
|
|
+ // },
|
|
|
+
|
|
|
+ // MediaTypes = new List<ChannelMediaType>
|
|
|
+ // {
|
|
|
+ // ChannelMediaType.Audio,
|
|
|
+ // ChannelMediaType.Video,
|
|
|
+ // ChannelMediaType.Photo
|
|
|
+ // }
|
|
|
+ // };
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public bool IsEnabledFor(string userId)
|
|
|
+ // {
|
|
|
+ // return true;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
|
|
|
+ // {
|
|
|
+ // throw new NotImplementedException();
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public IEnumerable<ImageType> GetSupportedChannelImages()
|
|
|
+ // {
|
|
|
+ // return new List<ImageType>
|
|
|
+ // {
|
|
|
+ // ImageType.Primary
|
|
|
+ // };
|
|
|
// }
|
|
|
|
|
|
- // internal void Start(Func<List<string>> localServersLookup)
|
|
|
+ // public void Start(Func<List<string>> localServersLookup)
|
|
|
// {
|
|
|
// _localServersLookup = localServersLookup;
|
|
|
|
|
|
- // //deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered;
|
|
|
+ // _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered;
|
|
|
+ // _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft;
|
|
|
+
|
|
|
+ // _deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered;
|
|
|
// _deviceDiscovery.DeviceLeft += deviceDiscovery_DeviceLeft;
|
|
|
// }
|
|
|
|
|
|
+ // public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
|
|
|
+ // {
|
|
|
+ // if (string.IsNullOrWhiteSpace(query.FolderId))
|
|
|
+ // {
|
|
|
+ // return await GetServers(query, cancellationToken).ConfigureAwait(false);
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return new ChannelItemResult();
|
|
|
+
|
|
|
+ // //var idParts = query.FolderId.Split('|');
|
|
|
+ // //var folderId = idParts.Length == 2 ? idParts[1] : null;
|
|
|
+
|
|
|
+ // //var result = await new ContentDirectoryBrowser(_httpClient, _logger).Browse(new ContentDirectoryBrowseRequest
|
|
|
+ // //{
|
|
|
+ // // Limit = query.Limit,
|
|
|
+ // // StartIndex = query.StartIndex,
|
|
|
+ // // ParentId = folderId,
|
|
|
+ // // ContentDirectoryUrl = ControlUrl
|
|
|
+
|
|
|
+ // //}, cancellationToken).ConfigureAwait(false);
|
|
|
+
|
|
|
+ // //items = result.Items.ToList();
|
|
|
+
|
|
|
+ // //var list = items.ToList();
|
|
|
+ // //var count = list.Count;
|
|
|
+
|
|
|
+ // //list = ApplyPaging(list, query).ToList();
|
|
|
+
|
|
|
+ // //return new ChannelItemResult
|
|
|
+ // //{
|
|
|
+ // // Items = list,
|
|
|
+ // // TotalRecordCount = count
|
|
|
+ // //};
|
|
|
+ // }
|
|
|
+
|
|
|
+ // public async Task<ChannelItemResult> GetServers(InternalChannelItemQuery query, CancellationToken cancellationToken)
|
|
|
+ // {
|
|
|
+ // await _syncLock.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
|
+
|
|
|
+ // try
|
|
|
+ // {
|
|
|
+ // var items = _servers.Select(i =>
|
|
|
+ // {
|
|
|
+ // var service = i.Properties.Services
|
|
|
+ // .FirstOrDefault(s => string.Equals(s.ServiceType, "urn:schemas-upnp-org:service:ContentDirectory:1", StringComparison.OrdinalIgnoreCase));
|
|
|
+
|
|
|
+ // var controlUrl = service == null ? null : (_servers[0].Properties.BaseUrl.TrimEnd('/') + "/" + service.ControlUrl.TrimStart('/'));
|
|
|
+
|
|
|
+ // if (string.IsNullOrWhiteSpace(controlUrl))
|
|
|
+ // {
|
|
|
+ // return null;
|
|
|
+ // }
|
|
|
+
|
|
|
+ // return new ChannelItemInfo
|
|
|
+ // {
|
|
|
+ // Id = i.Properties.UUID,
|
|
|
+ // Name = i.Properties.Name,
|
|
|
+ // Type = ChannelItemType.Folder
|
|
|
+ // };
|
|
|
+
|
|
|
+ // }).Where(i => i != null).ToList();
|
|
|
+
|
|
|
+ // return new ChannelItemResult
|
|
|
+ // {
|
|
|
+ // TotalRecordCount = items.Count,
|
|
|
+ // Items = items
|
|
|
+ // };
|
|
|
+ // }
|
|
|
+ // finally
|
|
|
+ // {
|
|
|
+ // _syncLock.Release();
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+
|
|
|
// async void deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e)
|
|
|
// {
|
|
|
// string usn;
|
|
@@ -57,16 +210,13 @@
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
- // if (GetExistingServers(usn).Any())
|
|
|
- // {
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
// await _syncLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
+ // var serverList = _servers.ToList();
|
|
|
+
|
|
|
// try
|
|
|
// {
|
|
|
- // if (GetExistingServers(usn).Any())
|
|
|
+ // if (GetExistingServers(serverList, usn).Any())
|
|
|
// {
|
|
|
// return;
|
|
|
// }
|
|
@@ -74,9 +224,9 @@
|
|
|
// var device = await Device.CreateuPnpDeviceAsync(new Uri(location), _httpClient, _config, _logger)
|
|
|
// .ConfigureAwait(false);
|
|
|
|
|
|
- // if (!_servers.Any(i => string.Equals(i.Properties.UUID, device.Properties.UUID, StringComparison.OrdinalIgnoreCase)))
|
|
|
+ // if (!serverList.Any(i => string.Equals(i.Properties.UUID, device.Properties.UUID, StringComparison.OrdinalIgnoreCase)))
|
|
|
// {
|
|
|
- // _servers.Add(device);
|
|
|
+ // serverList.Add(device);
|
|
|
// }
|
|
|
// }
|
|
|
// catch (Exception ex)
|
|
@@ -102,23 +252,22 @@
|
|
|
// return;
|
|
|
// }
|
|
|
|
|
|
- // if (!GetExistingServers(usn).Any())
|
|
|
- // {
|
|
|
- // return;
|
|
|
- // }
|
|
|
-
|
|
|
// await _syncLock.WaitAsync().ConfigureAwait(false);
|
|
|
|
|
|
// try
|
|
|
// {
|
|
|
- // var list = _servers.ToList();
|
|
|
+ // var serverList = _servers.ToList();
|
|
|
|
|
|
- // foreach (var device in GetExistingServers(usn).ToList())
|
|
|
+ // var matchingServers = GetExistingServers(serverList, usn);
|
|
|
+ // if (matchingServers.Count > 0)
|
|
|
// {
|
|
|
- // list.Remove(device);
|
|
|
- // }
|
|
|
+ // foreach (var device in matchingServers)
|
|
|
+ // {
|
|
|
+ // serverList.Remove(device);
|
|
|
+ // }
|
|
|
|
|
|
- // _servers = list;
|
|
|
+ // _servers = serverList;
|
|
|
+ // }
|
|
|
// }
|
|
|
// finally
|
|
|
// {
|
|
@@ -140,185 +289,17 @@
|
|
|
// return true;
|
|
|
// }
|
|
|
|
|
|
- // private IEnumerable<Device> GetExistingServers(string usn)
|
|
|
- // {
|
|
|
- // return _servers
|
|
|
- // .Where(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1);
|
|
|
- // }
|
|
|
-
|
|
|
- // public IEnumerable<IChannel> GetChannels()
|
|
|
+ // private List<Device> GetExistingServers(List<Device> allDevices, string usn)
|
|
|
// {
|
|
|
- // //if (_servers.Count > 0)
|
|
|
- // //{
|
|
|
- // // var service = _servers[0].Properties.Services
|
|
|
- // // .FirstOrDefault(i => string.Equals(i.ServiceType, "urn:schemas-upnp-org:service:ContentDirectory:1", StringComparison.OrdinalIgnoreCase));
|
|
|
-
|
|
|
- // // var controlUrl = service == null ? null : (_servers[0].Properties.BaseUrl.TrimEnd('/') + "/" + service.ControlUrl.TrimStart('/'));
|
|
|
-
|
|
|
- // // if (!string.IsNullOrEmpty(controlUrl))
|
|
|
- // // {
|
|
|
- // // return new List<IChannel>
|
|
|
- // // {
|
|
|
- // // new ServerChannel(_servers.ToList(), _httpClient, _logger, controlUrl)
|
|
|
- // // };
|
|
|
- // // }
|
|
|
- // //}
|
|
|
-
|
|
|
- // return new List<IChannel>();
|
|
|
+ // return allDevices
|
|
|
+ // .Where(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1)
|
|
|
+ // .ToList();
|
|
|
// }
|
|
|
|
|
|
// public void Dispose()
|
|
|
// {
|
|
|
- // if (_deviceDiscovery != null)
|
|
|
- // {
|
|
|
- // _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered;
|
|
|
- // _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft;
|
|
|
- // }
|
|
|
- // }
|
|
|
- //}
|
|
|
-
|
|
|
- //public class ServerChannel : IChannel, IFactoryChannel
|
|
|
- //{
|
|
|
- // private readonly IHttpClient _httpClient;
|
|
|
- // private readonly ILogger _logger;
|
|
|
- // public string ControlUrl { get; set; }
|
|
|
- // public List<Device> Servers { get; set; }
|
|
|
-
|
|
|
- // public ServerChannel(IHttpClient httpClient, ILogger logger)
|
|
|
- // {
|
|
|
- // _httpClient = httpClient;
|
|
|
- // _logger = logger;
|
|
|
- // Servers = new List<Device>();
|
|
|
- // }
|
|
|
-
|
|
|
- // public string Name
|
|
|
- // {
|
|
|
- // get { return "Devices"; }
|
|
|
- // }
|
|
|
-
|
|
|
- // public string Description
|
|
|
- // {
|
|
|
- // get { return string.Empty; }
|
|
|
- // }
|
|
|
-
|
|
|
- // public string DataVersion
|
|
|
- // {
|
|
|
- // get { return DateTime.UtcNow.Ticks.ToString(); }
|
|
|
- // }
|
|
|
-
|
|
|
- // public string HomePageUrl
|
|
|
- // {
|
|
|
- // get { return string.Empty; }
|
|
|
- // }
|
|
|
-
|
|
|
- // public ChannelParentalRating ParentalRating
|
|
|
- // {
|
|
|
- // get { return ChannelParentalRating.GeneralAudience; }
|
|
|
- // }
|
|
|
-
|
|
|
- // public InternalChannelFeatures GetChannelFeatures()
|
|
|
- // {
|
|
|
- // return new InternalChannelFeatures
|
|
|
- // {
|
|
|
- // ContentTypes = new List<ChannelMediaContentType>
|
|
|
- // {
|
|
|
- // ChannelMediaContentType.Song,
|
|
|
- // ChannelMediaContentType.Clip
|
|
|
- // },
|
|
|
-
|
|
|
- // MediaTypes = new List<ChannelMediaType>
|
|
|
- // {
|
|
|
- // ChannelMediaType.Audio,
|
|
|
- // ChannelMediaType.Video,
|
|
|
- // ChannelMediaType.Photo
|
|
|
- // }
|
|
|
- // };
|
|
|
- // }
|
|
|
-
|
|
|
- // public bool IsEnabledFor(string userId)
|
|
|
- // {
|
|
|
- // return true;
|
|
|
- // }
|
|
|
-
|
|
|
- // public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
|
|
|
- // {
|
|
|
- // IEnumerable<ChannelItemInfo> items;
|
|
|
-
|
|
|
- // if (string.IsNullOrWhiteSpace(query.FolderId))
|
|
|
- // {
|
|
|
- // items = Servers.Select(i => new ChannelItemInfo
|
|
|
- // {
|
|
|
- // FolderType = ChannelFolderType.Container,
|
|
|
- // Id = GetServerId(i),
|
|
|
- // Name = i.Properties.Name,
|
|
|
- // Overview = i.Properties.ModelDescription,
|
|
|
- // Type = ChannelItemType.Folder
|
|
|
- // });
|
|
|
- // }
|
|
|
- // else
|
|
|
- // {
|
|
|
- // var idParts = query.FolderId.Split('|');
|
|
|
- // var folderId = idParts.Length == 2 ? idParts[1] : null;
|
|
|
-
|
|
|
- // var result = await new ContentDirectoryBrowser(_httpClient, _logger).Browse(new ContentDirectoryBrowseRequest
|
|
|
- // {
|
|
|
- // Limit = query.Limit,
|
|
|
- // StartIndex = query.StartIndex,
|
|
|
- // ParentId = folderId,
|
|
|
- // ContentDirectoryUrl = ControlUrl
|
|
|
-
|
|
|
- // }, cancellationToken).ConfigureAwait(false);
|
|
|
-
|
|
|
- // items = result.Items.ToList();
|
|
|
- // }
|
|
|
-
|
|
|
- // var list = items.ToList();
|
|
|
- // var count = list.Count;
|
|
|
-
|
|
|
- // list = ApplyPaging(list, query).ToList();
|
|
|
-
|
|
|
- // return new ChannelItemResult
|
|
|
- // {
|
|
|
- // Items = list,
|
|
|
- // TotalRecordCount = count
|
|
|
- // };
|
|
|
- // }
|
|
|
-
|
|
|
- // private string GetServerId(Device device)
|
|
|
- // {
|
|
|
- // return device.Properties.UUID.GetMD5().ToString("N");
|
|
|
- // }
|
|
|
-
|
|
|
- // private IEnumerable<T> ApplyPaging<T>(IEnumerable<T> items, InternalChannelItemQuery query)
|
|
|
- // {
|
|
|
- // if (query.StartIndex.HasValue)
|
|
|
- // {
|
|
|
- // items = items.Skip(query.StartIndex.Value);
|
|
|
- // }
|
|
|
-
|
|
|
- // if (query.Limit.HasValue)
|
|
|
- // {
|
|
|
- // items = items.Take(query.Limit.Value);
|
|
|
- // }
|
|
|
-
|
|
|
- // return items;
|
|
|
- // }
|
|
|
-
|
|
|
- // public Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
|
|
|
- // {
|
|
|
- // // TODO: Implement
|
|
|
- // return Task.FromResult(new DynamicImageResponse
|
|
|
- // {
|
|
|
- // HasImage = false
|
|
|
- // });
|
|
|
- // }
|
|
|
-
|
|
|
- // public IEnumerable<ImageType> GetSupportedChannelImages()
|
|
|
- // {
|
|
|
- // return new List<ImageType>
|
|
|
- // {
|
|
|
- // ImageType.Primary
|
|
|
- // };
|
|
|
+ // _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered;
|
|
|
+ // _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft;
|
|
|
// }
|
|
|
//}
|
|
|
}
|