Fix code quality scanning issue #146

Merged
Kevinjil merged 2 commits from fix/code-quality into master 2025-01-05 12:45:42 +00:00
4 changed files with 18 additions and 27 deletions
Showing only changes of commit 7a8404cb68 - Show all commits

View File

@@ -203,12 +203,8 @@ public class XtreamController : ControllerBase
[HttpGet("LiveTv")]
public async Task<ActionResult<IEnumerable<StreamInfo>>> GetLiveTvChannels(CancellationToken cancellationToken)
{
List<ChannelResponse> channels = new List<ChannelResponse>();
await foreach (StreamInfo stream in Plugin.Instance.StreamService.GetLiveStreams(cancellationToken))
{
channels.Add(CreateChannelResponse(stream));
}
IEnumerable<StreamInfo> streams = await Plugin.Instance.StreamService.GetLiveStreams(cancellationToken).ConfigureAwait(false);
var channels = streams.Select(CreateChannelResponse).ToList();
return Ok(channels);
}
}

View File

@@ -129,7 +129,7 @@ public class CatchupChannel : IChannel
{
Plugin plugin = Plugin.Instance;
List<ChannelItemInfo> items = new List<ChannelItemInfo>();
await foreach (StreamInfo channel in plugin.StreamService.GetLiveStreamsWithOverrides(cancellationToken))
foreach (StreamInfo channel in await plugin.StreamService.GetLiveStreamsWithOverrides(cancellationToken).ConfigureAwait(false))
{
if (!channel.TvArchive)
{

View File

@@ -68,7 +68,7 @@ public class LiveTvService : ILiveTvService, ISupportsDirectStreamProvider
{
Plugin plugin = Plugin.Instance;
List<ChannelInfo> items = new List<ChannelInfo>();
await foreach (StreamInfo channel in plugin.StreamService.GetLiveStreamsWithOverrides(cancellationToken))
foreach (StreamInfo channel in await plugin.StreamService.GetLiveStreamsWithOverrides(cancellationToken).ConfigureAwait(false))
{
ParsedName parsed = StreamService.ParseName(channel.Name);
items.Add(new ChannelInfo()

View File

@@ -169,24 +169,18 @@ public class StreamService
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>IAsyncEnumerable{StreamInfo}.</returns>
public async IAsyncEnumerable<StreamInfo> GetLiveStreams([EnumeratorCancellation] CancellationToken cancellationToken)
public async Task<IEnumerable<StreamInfo>> GetLiveStreams(CancellationToken cancellationToken)
{
PluginConfiguration config = plugin.Configuration;
using (XtreamClient client = new XtreamClient())
{
foreach (var entry in config.LiveTv)
{
int categoryId = entry.Key;
cancellationToken.ThrowIfCancellationRequested();
using XtreamClient client = new XtreamClient();
IEnumerable<StreamInfo> channels = await client.GetLiveStreamsByCategoryAsync(plugin.Creds, categoryId, cancellationToken).ConfigureAwait(false);
foreach (StreamInfo channel in channels.Where((StreamInfo channel) => IsConfigured(config.LiveTv, categoryId, channel.StreamId)))
{
// If the set is empty, include all channels for the category.
yield return channel;
}
}
}
IEnumerable<Task<IEnumerable<StreamInfo>>> tasks = config.LiveTv.Select(async (entry) =>
{
int categoryId = entry.Key;
var streams = await client.GetLiveStreamsByCategoryAsync(plugin.Creds, categoryId, cancellationToken).ConfigureAwait(false);
return streams.Where((StreamInfo channel) => IsConfigured(config.LiveTv, categoryId, channel.StreamId));
});
return (await Task.WhenAll(tasks).ConfigureAwait(false)).SelectMany(i => i);
}
/// <summary>
@@ -194,10 +188,11 @@ public class StreamService
/// </summary>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>IAsyncEnumerable{StreamInfo}.</returns>
public async IAsyncEnumerable<StreamInfo> GetLiveStreamsWithOverrides([EnumeratorCancellation] CancellationToken cancellationToken)
public async Task<IEnumerable<StreamInfo>> GetLiveStreamsWithOverrides(CancellationToken cancellationToken)
{
PluginConfiguration config = Plugin.Instance.Configuration;
await foreach (StreamInfo stream in GetLiveStreams(cancellationToken))
IEnumerable<StreamInfo> streams = await GetLiveStreams(cancellationToken).ConfigureAwait(false);
return streams.Select((StreamInfo stream) =>
{
if (config.LiveTvOverrides.TryGetValue(stream.StreamId, out ChannelOverrides? overrides))
{
@@ -206,8 +201,8 @@ public class StreamService
stream.StreamIcon = overrides.LogoUrl ?? stream.StreamIcon;
}
yield return stream;
}
return stream;
});
}
/// <summary>