aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/LiveTv
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-20 12:16:56 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2017-10-20 12:16:56 -0400
commit060215143ff62e4cf475a493e57c8607beca8640 (patch)
tree1d1095525a83bb8183184db952d28556bc05f323 /Emby.Server.Implementations/LiveTv
parent86226ff97c7d6dc4005c3bb1978861e948de1e20 (diff)
improve httpclient resource disposal
Diffstat (limited to 'Emby.Server.Implementations/LiveTv')
-rw-r--r--Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs3
-rw-r--r--Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs115
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs38
-rw-r--r--Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs15
4 files changed, 96 insertions, 75 deletions
diff --git a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
index 5c32086ff..e7a360594 100644
--- a/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
+++ b/Emby.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs
@@ -1463,6 +1463,9 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
_timerProvider.AddOrUpdate(timer, false);
await SaveRecordingMetadata(timer, recordPath, seriesPath).ConfigureAwait(false);
+
+ CreateRecordingFolders();
+
TriggerRefresh(recordPath);
EnforceKeepUpTo(timer, seriesPath);
};
diff --git a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
index b7cfdea1b..136d0cc7f 100644
--- a/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
+++ b/Emby.Server.Implementations/LiveTv/Listings/SchedulesDirect.cs
@@ -541,27 +541,30 @@ namespace Emby.Server.Implementations.LiveTv.Listings
try
{
- using (Stream responce = await Get(options, false, info).ConfigureAwait(false))
+ using (var httpResponse = await Get(options, false, info).ConfigureAwait(false))
{
- var root = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.Headends>>(responce);
-
- if (root != null)
+ using (Stream responce = httpResponse.Content)
{
- foreach (ScheduleDirect.Headends headend in root)
+ var root = _jsonSerializer.DeserializeFromStream<List<ScheduleDirect.Headends>>(responce);
+
+ if (root != null)
{
- foreach (ScheduleDirect.Lineup lineup in headend.lineups)
+ foreach (ScheduleDirect.Headends headend in root)
{
- lineups.Add(new NameIdPair
+ foreach (ScheduleDirect.Lineup lineup in headend.lineups)
{
- Name = string.IsNullOrWhiteSpace(lineup.name) ? lineup.lineup : lineup.name,
- Id = lineup.uri.Substring(18)
- });
+ lineups.Add(new NameIdPair
+ {
+ Name = string.IsNullOrWhiteSpace(lineup.name) ? lineup.lineup : lineup.name,
+ Id = lineup.uri.Substring(18)
+ });
+ }
}
}
- }
- else
- {
- _logger.Info("No lineups available");
+ else
+ {
+ _logger.Info("No lineups available");
+ }
}
}
}
@@ -671,13 +674,13 @@ namespace Emby.Server.Implementations.LiveTv.Listings
return await Post(options, false, providerInfo).ConfigureAwait(false);
}
- private async Task<Stream> Get(HttpRequestOptions options,
+ private async Task<HttpResponseInfo> Get(HttpRequestOptions options,
bool enableRetry,
ListingsProviderInfo providerInfo)
{
try
{
- return await _httpClient.Get(options).ConfigureAwait(false);
+ return await _httpClient.SendAsync(options, "GET").ConfigureAwait(false);
}
catch (HttpException ex)
{
@@ -797,11 +800,14 @@ namespace Emby.Server.Implementations.LiveTv.Listings
try
{
- using (var response = await Get(options, false, null).ConfigureAwait(false))
+ using (var httpResponse = await Get(options, false, null).ConfigureAwait(false))
{
- var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Lineups>(response);
+ using (var response = httpResponse.Content)
+ {
+ var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Lineups>(response);
- return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));
+ return root.lineups.Any(i => string.Equals(info.ListingsId, i.lineup, StringComparison.OrdinalIgnoreCase));
+ }
}
}
catch (HttpException ex)
@@ -879,53 +885,56 @@ namespace Emby.Server.Implementations.LiveTv.Listings
var list = new List<ChannelInfo>();
- using (var response = await Get(httpOptions, true, info).ConfigureAwait(false))
+ using (var httpResponse = await Get(httpOptions, true, info).ConfigureAwait(false))
{
- var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Channel>(response);
- _logger.Info("Found " + root.map.Count + " channels on the lineup on ScheduleDirect");
- _logger.Info("Mapping Stations to Channel");
-
- var allStations = root.stations ?? new List<ScheduleDirect.Station>();
-
- foreach (ScheduleDirect.Map map in root.map)
+ using (var response = httpResponse.Content)
{
- var channelNumber = GetChannelNumber(map);
-
- var station = allStations.FirstOrDefault(item => string.Equals(item.stationID, map.stationID, StringComparison.OrdinalIgnoreCase));
- if (station == null)
- {
- station = new ScheduleDirect.Station
- {
- stationID = map.stationID
- };
- }
+ var root = _jsonSerializer.DeserializeFromStream<ScheduleDirect.Channel>(response);
+ _logger.Info("Found " + root.map.Count + " channels on the lineup on ScheduleDirect");
+ _logger.Info("Mapping Stations to Channel");
- var name = channelNumber;
+ var allStations = root.stations ?? new List<ScheduleDirect.Station>();
- var channelInfo = new ChannelInfo
+ foreach (ScheduleDirect.Map map in root.map)
{
- Number = channelNumber,
- Name = name
- };
+ var channelNumber = GetChannelNumber(map);
- if (station != null)
- {
- if (!string.IsNullOrWhiteSpace(station.name))
+ var station = allStations.FirstOrDefault(item => string.Equals(item.stationID, map.stationID, StringComparison.OrdinalIgnoreCase));
+ if (station == null)
{
- channelInfo.Name = station.name;
+ station = new ScheduleDirect.Station
+ {
+ stationID = map.stationID
+ };
}
- channelInfo.Id = station.stationID;
- channelInfo.CallSign = station.callsign;
+ var name = channelNumber;
- if (station.logo != null)
+ var channelInfo = new ChannelInfo
{
- channelInfo.ImageUrl = station.logo.URL;
- channelInfo.HasImage = true;
+ Number = channelNumber,
+ Name = name
+ };
+
+ if (station != null)
+ {
+ if (!string.IsNullOrWhiteSpace(station.name))
+ {
+ channelInfo.Name = station.name;
+ }
+
+ channelInfo.Id = station.stationID;
+ channelInfo.CallSign = station.callsign;
+
+ if (station.logo != null)
+ {
+ channelInfo.ImageUrl = station.logo.URL;
+ channelInfo.HasImage = true;
+ }
}
- }
- list.Add(channelInfo);
+ list.Add(channelInfo);
+ }
}
}
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
index cfdaaed10..f8bb766d2 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHost.cs
@@ -86,16 +86,19 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
CancellationToken = cancellationToken,
BufferContent = false
};
- using (var stream = await _httpClient.Get(options).ConfigureAwait(false))
+ using (var response = await _httpClient.SendAsync(options, "GET").ConfigureAwait(false))
{
- var lineup = JsonSerializer.DeserializeFromStream<List<Channels>>(stream) ?? new List<Channels>();
-
- if (info.ImportFavoritesOnly)
+ using (var stream = response.Content)
{
- lineup = lineup.Where(i => i.Favorite).ToList();
- }
+ var lineup = JsonSerializer.DeserializeFromStream<List<Channels>>(stream) ?? new List<Channels>();
+
+ if (info.ImportFavoritesOnly)
+ {
+ lineup = lineup.Where(i => i.Favorite).ToList();
+ }
- return lineup.Where(i => !i.DRM).ToList();
+ return lineup.Where(i => !i.DRM).ToList();
+ }
}
}
@@ -143,26 +146,29 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
try
{
- using (var stream = await _httpClient.Get(new HttpRequestOptions()
+ using (var response = await _httpClient.SendAsync(new HttpRequestOptions()
{
Url = string.Format("{0}/discover.json", GetApiUrl(info, false)),
CancellationToken = cancellationToken,
TimeoutMs = Convert.ToInt32(TimeSpan.FromSeconds(5).TotalMilliseconds),
BufferContent = false
- }).ConfigureAwait(false))
+ }, "GET").ConfigureAwait(false))
{
- var response = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream);
-
- if (!string.IsNullOrWhiteSpace(info.Id))
+ using (var stream = response.Content)
{
- lock (_modelCache)
+ var discoverResponse = JsonSerializer.DeserializeFromStream<DiscoverResponse>(stream);
+
+ if (!string.IsNullOrWhiteSpace(info.Id))
{
- _modelCache[info.Id] = response;
+ lock (_modelCache)
+ {
+ _modelCache[info.Id] = discoverResponse;
+ }
}
- }
- return response;
+ return discoverResponse;
+ }
}
}
catch (HttpException ex)
diff --git a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs
index ad9c0d894..f3d89c6cc 100644
--- a/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs
+++ b/Emby.Server.Implementations/LiveTv/TunerHosts/HdHomerun/HdHomerunHttpStream.cs
@@ -92,14 +92,17 @@ namespace Emby.Server.Implementations.LiveTv.TunerHosts.HdHomerun
}, "GET").ConfigureAwait(false))
{
- Logger.Info("Opened HDHR stream from {0}", url);
+ using (var stream = response.Content)
+ {
+ Logger.Info("Opened HDHR stream from {0}", url);
- Logger.Info("Beginning multicastStream.CopyUntilCancelled");
+ Logger.Info("Beginning multicastStream.CopyUntilCancelled");
- FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
- using (var fileStream = FileSystem.GetFileStream(TempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
- {
- StreamHelper.CopyTo(response.Content, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
+ FileSystem.CreateDirectory(FileSystem.GetDirectoryName(TempFilePath));
+ using (var fileStream = FileSystem.GetFileStream(TempFilePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, FileOpenOptions.None))
+ {
+ StreamHelper.CopyTo(stream, fileStream, 81920, () => Resolve(openTaskCompletionSource), cancellationToken);
+ }
}
}
}