fixed youtube stream notifications incase invalid channel was provided
This commit is contained in:
parent
4a5bcd46e6
commit
9b8d00d184
2 changed files with 59 additions and 56 deletions
src/EllieBot/Modules/Searches/_common/StreamNotifications
|
@ -63,20 +63,19 @@ public class NotifChecker
|
||||||
.ToDictionary(x => x.Key.Name, x => x.Value));
|
.ToDictionary(x => x.Key.Name, x => x.Value));
|
||||||
|
|
||||||
var newStreamData = await oldStreamDataDict
|
var newStreamData = await oldStreamDataDict
|
||||||
.Select(x =>
|
.Select(async x =>
|
||||||
{
|
{
|
||||||
// get all stream data for the streams of this type
|
// get all stream data for the streams of this type
|
||||||
if (_streamProviders.TryGetValue(x.Key,
|
if (_streamProviders.TryGetValue(x.Key,
|
||||||
out var provider))
|
out var provider))
|
||||||
{
|
{
|
||||||
return provider.GetStreamDataAsync(x.Value
|
return await provider.GetStreamDataAsync(x.Value
|
||||||
.Select(entry => entry.Key)
|
.Select(entry => entry.Key)
|
||||||
.ToList());
|
.ToList());
|
||||||
}
|
}
|
||||||
|
|
||||||
// this means there's no provider for this stream data, (and there was before?)
|
// this means there's no provider for this stream data, (and there was before?)
|
||||||
return Task.FromResult<IReadOnlyCollection<StreamData>>(
|
return [];
|
||||||
new List<StreamData>());
|
|
||||||
})
|
})
|
||||||
.WhenAll();
|
.WhenAll();
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,7 @@
|
||||||
using System.Net;
|
using EllieBot.Db.Models;
|
||||||
using EllieBot.Db.Models;
|
|
||||||
using EllieBot.Services;
|
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Net.Http.Json;
|
using System.Net.Http.Json;
|
||||||
using System.Text.Json;
|
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
using System.Xml.Linq;
|
|
||||||
using AngleSharp.Browser;
|
|
||||||
|
|
||||||
namespace EllieBot.Modules.Searches.Common.StreamNotifications.Providers;
|
namespace EllieBot.Modules.Searches.Common.StreamNotifications.Providers;
|
||||||
|
|
||||||
|
@ -112,6 +107,8 @@ public sealed partial class YouTubeProvider : Provider
|
||||||
/// <param name="channelId">Channel ID or name</param>
|
/// <param name="channelId">Channel ID or name</param>
|
||||||
/// <returns><see cref="StreamData"/> of the channel. Null if none found</returns>
|
/// <returns><see cref="StreamData"/> of the channel. Null if none found</returns>
|
||||||
public override async Task<StreamData?> GetStreamDataAsync(string channelId)
|
public override async Task<StreamData?> GetStreamDataAsync(string channelId)
|
||||||
|
{
|
||||||
|
try
|
||||||
{
|
{
|
||||||
var instances = _scs.Data.InvidiousInstances;
|
var instances = _scs.Data.InvidiousInstances;
|
||||||
|
|
||||||
|
@ -164,6 +161,13 @@ public sealed partial class YouTubeProvider : Provider
|
||||||
UniqueName = vid.AuthorId,
|
UniqueName = vid.AuthorId,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Warning(ex, "Unable to get stream data for a youtube channel {ChannelId}", channelId);
|
||||||
|
_failingStreams.TryAdd(channelId, DateTime.UtcNow);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets stream data of all specified YouTube channels
|
/// Gets stream data of all specified YouTube channels
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue