From 036dff3b1262deac6039de4b5a567dbd14381c09 Mon Sep 17 00:00:00 2001 From: Adam R Grey Date: Sun, 9 Apr 2023 18:00:28 -0400 Subject: [PATCH] podcast from attachment works --- Program.cs | 79 --------------- tasks/PodcastifyAttachment.cs | 176 ++++++++++++++++------------------ tasks/PodcastifyYT.cs | 2 +- tasks/Publish.cs | 2 +- 4 files changed, 83 insertions(+), 176 deletions(-) diff --git a/Program.cs b/Program.cs index 3a023f4..38dd06f 100644 --- a/Program.cs +++ b/Program.cs @@ -198,84 +198,5 @@ namespace ttrss_co_client return conf; } - private static async Task> podcastifyYT(string articleLink, string podcastName) - { - Console.WriteLine($" youtube-podcastifying {articleLink} ({podcastName})"); - try - { - var ytdl = new YoutubeDLSharp.YoutubeDL(); - ytdl.YoutubeDLPath = "yt-dlp"; - ytdl.FFmpegPath = "ffmpeg"; - ytdl.OutputFolder = $"./tmp/Podcasts/{podcastName}"; - ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s"; - var sw = new Stopwatch(); - sw.Start(); - var res = await ytdl.RunAudioDownload(articleLink); - sw.Stop(); - var outputStr = $"{(res.Success ? "Success" : "fail")} in {sw.Elapsed}"; - if (res.ErrorOutput != null && res.ErrorOutput.Length > 0) - { - outputStr += "\n" + string.Join('\n', res.ErrorOutput); - } - Console.WriteLine($" {(res.Success ? "Success" : "fail")} in {sw.Elapsed} - {res.Data}"); - if (res.Success && !res.Data.EndsWith(".mp3")) - { - Console.WriteLine(" must convert audio"); - sw.Reset(); - var outputFilename = res.Data.Substring(0, res.Data.LastIndexOf('.')) + ".mp3"; - sw.Start(); - var conversionProc = Process.Start("ffmpeg", $"-y -i \"{res.Data}\" \"{outputFilename}\""); - conversionProc.WaitForExit(); - sw.Stop(); - File.Delete(res.Data); - outputStr += $"\nconverted in {sw.Elapsed}"; - } - return new Tuple(res.Success, outputStr); - } - catch (Exception e) - { - Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}"); - return new Tuple(false, $"{e.ToString()}: {e.Message}.\n{e.StackTrace}"); - } - } - private static async Task> podcastifyAttachment(string attachmentLink, string podcastName, string episodeTitle) - { - Console.WriteLine($" attachment-podcastifying {attachmentLink} ({podcastName})"); - try - { - var extensionUpstream = attachmentLink.Substring(attachmentLink.LastIndexOf('.')); - var containingDirectory = $"./tmp/Podcasts/{podcastName}/"; - var outputFilename = $"{containingDirectory}{episodeTitle}{extensionUpstream}"; - if (!Directory.Exists(containingDirectory)) - { - Directory.CreateDirectory(containingDirectory); - } - var downloader = new HttpClient(); - var sw = new Stopwatch(); - sw.Start(); - File.WriteAllBytes(outputFilename, await (await downloader.GetAsync(attachmentLink)).Content.ReadAsByteArrayAsync()); - sw.Stop(); - var outputStr = $"{(File.Exists(outputFilename) ? "Success" : "fail")} in {sw.Elapsed}"; - Console.WriteLine($" {outputStr} - {outputFilename}"); - if (File.Exists(outputFilename) && extensionUpstream != ".mp3") - { - Console.WriteLine(" must convert audio"); - sw.Reset(); - var targetFilename = outputFilename.Substring(0, outputFilename.LastIndexOf('.')) + ".mp3"; - sw.Start(); - var conversionProc = Process.Start("ffmpeg", $"-y -i \"{outputFilename}\" \"{targetFilename}\""); - conversionProc.WaitForExit(); - sw.Stop(); - File.Delete(outputFilename); - outputStr += $"\nconverted in {sw.Elapsed}"; - } - return new Tuple(true, outputStr); - } - catch (Exception e) - { - Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}"); - return new Tuple(false, $"{e.ToString()}: {e.Message}.\n{e.StackTrace}"); - } - } } } \ No newline at end of file diff --git a/tasks/PodcastifyAttachment.cs b/tasks/PodcastifyAttachment.cs index 6224d54..0a07d11 100644 --- a/tasks/PodcastifyAttachment.cs +++ b/tasks/PodcastifyAttachment.cs @@ -1,102 +1,88 @@ -// using System.Diagnostics; -// using ttrss_co_client.ttrss; -// using ttrss_co_client.ttrss.datastructures; +using System.Diagnostics; +using ttrss_co_client.ttrss; +using ttrss_co_client.ttrss.datastructures; -// namespace ttrss_co_client.tasks -// { -// ///download directly from an RSS attachment -// public class PodcastifyAttachment : Phase1Task -// { -// public override async Task ActOn(Headline headline, IEnumerable