diff options
Diffstat (limited to 'MediaBrowser.Server.Implementations')
11 files changed, 160 insertions, 49 deletions
diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs index 18117c100..031ca85f9 100644 --- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs +++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs @@ -1,5 +1,4 @@ -using System.Linq; -using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Configuration; using MediaBrowser.Common.Events; using MediaBrowser.Common.Implementations.Configuration; using MediaBrowser.Controller; @@ -14,6 +13,7 @@ using MediaBrowser.Model.Logging; using MediaBrowser.Model.Serialization; using System; using System.IO; +using System.Linq; namespace MediaBrowser.Server.Implementations.Configuration { diff --git a/MediaBrowser.Server.Implementations/Dto/DtoService.cs b/MediaBrowser.Server.Implementations/Dto/DtoService.cs index c4499fac0..afcfde556 100644 --- a/MediaBrowser.Server.Implementations/Dto/DtoService.cs +++ b/MediaBrowser.Server.Implementations/Dto/DtoService.cs @@ -66,22 +66,35 @@ namespace MediaBrowser.Server.Implementations.Dto /// <exception cref="System.ArgumentNullException">item</exception> public BaseItemDto GetBaseItemDto(BaseItem item, List<ItemFields> fields, User user = null, BaseItem owner = null) { + var dto = GetBaseItemDtoInternal(item, fields, user, owner); + var byName = item as IItemByName; - if (byName != null) + if (byName != null && !(item is LiveTvChannel)) { - var libraryItems = user != null ? - user.RootFolder.GetRecursiveChildren(user) : - _libraryManager.RootFolder.RecursiveChildren; + IEnumerable<BaseItem> libraryItems; + + var artist = item as MusicArtist; - var dto = GetBaseItemDtoInternal(item, fields, user); + if (artist == null || artist.IsAccessedByName) + { + libraryItems = user != null ? + user.RootFolder.GetRecursiveChildren(user) : + _libraryManager.RootFolder.RecursiveChildren; + } + else + { + libraryItems = user != null ? + artist.GetRecursiveChildren(user) : + artist.RecursiveChildren; + } SetItemByNameInfo(item, dto, byName.GetTaggedItems(libraryItems).ToList(), user); return dto; } - return GetBaseItemDtoInternal(item, fields, user, owner); + return dto; } private BaseItemDto GetBaseItemDtoInternal(BaseItem item, List<ItemFields> fields, User user = null, BaseItem owner = null) diff --git a/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs b/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs index 7e5d5d3d8..9191e0bea 100644 --- a/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs +++ b/MediaBrowser.Server.Implementations/EntryPoints/UdpServerEntryPoint.cs @@ -1,4 +1,5 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Net; using MediaBrowser.Controller.Plugins; @@ -35,6 +36,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// The _HTTP server /// </summary> private readonly IHttpServer _httpServer; + private readonly IServerApplicationHost _appHost; public const int PortNumber = 7359; @@ -45,12 +47,13 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// <param name="networkManager">The network manager.</param> /// <param name="serverConfigurationManager">The server configuration manager.</param> /// <param name="httpServer">The HTTP server.</param> - public UdpServerEntryPoint(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer) + public UdpServerEntryPoint(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer, IServerApplicationHost appHost) { _logger = logger; _networkManager = networkManager; _serverConfigurationManager = serverConfigurationManager; _httpServer = httpServer; + _appHost = appHost; } /// <summary> @@ -58,7 +61,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints /// </summary> public void Run() { - var udpServer = new UdpServer(_logger, _networkManager, _serverConfigurationManager, _httpServer); + var udpServer = new UdpServer(_logger, _networkManager, _serverConfigurationManager, _httpServer, _appHost); try { diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvConfigurationFactory.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvConfigurationFactory.cs new file mode 100644 index 000000000..fefe6401d --- /dev/null +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvConfigurationFactory.cs @@ -0,0 +1,21 @@ +using MediaBrowser.Common.Configuration; +using MediaBrowser.Model.Configuration; +using System.Collections.Generic; + +namespace MediaBrowser.Server.Implementations.LiveTv +{ + public class LiveTvConfigurationFactory : IConfigurationFactory + { + public IEnumerable<ConfigurationStore> GetConfigurations() + { + return new List<ConfigurationStore> + { + new ConfigurationStore + { + ConfigurationType = typeof(LiveTvOptions), + Key = "livetv" + } + }; + } + } +} diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index a0eb9f2b4..251acb02d 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -1,4 +1,5 @@ -using MediaBrowser.Common.Extensions; +using MediaBrowser.Common.Configuration; +using MediaBrowser.Common.Extensions; using MediaBrowser.Common.IO; using MediaBrowser.Common.ScheduledTasks; using MediaBrowser.Controller.Configuration; @@ -11,6 +12,7 @@ using MediaBrowser.Controller.Localization; using MediaBrowser.Controller.Persistence; using MediaBrowser.Controller.Providers; using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; using MediaBrowser.Model.LiveTv; @@ -83,6 +85,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv public ILiveTvService ActiveService { get; private set; } + private LiveTvOptions GetConfiguration() + { + return _config.GetConfiguration<LiveTvOptions>("livetv"); + } + /// <summary> /// Adds the parts. /// </summary> @@ -91,7 +98,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv { _services.AddRange(services); - SetActiveService(_config.Configuration.LiveTvOptions.ActiveService); + SetActiveService(GetConfiguration().ActiveService); } private void SetActiveService(string name) @@ -303,22 +310,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv try { - // Avoid implicitly captured closure - var itemId = id; - - var stream = _openStreams - .Where(i => string.Equals(i.Value.ItemId, itemId) && isChannel == i.Value.IsChannel) - .Take(1) - .Select(i => i.Value) - .FirstOrDefault(); - - if (stream != null) - { - stream.ConsumerCount++; - _logger.Debug("Returning existing live tv stream"); - return stream.Info; - } - var service = ActiveService; LiveStreamInfo info; @@ -1010,9 +1001,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv private double GetGuideDays(int channelCount) { - if (_config.Configuration.LiveTvOptions.GuideDays.HasValue) + var config = GetConfiguration(); + + if (config.GuideDays.HasValue) { - return _config.Configuration.LiveTvOptions.GuideDays.Value; + return config.GuideDays.Value; } var programsPerDay = channelCount * 48; diff --git a/MediaBrowser.Server.Implementations/Localization/Server/server.json b/MediaBrowser.Server.Implementations/Localization/Server/server.json index 8b3a5e8c9..caf8860fc 100644 --- a/MediaBrowser.Server.Implementations/Localization/Server/server.json +++ b/MediaBrowser.Server.Implementations/Localization/Server/server.json @@ -699,6 +699,10 @@ "HeaderProfileServerSettingsHelp": "These values control how Media Browser will present itself to the device.", "LabelMaxBitrate": "Max bitrate:", "LabelMaxBitrateHelp": "Specify a max bitrate in bandwidth constrained environments, or if the device imposes it's own limit.", + "LabelMaxStreamingBitrate": "Max streaming bitrate:", + "LabelMaxStreamingBitrateHelp": "Specify a max bitrate when streaming.", + "LabelMaxStaticBitrate": "Max sync bitrate:", + "LabelMaxStaticBitrateHelp": "Specify a max bitrate when syncing content at high quality.", "OptionIgnoreTranscodeByteRangeRequests": "Ignore transcode byte range requests", "OptionIgnoreTranscodeByteRangeRequestsHelp": "If enabled, these requests will be honored but will ignore the byte range header.", "LabelFriendlyName": "Friendly name", @@ -905,5 +909,11 @@ "HeaderChapters": "Chapters", "HeaderResumeSettings": "Resume Settings", "TabSync": "Sync", - "TitleUsers": "Users" + "TitleUsers": "Users", + "LabelProtocol": "Protocol:", + "OptionProtocolHttp": "Http", + "OptionProtocolHls": "Http Live Streaming", + "LabelContext": "Context:", + "OptionContextStreaming": "Streaming", + "OptionContextStatic": "Sync" } diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index ef6730b75..79d15039b 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -198,6 +198,7 @@ <Compile Include="Library\Validators\YearsPostScanTask.cs" /> <Compile Include="LiveTv\ChannelImageProvider.cs" /> <Compile Include="LiveTv\CleanDatabaseScheduledTask.cs" /> + <Compile Include="LiveTv\LiveTvConfigurationFactory.cs" /> <Compile Include="LiveTv\LiveTvDtoService.cs" /> <Compile Include="LiveTv\LiveTvManager.cs" /> <Compile Include="LiveTv\ProgramImageProvider.cs" /> diff --git a/MediaBrowser.Server.Implementations/Security/EncryptionManager.cs b/MediaBrowser.Server.Implementations/Security/EncryptionManager.cs index 73a4e3004..33818dcea 100644 --- a/MediaBrowser.Server.Implementations/Security/EncryptionManager.cs +++ b/MediaBrowser.Server.Implementations/Security/EncryptionManager.cs @@ -17,6 +17,10 @@ namespace MediaBrowser.Server.Implementations.Security { if (value == null) throw new ArgumentNullException("value"); +#if __MonoCS__ + return EncryptStringUniversal(value); +#endif + return Encoding.Default.GetString(ProtectedData.Protect(Encoding.Default.GetBytes(value), null, DataProtectionScope.LocalMachine)); } @@ -30,7 +34,27 @@ namespace MediaBrowser.Server.Implementations.Security { if (value == null) throw new ArgumentNullException("value"); +#if __MonoCS__ + return DecryptStringUniversal(value); +#endif + return Encoding.Default.GetString(ProtectedData.Unprotect(Encoding.Default.GetBytes(value), null, DataProtectionScope.LocalMachine)); } + + private string EncryptStringUniversal(string value) + { + // Yes, this isn't good, but ProtectedData in mono is throwing exceptions, so use this for now + + var bytes = Encoding.UTF8.GetBytes(value); + return Convert.ToBase64String(bytes); + } + + private string DecryptStringUniversal(string value) + { + // Yes, this isn't good, but ProtectedData in mono is throwing exceptions, so use this for now + + var bytes = Convert.FromBase64String(value); + return Encoding.UTF8.GetString(bytes); + } } } diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 168948821..61c65cfd6 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -1236,7 +1236,8 @@ namespace MediaBrowser.Server.Implementations.Session { User = _dtoService.GetUserDto(user), SessionInfo = GetSessionInfoDto(session), - AccessToken = token + AccessToken = token, + ServerId = _appHost.ServerId }; } diff --git a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs index a8d723ce3..b5e13e306 100644 --- a/MediaBrowser.Server.Implementations/Sync/SyncManager.cs +++ b/MediaBrowser.Server.Implementations/Sync/SyncManager.cs @@ -68,7 +68,8 @@ namespace MediaBrowser.Server.Implementations.Sync LimitType = request.LimitType, RequestedItemIds = request.ItemIds, DateCreated = DateTime.UtcNow, - DateLastModified = DateTime.UtcNow + DateLastModified = DateTime.UtcNow, + ItemCount = 1 }; await _repo.Create(job).ConfigureAwait(false); diff --git a/MediaBrowser.Server.Implementations/Udp/UdpServer.cs b/MediaBrowser.Server.Implementations/Udp/UdpServer.cs index 6b5cac196..f78f983dc 100644 --- a/MediaBrowser.Server.Implementations/Udp/UdpServer.cs +++ b/MediaBrowser.Server.Implementations/Udp/UdpServer.cs @@ -1,8 +1,12 @@ using MediaBrowser.Common.Net; +using MediaBrowser.Controller; using MediaBrowser.Controller.Configuration; using MediaBrowser.Controller.Net; +using MediaBrowser.Model.ApiClient; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Serialization; using System; +using System.Collections.Generic; using System.Linq; using System.Net; using System.Net.Sockets; @@ -37,6 +41,11 @@ namespace MediaBrowser.Server.Implementations.Udp private bool _isDisposed; + private readonly List<Tuple<byte[], Action<string>>> _responders = new List<Tuple<byte[], Action<string>>>(); + + private readonly IServerApplicationHost _appHost; + private readonly IJsonSerializer _json; + /// <summary> /// Initializes a new instance of the <see cref="UdpServer" /> class. /// </summary> @@ -44,12 +53,24 @@ namespace MediaBrowser.Server.Implementations.Udp /// <param name="networkManager">The network manager.</param> /// <param name="serverConfigurationManager">The server configuration manager.</param> /// <param name="httpServer">The HTTP server.</param> - public UdpServer(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer) + /// <param name="appHost">The application host.</param> + public UdpServer(ILogger logger, INetworkManager networkManager, IServerConfigurationManager serverConfigurationManager, IHttpServer httpServer, IServerApplicationHost appHost) { _logger = logger; _networkManager = networkManager; _serverConfigurationManager = serverConfigurationManager; _httpServer = httpServer; + _appHost = appHost; + + AddMessageResponder("who is MediaBrowserServer?", RespondToV1Message); + AddMessageResponder("who is MediaBrowserServer_v2?", RespondToV2Message); + } + + private void AddMessageResponder(string message, Action<string> responder) + { + var expectedMessageBytes = Encoding.UTF8.GetBytes(message); + + _responders.Add(new Tuple<byte[], Action<string>>(expectedMessageBytes, responder)); } /// <summary> @@ -58,28 +79,51 @@ namespace MediaBrowser.Server.Implementations.Udp /// <param name="e">The <see cref="UdpMessageReceivedEventArgs"/> instance containing the event data.</param> private async void OnMessageReceived(UdpMessageReceivedEventArgs e) { - const string context = "Server"; + var responder = _responders.FirstOrDefault(i => i.Item1.SequenceEqual(e.Bytes)); - var expectedMessage = String.Format("who is MediaBrowser{0}?", context); - var expectedMessageBytes = Encoding.UTF8.GetBytes(expectedMessage); + if (responder != null) + { + responder.Item2(e.RemoteEndPoint); + } + } - if (expectedMessageBytes.SequenceEqual(e.Bytes)) + private async void RespondToV1Message(string endpoint) + { + var localAddress = GetLocalIpAddress(); + + if (!string.IsNullOrEmpty(localAddress)) { - _logger.Info("Received UDP server request from " + e.RemoteEndPoint); + // Send a response back with our ip address and port + var response = String.Format("MediaBrowserServer|{0}:{1}", localAddress, _serverConfigurationManager.Configuration.HttpServerPortNumber); - var localAddress = GetLocalIpAddress(); + await SendAsync(Encoding.UTF8.GetBytes(response), endpoint); + } + else + { + _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); + } + } - if (!string.IsNullOrEmpty(localAddress)) - { - // Send a response back with our ip address and port - var response = String.Format("MediaBrowser{0}|{1}:{2}", context, GetLocalIpAddress(), _serverConfigurationManager.Configuration.HttpServerPortNumber); + private async void RespondToV2Message(string endpoint) + { + var localAddress = GetLocalIpAddress(); - await SendAsync(Encoding.UTF8.GetBytes(response), e.RemoteEndPoint); - } - else + if (!string.IsNullOrEmpty(localAddress)) + { + var serverAddress = string.Format("http://{0}:{1}", localAddress, _serverConfigurationManager.Configuration.HttpServerPortNumber); + + var response = new ServerDiscoveryInfo { - _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); - } + Address = serverAddress, + Id = _appHost.ServerId, + Name = _appHost.Name + }; + + await SendAsync(Encoding.UTF8.GetBytes(_json.SerializeToString(response)), endpoint); + } + else + { + _logger.Warn("Unable to respond to udp request because the local ip address could not be determined."); } } |
