fixed youtube stream notifications incase invalid channel was provided

This commit is contained in:
Toastie 2025-03-20 22:44:39 +13:00
parent 4a5bcd46e6
commit 9b8d00d184
Signed by: toastie_t0ast
GPG key ID: 0861BE54AD481DC7
2 changed files with 59 additions and 56 deletions
src/EllieBot/Modules/Searches/_common/StreamNotifications

View file

@ -63,20 +63,19 @@ public class NotifChecker
.ToDictionary(x => x.Key.Name, x => x.Value));
var newStreamData = await oldStreamDataDict
.Select(x =>
.Select(async x =>
{
// get all stream data for the streams of this type
if (_streamProviders.TryGetValue(x.Key,
out var provider))
{
return provider.GetStreamDataAsync(x.Value
return await provider.GetStreamDataAsync(x.Value
.Select(entry => entry.Key)
.ToList());
}
// this means there's no provider for this stream data, (and there was before?)
return Task.FromResult<IReadOnlyCollection<StreamData>>(
new List<StreamData>());
return [];
})
.WhenAll();

View file

@ -1,12 +1,7 @@
using System.Net;
using EllieBot.Db.Models;
using EllieBot.Services;
using EllieBot.Db.Models;
using System.Text.RegularExpressions;
using System.Net.Http.Json;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Xml.Linq;
using AngleSharp.Browser;
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>
/// <returns><see cref="StreamData"/> of the channel. Null if none found</returns>
public override async Task<StreamData?> GetStreamDataAsync(string channelId)
{
try
{
var instances = _scs.Data.InvidiousInstances;
@ -164,6 +161,13 @@ public sealed partial class YouTubeProvider : Provider
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>
/// Gets stream data of all specified YouTube channels