Merge pull request #1735 from MediaBrowser/dev

update tabs
pull/702/head
Luke 9 years ago
commit 8cc618232b

@ -1,324 +1,305 @@
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 ILogger _logger;
// private readonly IHttpClient _httpClient; // private readonly IHttpClient _httpClient;
// private readonly IServerConfigurationManager _config;
// private List<Device> _servers = new List<Device>();
// private readonly IDeviceDiscovery _deviceDiscovery; // private readonly IDeviceDiscovery _deviceDiscovery;
// private readonly SemaphoreSlim _syncLock = new SemaphoreSlim(1, 1); // private readonly SemaphoreSlim _syncLock = new SemaphoreSlim(1, 1);
// private List<Device> _servers = new List<Device>();
// public static DlnaChannelFactory Instance;
// private Func<List<string>> _localServersLookup; // 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; // _logger = logger;
// _httpClient = httpClient;
// _deviceDiscovery = deviceDiscovery; // _deviceDiscovery = deviceDiscovery;
// Instance = this; // _config = config;
// Current = this;
// } // }
// internal void Start(Func<List<string>> localServersLookup) // public string Name
// { // {
// _localServersLookup = localServersLookup; // get { return "Devices"; }
// //deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered;
// _deviceDiscovery.DeviceLeft += deviceDiscovery_DeviceLeft;
// } // }
// async void deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e) // public string Description
// {
// string usn;
// if (!e.Headers.TryGetValue("USN", out usn)) usn = string.Empty;
// string nt;
// if (!e.Headers.TryGetValue("NT", out nt)) nt = string.Empty;
// string location;
// if (!e.Headers.TryGetValue("Location", out location)) location = string.Empty;
// if (!IsValid(nt, usn))
// { // {
// return; // get { return string.Empty; }
// } // }
// if (_localServersLookup != null) // public string DataVersion
// {
// if (_localServersLookup().Any(i => usn.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))
// { // {
// // Don't add the local Dlna server to this // get { return DateTime.UtcNow.Ticks.ToString(); }
// return;
// }
// } // }
// if (GetExistingServers(usn).Any()) // public string HomePageUrl
// { // {
// return; // get { return string.Empty; }
// } // }
// await _syncLock.WaitAsync().ConfigureAwait(false); // public ChannelParentalRating ParentalRating
// try
// {
// if (GetExistingServers(usn).Any())
// { // {
// return; // get { return ChannelParentalRating.GeneralAudience; }
// } // }
// var device = await Device.CreateuPnpDeviceAsync(new Uri(location), _httpClient, _config, _logger) // public InternalChannelFeatures GetChannelFeatures()
// .ConfigureAwait(false);
// if (!_servers.Any(i => string.Equals(i.Properties.UUID, device.Properties.UUID, StringComparison.OrdinalIgnoreCase)))
// { // {
// _servers.Add(device); // return new InternalChannelFeatures
// } // {
// } // ContentTypes = new List<ChannelMediaContentType>
// catch (Exception ex)
// { // {
// ChannelMediaContentType.Song,
// ChannelMediaContentType.Clip
// },
// } // MediaTypes = new List<ChannelMediaType>
// finally
// { // {
// _syncLock.Release(); // ChannelMediaType.Audio,
// ChannelMediaType.Video,
// ChannelMediaType.Photo
// } // }
// };
// } // }
// async void deviceDiscovery_DeviceLeft(object sender, SsdpMessageEventArgs e) // public bool IsEnabledFor(string userId)
// {
// string usn;
// if (!e.Headers.TryGetValue("USN", out usn)) usn = String.Empty;
// string nt;
// if (!e.Headers.TryGetValue("NT", out nt)) nt = String.Empty;
// if (!IsValid(nt, usn))
// { // {
// return; // return true;
// } // }
// if (!GetExistingServers(usn).Any()) // public Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken)
// { // {
// return; // throw new NotImplementedException();
// } // }
// await _syncLock.WaitAsync().ConfigureAwait(false); // public IEnumerable<ImageType> GetSupportedChannelImages()
// try
// { // {
// var list = _servers.ToList(); // return new List<ImageType>
// foreach (var device in GetExistingServers(usn).ToList())
// { // {
// list.Remove(device); // ImageType.Primary
// };
// } // }
// _servers = list; // public void Start(Func<List<string>> localServersLookup)
// }
// finally
// { // {
// _syncLock.Release(); // _localServersLookup = localServersLookup;
// }
// _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered;
// _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft;
// _deviceDiscovery.DeviceDiscovered += deviceDiscovery_DeviceDiscovered;
// _deviceDiscovery.DeviceLeft += deviceDiscovery_DeviceLeft;
// } // }
// private bool IsValid(string nt, string usn) // public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken)
// { // {
// // It has to report that it's a media renderer // if (string.IsNullOrWhiteSpace(query.FolderId))
// if (usn.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 &&
// nt.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 &&
// usn.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1 &&
// nt.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1)
// { // {
// return false; // return await GetServers(query, cancellationToken).ConfigureAwait(false);
// } // }
// return true; // return new ChannelItemResult();
// }
// private IEnumerable<Device> GetExistingServers(string usn) // //var idParts = query.FolderId.Split('|');
// { // //var folderId = idParts.Length == 2 ? idParts[1] : null;
// return _servers
// .Where(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1);
// }
// public IEnumerable<IChannel> GetChannels() // //var result = await new ContentDirectoryBrowser(_httpClient, _logger).Browse(new ContentDirectoryBrowseRequest
// {
// //if (_servers.Count > 0)
// //{ // //{
// // var service = _servers[0].Properties.Services // // Limit = query.Limit,
// // .FirstOrDefault(i => string.Equals(i.ServiceType, "urn:schemas-upnp-org:service:ContentDirectory:1", StringComparison.OrdinalIgnoreCase)); // // StartIndex = query.StartIndex,
// // ParentId = folderId,
// // ContentDirectoryUrl = ControlUrl
// // var controlUrl = service == null ? null : (_servers[0].Properties.BaseUrl.TrimEnd('/') + "/" + service.ControlUrl.TrimStart('/')); // //}, cancellationToken).ConfigureAwait(false);
// // if (!string.IsNullOrEmpty(controlUrl)) // //items = result.Items.ToList();
// // {
// // return new List<IChannel> // //var list = items.ToList();
// //var count = list.Count;
// //list = ApplyPaging(list, query).ToList();
// //return new ChannelItemResult
// //{ // //{
// // new ServerChannel(_servers.ToList(), _httpClient, _logger, controlUrl) // // Items = list,
// // TotalRecordCount = count
// //}; // //};
// // }
// //}
// return new List<IChannel>();
// } // }
// public void Dispose() // public async Task<ChannelItemResult> GetServers(InternalChannelItemQuery query, CancellationToken cancellationToken)
// {
// if (_deviceDiscovery != null)
// { // {
// _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered; // await _syncLock.WaitAsync(cancellationToken).ConfigureAwait(false);
// _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft;
// }
// }
//}
//public class ServerChannel : IChannel, IFactoryChannel // try
// { // {
// private readonly IHttpClient _httpClient; // var items = _servers.Select(i =>
// private readonly ILogger _logger; // {
// public string ControlUrl { get; set; } // var service = i.Properties.Services
// public List<Device> Servers { get; set; } // .FirstOrDefault(s => string.Equals(s.ServiceType, "urn:schemas-upnp-org:service:ContentDirectory:1", StringComparison.OrdinalIgnoreCase));
// public ServerChannel(IHttpClient httpClient, ILogger logger) // var controlUrl = service == null ? null : (_servers[0].Properties.BaseUrl.TrimEnd('/') + "/" + service.ControlUrl.TrimStart('/'));
// if (string.IsNullOrWhiteSpace(controlUrl))
// { // {
// _httpClient = httpClient; // return null;
// _logger = logger;
// Servers = new List<Device>();
// } // }
// public string Name // return new ChannelItemInfo
// { // {
// get { return "Devices"; } // Id = i.Properties.UUID,
// } // Name = i.Properties.Name,
// Type = ChannelItemType.Folder
// };
// public string Description // }).Where(i => i != null).ToList();
// return new ChannelItemResult
// { // {
// get { return string.Empty; } // TotalRecordCount = items.Count,
// Items = items
// };
// } // }
// finally
// public string DataVersion
// { // {
// get { return DateTime.UtcNow.Ticks.ToString(); } // _syncLock.Release();
// }
// } // }
// public string HomePageUrl // async void deviceDiscovery_DeviceDiscovered(object sender, SsdpMessageEventArgs e)
// { // {
// get { return string.Empty; } // string usn;
// } // if (!e.Headers.TryGetValue("USN", out usn)) usn = string.Empty;
// public ChannelParentalRating ParentalRating // string nt;
// if (!e.Headers.TryGetValue("NT", out nt)) nt = string.Empty;
// string location;
// if (!e.Headers.TryGetValue("Location", out location)) location = string.Empty;
// if (!IsValid(nt, usn))
// { // {
// get { return ChannelParentalRating.GeneralAudience; } // return;
// } // }
// public InternalChannelFeatures GetChannelFeatures() // if (_localServersLookup != null)
// {
// return new InternalChannelFeatures
// {
// ContentTypes = new List<ChannelMediaContentType>
// { // {
// ChannelMediaContentType.Song, // if (_localServersLookup().Any(i => usn.IndexOf(i, StringComparison.OrdinalIgnoreCase) != -1))
// ChannelMediaContentType.Clip
// },
// MediaTypes = new List<ChannelMediaType>
// { // {
// ChannelMediaType.Audio, // // Don't add the local Dlna server to this
// ChannelMediaType.Video, // return;
// ChannelMediaType.Photo
// } // }
// };
// } // }
// public bool IsEnabledFor(string userId) // await _syncLock.WaitAsync().ConfigureAwait(false);
// var serverList = _servers.ToList();
// try
// { // {
// return true; // if (GetExistingServers(serverList, usn).Any())
// {
// return;
// } // }
// public async Task<ChannelItemResult> GetChannelItems(InternalChannelItemQuery query, CancellationToken cancellationToken) // var device = await Device.CreateuPnpDeviceAsync(new Uri(location), _httpClient, _config, _logger)
// { // .ConfigureAwait(false);
// IEnumerable<ChannelItemInfo> items;
// if (string.IsNullOrWhiteSpace(query.FolderId)) // if (!serverList.Any(i => string.Equals(i.Properties.UUID, device.Properties.UUID, StringComparison.OrdinalIgnoreCase)))
// { // {
// items = Servers.Select(i => new ChannelItemInfo // serverList.Add(device);
// { // }
// FolderType = ChannelFolderType.Container,
// Id = GetServerId(i),
// Name = i.Properties.Name,
// Overview = i.Properties.ModelDescription,
// Type = ChannelItemType.Folder
// });
// } // }
// else // catch (Exception ex)
// { // {
// var idParts = query.FolderId.Split('|');
// var folderId = idParts.Length == 2 ? idParts[1] : null;
// var result = await new ContentDirectoryBrowser(_httpClient, _logger).Browse(new ContentDirectoryBrowseRequest // }
// finally
// { // {
// Limit = query.Limit, // _syncLock.Release();
// StartIndex = query.StartIndex, // }
// ParentId = folderId,
// ContentDirectoryUrl = ControlUrl
// }, cancellationToken).ConfigureAwait(false);
// items = result.Items.ToList();
// } // }
// var list = items.ToList(); // async void deviceDiscovery_DeviceLeft(object sender, SsdpMessageEventArgs e)
// var count = list.Count; // {
// string usn;
// if (!e.Headers.TryGetValue("USN", out usn)) usn = String.Empty;
// list = ApplyPaging(list, query).ToList(); // string nt;
// if (!e.Headers.TryGetValue("NT", out nt)) nt = String.Empty;
// return new ChannelItemResult // if (!IsValid(nt, usn))
// { // {
// Items = list, // return;
// TotalRecordCount = count
// };
// } // }
// private string GetServerId(Device device) // await _syncLock.WaitAsync().ConfigureAwait(false);
// try
// { // {
// return device.Properties.UUID.GetMD5().ToString("N"); // var serverList = _servers.ToList();
// }
// private IEnumerable<T> ApplyPaging<T>(IEnumerable<T> items, InternalChannelItemQuery query) // var matchingServers = GetExistingServers(serverList, usn);
// if (matchingServers.Count > 0)
// { // {
// if (query.StartIndex.HasValue) // foreach (var device in matchingServers)
// { // {
// items = items.Skip(query.StartIndex.Value); // serverList.Remove(device);
// } // }
// if (query.Limit.HasValue) // _servers = serverList;
// }
// }
// finally
// { // {
// items = items.Take(query.Limit.Value); // _syncLock.Release();
// } // }
// return items;
// } // }
// public Task<DynamicImageResponse> GetChannelImage(ImageType type, CancellationToken cancellationToken) // private bool IsValid(string nt, string usn)
// { // {
// // TODO: Implement // // It has to report that it's a media renderer
// return Task.FromResult(new DynamicImageResponse // if (usn.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 &&
// nt.IndexOf("ContentDirectory:", StringComparison.OrdinalIgnoreCase) == -1 &&
// usn.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1 &&
// nt.IndexOf("MediaServer:", StringComparison.OrdinalIgnoreCase) == -1)
// { // {
// HasImage = false // return false;
// });
// } // }
// public IEnumerable<ImageType> GetSupportedChannelImages() // return true;
// }
// private List<Device> GetExistingServers(List<Device> allDevices, string usn)
// { // {
// return new List<ImageType> // return allDevices
// .Where(i => usn.IndexOf(i.Properties.UUID, StringComparison.OrdinalIgnoreCase) != -1)
// .ToList();
// }
// public void Dispose()
// { // {
// ImageType.Primary // _deviceDiscovery.DeviceDiscovered -= deviceDiscovery_DeviceDiscovered;
// }; // _deviceDiscovery.DeviceLeft -= deviceDiscovery_DeviceLeft;
// } // }
//} //}
} }

@ -14,7 +14,9 @@ using MediaBrowser.Dlna.Ssdp;
using MediaBrowser.Model.Logging; using MediaBrowser.Model.Logging;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Controller.MediaEncoding; using MediaBrowser.Controller.MediaEncoding;
using MediaBrowser.Dlna.Channels;
namespace MediaBrowser.Dlna.Main namespace MediaBrowser.Dlna.Main
{ {
@ -167,6 +169,8 @@ namespace MediaBrowser.Dlna.Main
try try
{ {
((DeviceDiscovery)_deviceDiscovery).Start(_ssdpHandler); ((DeviceDiscovery)_deviceDiscovery).Start(_ssdpHandler);
//DlnaChannel.Current.Start(() => _registeredServerIds.ToList());
} }
catch (Exception ex) catch (Exception ex)
{ {

@ -548,7 +548,8 @@ namespace MediaBrowser.MediaEncoding.Probing
private void NormalizeStreamTitle(MediaStream stream) private void NormalizeStreamTitle(MediaStream stream)
{ {
if (string.Equals(stream.Title, "sdh", StringComparison.OrdinalIgnoreCase)) if (string.Equals(stream.Title, "sdh", StringComparison.OrdinalIgnoreCase) ||
string.Equals(stream.Title, "cc", StringComparison.OrdinalIgnoreCase))
{ {
stream.Title = null; stream.Title = null;
} }

@ -1383,6 +1383,28 @@ namespace MediaBrowser.Server.Implementations.LiveTv
} }
} }
private QueryResult<BaseItem> GetEmbyRecordings(RecordingQuery query, User user)
{
var folders = EmbyTV.EmbyTV.Current.GetRecordingFolders()
.SelectMany(i => i.Locations)
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(i => _libraryManager.FindByPath(i, true))
.Where(i => i != null)
.Where(i => i.IsVisibleStandalone(user))
.ToList();
var items = _libraryManager.GetItemsResult(new InternalItemsQuery(user)
{
MediaTypes = new[] { MediaType.Video },
Recursive = true,
AncestorIds = folders.Select(i => i.Id.ToString("N")).ToArray(),
ExcludeLocationTypes = new[] { LocationType.Virtual },
Limit = Math.Min(10, query.Limit ?? int.MaxValue)
});
return items;
}
public async Task<QueryResult<BaseItem>> GetInternalRecordings(RecordingQuery query, CancellationToken cancellationToken) public async Task<QueryResult<BaseItem>> GetInternalRecordings(RecordingQuery query, CancellationToken cancellationToken)
{ {
var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId);
@ -1391,6 +1413,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv
return new QueryResult<BaseItem>(); return new QueryResult<BaseItem>();
} }
if (user != null && !(query.IsInProgress ?? false))
{
var initialResult = GetEmbyRecordings(query, user);
if (initialResult.TotalRecordCount > 0)
{
return initialResult;
}
}
await RefreshRecordings(cancellationToken).ConfigureAwait(false); await RefreshRecordings(cancellationToken).ConfigureAwait(false);
var internalQuery = new InternalItemsQuery(user) var internalQuery = new InternalItemsQuery(user)
@ -2060,7 +2091,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv
}, cancellationToken).ConfigureAwait(false); }, cancellationToken).ConfigureAwait(false);
var recordings = recordingResult.Items.Cast<ILiveTvRecording>().ToList(); var recordings = recordingResult.Items.OfType<ILiveTvRecording>().ToList();
var groups = new List<BaseItemDto>(); var groups = new List<BaseItemDto>();

Loading…
Cancel
Save