report sponsor check status

This commit is contained in:
Adam R Grey 2023-04-06 14:17:31 -04:00
parent dbb342302e
commit 2baaa4b1ef

View File

@ -30,15 +30,16 @@ namespace ttrss_co_client
labelsWRTFeed.Where(l => l.@checked).Select(l => l.caption).Contains(fa.triggerlabelCaption))?.ToList(); labelsWRTFeed.Where(l => l.@checked).Select(l => l.caption).Contains(fa.triggerlabelCaption))?.ToList();
if (actionsForFeed != null && actionsForFeed.Any()) if (actionsForFeed != null && actionsForFeed.Any())
{ {
if(!(await SponsorCheck(hl))) var sponsorCheck = await SponsorCheck(hl);
if(!sponsorCheck.Item1)
{ {
await ttrssClient.UpdateArticleNote($"{hl.note}\n[{DateTime.Now.ToLongTimeString()}] waiting for sponsorblock", hl.id); await ttrssClient.UpdateArticleNote($"{hl.note}\n[{DateTime.Now.ToLongTimeString()}] sponsorcheck: {sponsorCheck.Item2}", hl.id);
continue; continue;
} }
foreach (var action in actionsForFeed) foreach (var action in actionsForFeed)
{ {
Console.WriteLine($" {hl.title} -> action: {action.command}"); Console.WriteLine($" {hl.title} -> action: {action.command}");
var noteString = hl.note; var noteString = $"{hl.note}\n[{DateTime.Now.ToLongTimeString()}] sponsorcheck: {sponsorCheck.Item2}";
ttrss.datastructures.Label nameLabel; ttrss.datastructures.Label nameLabel;
string podcastName; string podcastName;
if (!string.IsNullOrWhiteSpace(noteString)) if (!string.IsNullOrWhiteSpace(noteString))
@ -295,12 +296,11 @@ namespace ttrss_co_client
return new Tuple<bool, string>(false, $"{e.ToString()}: {e.Message}.\n{e.StackTrace}"); return new Tuple<bool, string>(false, $"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
} }
} }
public static async Task<bool> SponsorCheck(ttrss.datastructures.Headline hl) private static async Task<Tuple<bool, string>> SponsorCheck(ttrss.datastructures.Headline hl)
{ {
if(!hl.link.Host.EndsWith("youtube.com")) if(!hl.link.Host.EndsWith("youtube.com"))
{ {
//sponsorblock, sadly, only exists for youtube return new Tuple<bool, string>(true, "sponsorblock, sadly, only exists for youtube");
return true;
} }
var match = Regex.Match(hl.link.Query, "v=([^&]+)(&|$)"); var match = Regex.Match(hl.link.Query, "v=([^&]+)(&|$)");
var videoId = match.Groups?[1].Value; var videoId = match.Groups?[1].Value;
@ -314,18 +314,16 @@ namespace ttrss_co_client
updateTimestamp = updateTimestamp.AddSeconds(hl.updated).ToLocalTime(); updateTimestamp = updateTimestamp.AddSeconds(hl.updated).ToLocalTime();
if(DateTime.Now - updateTimestamp > TimeSpan.FromMinutes(45)) if(DateTime.Now - updateTimestamp > TimeSpan.FromMinutes(45))
{ {
Console.WriteLine($"updated {updateTimestamp} (more than 45 minutes ago), going to give up waiting for sponsorblock"); return new Tuple<bool, string>(true, $"updated {updateTimestamp} (more than 45 minutes ago), going to give up waiting for sponsorblock");
return true;
} }
else else
{ {
Console.WriteLine($"going to wait a bit for segments to show up."); return new Tuple<bool, string>(false, "none found, waiting");
return false;
} }
} }
else else
{ {
return true; return new Tuple<bool, string>(true, "status other than 404");
} }
} }
} }