From 9628a7b8b952df3cddbfa8e5e51f365db5fc7ee3 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Thu, 6 Apr 2023 16:01:26 -0400 Subject: [PATCH] oh wait, i didn't believe it when it said it was broken --- Program.cs | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/Program.cs b/Program.cs index c98c21f..55211b2 100644 --- a/Program.cs +++ b/Program.cs @@ -31,7 +31,7 @@ namespace ttrss_co_client if (actionsForFeed != null && actionsForFeed.Any()) { var sponsorCheck = await SponsorCheck(hl); - if(!sponsorCheck.Item1) + if (!sponsorCheck.Item1) { await ttrssClient.UpdateArticleNote($"{hl.note}\n[{DateTime.Now.ToLongTimeString()}] sponsorcheck: {sponsorCheck.Item2}", hl.id); continue; @@ -135,7 +135,7 @@ namespace ttrss_co_client { Directory.CreateDirectory(Path.GetDirectoryName(moveTarget)); } - if(File.Exists(moveTarget)) + if (File.Exists(moveTarget)) { Console.WriteLine("file already exists, abandoning"); } @@ -265,7 +265,7 @@ namespace ttrss_co_client var extensionUpstream = attachmentLink.Substring(attachmentLink.LastIndexOf('.')); var containingDirectory = $"./tmp/Podcasts/{podcastName}/"; var outputFilename = $"{containingDirectory}{episodeTitle}{extensionUpstream}"; - if(!Directory.Exists(containingDirectory)) + if (!Directory.Exists(containingDirectory)) { Directory.CreateDirectory(containingDirectory); } @@ -298,21 +298,21 @@ namespace ttrss_co_client } private static async Task> SponsorCheck(ttrss.datastructures.Headline hl) { - if(!hl.link.Host.EndsWith("youtube.com")) + if (!hl.link.Host.EndsWith("youtube.com")) { return new Tuple(true, "sponsorblock, sadly, only exists for youtube"); } var match = Regex.Match(hl.link.Query, "v=([^&]+)(&|$)"); var videoId = match.Groups?[1].Value; var c = new HttpClient(); - + var sponsorblockcheck = await c.GetAsync($"https://sponsor.ajay.app/api/skipSegments?videoID={videoId}&category=sponsor&category=selfpromo&category=interaciton&category=intro&category=outro&category=preview"); - if(sponsorblockcheck.StatusCode == System.Net.HttpStatusCode.NotFound) + if (sponsorblockcheck.StatusCode == System.Net.HttpStatusCode.NotFound) { Console.WriteLine($"sponsorblock reports that {videoId} has no entries (yet)"); var updateTimestamp = new DateTime(1970, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc); updateTimestamp = updateTimestamp.AddSeconds(hl.updated).ToLocalTime(); - if(DateTime.Now - updateTimestamp > TimeSpan.FromMinutes(45)) + if (DateTime.Now - updateTimestamp > TimeSpan.FromMinutes(45)) { return new Tuple(true, $"updated {updateTimestamp} (more than 45 minutes ago), going to give up waiting for sponsorblock"); } @@ -326,7 +326,7 @@ namespace ttrss_co_client try { var segments = JsonConvert.DeserializeObject>(await sponsorblockcheck.Content.ReadAsStringAsync()); - if(segments.Count() > 1) + if (segments.Count() > 1) { return new Tuple(true, $"{segments.Count()} segments"); } @@ -335,6 +335,10 @@ namespace ttrss_co_client return new Tuple(false, $"no segments"); } } + catch (Exception e) + { + return new Tuple(false, $"{e.ToString()} - {e.Message}"); + } } } }