diff --git a/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs b/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs index 9b5fa726c8..834bac67dc 100644 --- a/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs +++ b/MediaBrowser.Common.Implementations/Networking/BaseNetworkManager.cs @@ -139,11 +139,13 @@ namespace MediaBrowser.Common.Implementations.Networking IPAddress address; if (IPAddress.TryParse(endpoint, out address)) { + var addressString = address.ToString(); + int lengthMatch = 100; if (address.AddressFamily == AddressFamily.InterNetwork) { lengthMatch = 4; - if (IsInPrivateAddressSpaceIpv4(endpoint)) + if (IsInPrivateAddressSpaceIpv4(addressString)) { return true; } @@ -158,9 +160,9 @@ namespace MediaBrowser.Common.Implementations.Networking } // Should be even be doing this with ipv6? - if (endpoint.Length >= lengthMatch) + if (addressString.Length >= lengthMatch) { - var prefix = endpoint.Substring(0, lengthMatch); + var prefix = addressString.Substring(0, lengthMatch); if (GetLocalIpAddresses() .Any(i => i.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))) @@ -168,9 +170,8 @@ namespace MediaBrowser.Common.Implementations.Networking return true; } } - } - - if (resolveHost && !IPAddress.TryParse(endpoint, out address)) + } + else if (resolveHost) { Uri uri; if (Uri.TryCreate(endpoint, UriKind.RelativeOrAbsolute, out uri)) diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 8bf0668874..af349ae120 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -565,7 +565,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv isNew = true; } item.ParentId = parentFolderId; - + item.ChannelType = channelInfo.ChannelType; item.ServiceName = serviceName; item.Number = channelInfo.Number; @@ -633,7 +633,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv forceUpdate = true; } item.ParentId = channel.Id; - + //item.ChannelType = channelType; if (!string.Equals(item.ServiceName, serviceName, StringComparison.Ordinal)) { @@ -781,7 +781,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv dataChanged = true; } item.ParentId = parentFolderId; - + if (!item.HasImage(ImageType.Primary)) { if (!string.IsNullOrWhiteSpace(info.ImagePath)) @@ -847,7 +847,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv var dto = _dtoService.GetBaseItemDto(program, new DtoOptions(), user); - await AddRecordingInfo(new[] { dto }, cancellationToken).ConfigureAwait(false); + var list = new List>(); + list.Add(new Tuple(dto, program.ServiceName, program.ExternalId)); + + await AddRecordingInfo(list, cancellationToken).ConfigureAwait(false); return dto; } @@ -889,14 +892,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv var queryResult = _libraryManager.QueryItems(internalQuery); var returnArray = queryResult.Items - .Select(i => _dtoService.GetBaseItemDto(i, options, user)) + .Cast() + .Select(i => new Tuple(_dtoService.GetBaseItemDto(i, options, user), i.ServiceName, i.ExternalId)) .ToArray(); await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false); var result = new QueryResult { - Items = returnArray, + Items = returnArray.Select(i => i.Item1).ToArray(), TotalRecordCount = queryResult.TotalRecordCount }; @@ -968,14 +972,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv var user = _userManager.GetUserById(query.UserId); var returnArray = internalResult.Items - .Select(i => _dtoService.GetBaseItemDto(i, options, user)) + .Select(i => new Tuple(_dtoService.GetBaseItemDto(i, options, user), i.ServiceName, i.ExternalId)) .ToArray(); await AddRecordingInfo(returnArray, cancellationToken).ConfigureAwait(false); var result = new QueryResult { - Items = returnArray, + Items = returnArray.Select(i => i.Item1).ToArray(), TotalRecordCount = internalResult.TotalRecordCount }; @@ -1051,44 +1055,46 @@ namespace MediaBrowser.Server.Implementations.LiveTv }).Sum(); } - private async Task AddRecordingInfo(IEnumerable programs, CancellationToken cancellationToken) + private async Task AddRecordingInfo(IEnumerable> programs, CancellationToken cancellationToken) { var timers = new Dictionary>(); - foreach (var program in programs) + foreach (var programTuple in programs) { - var internalProgram = GetInternalProgram(program.Id); + var program = programTuple.Item1; + var serviceName = programTuple.Item2; + var externalProgramId = programTuple.Item3; - if (string.IsNullOrWhiteSpace(internalProgram.ServiceName)) + if (string.IsNullOrWhiteSpace(serviceName)) { continue; } List timerList; - if (!timers.TryGetValue(internalProgram.ServiceName, out timerList)) + if (!timers.TryGetValue(serviceName, out timerList)) { try { - var tempTimers = await GetService(internalProgram.ServiceName).GetTimersAsync(cancellationToken).ConfigureAwait(false); - timers[internalProgram.ServiceName] = timerList = tempTimers.ToList(); + var tempTimers = await GetService(serviceName).GetTimersAsync(cancellationToken).ConfigureAwait(false); + timers[serviceName] = timerList = tempTimers.ToList(); } catch (Exception ex) { _logger.ErrorException("Error getting timer infos", ex); - timers[internalProgram.ServiceName] = timerList = new List(); + timers[serviceName] = timerList = new List(); } } - var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, internalProgram.ExternalId, StringComparison.OrdinalIgnoreCase)); + var timer = timerList.FirstOrDefault(i => string.Equals(i.ProgramId, externalProgramId, StringComparison.OrdinalIgnoreCase)); if (timer != null) { - program.TimerId = _tvDtoService.GetInternalTimerId(internalProgram.ServiceName, timer.Id) + program.TimerId = _tvDtoService.GetInternalTimerId(serviceName, timer.Id) .ToString("N"); if (!string.IsNullOrEmpty(timer.SeriesTimerId)) { - program.SeriesTimerId = _tvDtoService.GetInternalSeriesTimerId(internalProgram.ServiceName, timer.SeriesTimerId) + program.SeriesTimerId = _tvDtoService.GetInternalSeriesTimerId(serviceName, timer.SeriesTimerId) .ToString("N"); } } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index cea45daa5f..bf95fa6124 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1059,7 +1059,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var tvItem = item as ILiveTvItem; if (tvItem != null) { - item.ForcedSortName = reader.GetString(43); + tvItem.ServiceName = reader.GetString(43); } }