From 3d61948ccf2d0ea8919b19ad4350df01ee10fdeb Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Wed, 5 Apr 2023 21:05:58 -0400 Subject: [PATCH] handle some common tripping blocks --- Program.cs | 58 +++++++++++++++++++++++++++++------------------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/Program.cs b/Program.cs index 4045275..de4792a 100644 --- a/Program.cs +++ b/Program.cs @@ -9,13 +9,14 @@ namespace ttrss_co_client static async Task Main(string[] args) { var conf = Configure(); + Console.WriteLine($"{DateTime.Now.ToLongDateString()}"); + var ttrssClient = new ttrss.ApiClient(conf.BaseURI); await ttrssClient.Login(conf.Username, conf.Password); var loggedin = await ttrssClient.IsLoggedIn(); Console.WriteLine($"logged in: {loggedin}"); - var miscTasks = new List(); var unreadFeeds = await ttrssClient.GetFeeds(cat_id: -3, unread_only: true); foreach (var uf in unreadFeeds) { @@ -42,15 +43,14 @@ namespace ttrss_co_client { case "dl": var stdDLResult = await standardDL(hl.link.ToString()); - miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {stdDLResult.Item2}", hl.id)); + await ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {stdDLResult.Item2}", hl.id); if (stdDLResult.Item1 == true) { Console.WriteLine($" {hl.title} -> dl success, removing label"); - miscTasks.Add( - ttrssClient.SetArticleLabel( - labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, - false, - hl.id)); + await ttrssClient.SetArticleLabel( + labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, + false, + hl.id); } else { @@ -62,18 +62,17 @@ namespace ttrss_co_client podcastName = nameLabel?.caption.Substring(conf.PodcastTitlePrefix.Length) ?? hl.feed_title; var YTpodcastifyResult = await podcastifyYT(hl.link.ToString(), podcastName); - miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {YTpodcastifyResult.Item2}", hl.id)); + await ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {YTpodcastifyResult.Item2}", hl.id); if (YTpodcastifyResult.Item1 == true) { Console.WriteLine($" {hl.title} -> podcastify (YT) success, removing labels"); - miscTasks.Add( - ttrssClient.SetArticleLabel( - labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, - false, - hl.id)); + await ttrssClient.SetArticleLabel( + labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, + false, + hl.id); if (nameLabel != null) { - miscTasks.Add(ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id)); + await ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id); } } else @@ -87,18 +86,17 @@ namespace ttrss_co_client ?? hl.feed_title; var attachmentLink = hl.attachments.Select(a => a.content_url)?.FirstOrDefault(); var ATTpodcastifyResult = await podcastifyAttachment(attachmentLink.ToString(), podcastName, hl.title); - miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {ATTpodcastifyResult.Item2}", hl.id)); + await ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {ATTpodcastifyResult.Item2}", hl.id); if (ATTpodcastifyResult.Item1 == true) { Console.WriteLine($" {hl.title} -> podcastify (att) success, removing labels"); - miscTasks.Add( - ttrssClient.SetArticleLabel( - labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, - false, - hl.id)); + await ttrssClient.SetArticleLabel( + labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, + false, + hl.id); if (nameLabel != null) { - miscTasks.Add(ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id)); + await ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id); } } else @@ -110,15 +108,14 @@ namespace ttrss_co_client noteString += $"[{DateTime.Now.ToLongTimeString()}] - feed configured but action not recognized"; break; } - miscTasks.Add(ttrssClient.UpdateArticleNote(noteString, hl.id)); + await ttrssClient.UpdateArticleNote(noteString, hl.id); } } } } - Console.WriteLine($"awaiting remaining download tasks"); - Task.WaitAll(miscTasks.ToArray()); + Console.WriteLine($"logging out"); await ttrssClient.Logout(); Console.WriteLine($"done, moving files from temporary location"); @@ -132,7 +129,14 @@ namespace ttrss_co_client { Directory.CreateDirectory(Path.GetDirectoryName(moveTarget)); } - File.Move(f, moveTarget); + if(File.Exists(moveTarget)) + { + Console.WriteLine("file already exists, abandoning"); + } + else + { + File.Move(f, moveTarget); + } } } Console.WriteLine($"done for real"); @@ -215,7 +219,7 @@ namespace ttrss_co_client var ytdl = new YoutubeDLSharp.YoutubeDL(); ytdl.YoutubeDLPath = "yt-dlp"; ytdl.FFmpegPath = "ffmpeg"; - ytdl.OutputFolder = $"./tmp/podcasts/{podcastName}"; + ytdl.OutputFolder = $"./tmp/Podcasts/{podcastName}"; ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s"; var sw = new Stopwatch(); sw.Start(); @@ -253,7 +257,7 @@ namespace ttrss_co_client try { var extensionUpstream = attachmentLink.Substring(attachmentLink.LastIndexOf('.')); - var containingDirectory = $"./tmp/podcasts/{podcastName}/"; + var containingDirectory = $"./tmp/Podcasts/{podcastName}/"; var outputFilename = $"{containingDirectory}{episodeTitle}{extensionUpstream}"; if(!Directory.Exists(containingDirectory)) {