Compare commits

..

No commits in common. "036dff3b1262deac6039de4b5a567dbd14381c09" and "3fcc5f376df6a4693cd3b88c063aedd58e5d8813" have entirely different histories.

5 changed files with 268 additions and 168 deletions

View File

@ -198,5 +198,84 @@ namespace ttrss_co_client
return conf;
}
private static async Task<Tuple<bool, string>> 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<bool, string>(res.Success, outputStr);
}
catch (Exception e)
{
Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
return new Tuple<bool, string>(false, $"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
}
}
private static async Task<Tuple<bool, string>> 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<bool, string>(true, outputStr);
}
catch (Exception e)
{
Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
return new Tuple<bool, string>(false, $"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
}
}
}
}

View File

@ -1,88 +1,102 @@
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
{
///<summary>podcast, with attachment that is podcast</summary>
public class PodcastifyAttachment : Phase1Task
{
public override string TaskName => "podcastifyAttachment";
public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
{
Console.WriteLine($" podcast-is-attachment: {headline.link.ToString()}");
var myGuid = Guid.NewGuid().ToString();
var workingFolder = $"{Conf.WorkingDirectory}/{myGuid}";
var sw = new Stopwatch();
if(!Path.Exists(workingFolder))
{
Directory.CreateDirectory(workingFolder);
}
// namespace ttrss_co_client.tasks
// {
// ///<summary>download directly from an RSS attachment</summary>
// public class PodcastifyAttachment : Phase1Task
// {
// public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
// {
try
{
var attachmentLink = headline.attachments.Select(a => a.content_url)?.FirstOrDefault().ToString();
var extensionUpstream = attachmentLink.Substring(attachmentLink.LastIndexOf('.'));
var downloadPath = Path.Combine(workingFolder, headline.title) + extensionUpstream;
var downloader = new HttpClient();
sw.Start();
File.WriteAllBytes(downloadPath, await (await downloader.GetAsync(attachmentLink)).Content.ReadAsByteArrayAsync());
sw.Stop();
var outputStr = $"{(File.Exists(downloadPath) ? "Success" : "fail")} in {sw.Elapsed}";
Console.WriteLine($" {attachmentLink}\n{outputStr}");
await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
Console.WriteLine($" {headline.title}: download trigger label removed");
// // case "podcastifyAttachment":
// // nameLabel = labelsWRTArticle.FirstOrDefault(l => l.caption?.StartsWith(conf.PodcastTitlePrefix) == true && l.@checked);
// // podcastName = nameLabel?.caption.Substring(conf.PodcastTitlePrefix.Length)
// // ?? hl.feed_title;
// // var attachmentLink = hl.attachments.Select(a => a.content_url)?.FirstOrDefault();
// // var ATTpodcastifyResult = await podcastifyAttachment(attachmentLink.ToString(), podcastName, hl.title);
// // await ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToString("o")}] - {ATTpodcastifyResult.Item2}", hl.id);
// // if (ATTpodcastifyResult.Item1 == true)
// // {
// // Console.WriteLine($" {hl.title} -> podcastify (att) success, removing labels");
// // await ttrssClient.SetArticleLabel(
// // labelsWRTArticle.First(l => l.caption == action.triggerlabelCaption).id,
// // false,
// // hl.id);
// // if (nameLabel != null)
// // {
// // await ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id);
// // }
// // }
// // else
// // {
// // Console.WriteLine($" {hl.title} -> podcastify (att) failed");
// // }
// // break;
var podcastTitle = headline.feed_title;
var titlingLabel = labelsWRTArticle.FirstOrDefault(l => l.@checked && l.caption?.ToLower().StartsWith(Conf.PodcastTitlePrefix) == true);
if(titlingLabel != null)
{
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
Console.WriteLine($" {headline.title}: podcast titling label removed");
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
}
Console.WriteLine($"article {headline.id} - podcastifying; {podcastTitle}");
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - podcastify attachment (dl): {outputStr}", headline.id);
if (!File.Exists(downloadPath))
{
return null;
}
else
{
Console.WriteLine($"{attachmentLink} downloaded.");
var toReturn = new WorkOrder()
{
articleId = headline.id,//<-- that way later tasks can update the note
Phase2TaskList = new Dictionary<int, string>(),
data = new Dictionary<string, string>(),
guid = Guid.Parse(myGuid)
};
toReturn.data["path"] = downloadPath;
toReturn.Phase2TaskList[1] = "filemovePublish";
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/{Path.GetFileName(downloadPath)}";
if(extensionUpstream != ".mp3")
{
Console.WriteLine($"{headline.title} needs conversion task.");
toReturn.Phase2TaskList[0] = "convert";
toReturn.data["conversion-target"] = downloadPath.Substring(0, downloadPath.LastIndexOf('.')) + ".mp3";
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/{Path.GetFileName(toReturn.data["conversion-target"])}";
}
// // Console.WriteLine($" youtube podcastify: {headline.link.ToString()}");
// // var myGuid = Guid.NewGuid();
// // var ytdl = new YoutubeDLSharp.YoutubeDL();
// // ytdl.YoutubeDLPath = "yt-dlp";
// // ytdl.FFmpegPath = "ffmpeg";
// // ytdl.OutputFolder = $"{Conf.WorkingDirectory}/{myGuid}";
// // ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
// // var sw = new Stopwatch();
// // try
// // {
// // sw.Start();
// // var res = await ytdl.RunVideoDownload(headline.link.ToString(), overrideOptions: new YoutubeDLSharp.Options.OptionSet() { });
// // sw.Stop();
return toReturn;
}
}
catch (Exception e)
{
Console.Error.WriteLine($"fatal error in podcast attachment DL for {headline.link}");
Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - fatal error {e.ToString()}: {e.Message}.\n{e.StackTrace}", headline.id);
return null;
}
}
}
}
// // var outputStr = $"download {(res.Success ? "success" : "fail")} in {sw.Elapsed}";
// // if (res.ErrorOutput != null && res.ErrorOutput.Length > 0)
// // {
// // outputStr += "\n" + string.Join('\n', res.ErrorOutput);
// // }
// // Console.WriteLine($" {headline.link} -> {res.Data}\n{outputStr}");
// // await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
// // Console.WriteLine($" {headline.title}: label removed");
// // if (!res.Success)
// // {
// // await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - standard dl failed; {string.Join('\n', res.ErrorOutput)}", hl.id);
// // return null;
// // }
// // else
// // {
// // var outputFilename = res.Data;
// // Console.WriteLine($"{headline.title} downloaded, shipping off to conversion. That task can determine if there's no work.");
// // var toReturn = new WorkOrder()
// // {
// // articleId = headline.id, //<-- that way adblocker, if I should want to suppress it, can be labelled on ttrss
// // nextTask = "convert",
// // data = new Dictionary<string, string>()
// // };
// // toReturn.data["path"] = outputFilename;
// // toReturn.data["target"] = outputFilename.Substring(0, res.Data.LastIndexOf('.')) + ".mp4";
// // return toReturn;
// // // sw.Reset();
// // // outputFilename =
// // // sw.Start();
// // // var conversionProc = Process.Start("ffmpeg", $"-y -i \"{res.Data}\" \"{outputFilename}\"");
// // // conversionProc.WaitForExit();
// // // sw.Stop();
// // // Console.WriteLine($" converted {res.Data} -> {outputFilename}");
// // // File.Delete(res.Data);
// // //outputStr += $"\nconverted in {sw.Elapsed}";
// // }
// // }
// // catch (Exception e)
// // {
// // Console.Error.WriteLine($"fatal error in standard DL for {headline.link}");
// // Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
// // await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - fatal error {e.ToString()}: {e.Message}.\n{e.StackTrace}", hl.id);
// // return null;
// // }
// }
// }
// }

View File

@ -1,91 +1,99 @@
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
{
///<summary>download from YT</summary>
public class PodcastifyYT : Phase1Task
{
public override string TaskName => "podcastifyYT";
public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
{
Console.WriteLine($" YT podcastify: {headline.link.ToString()}");
var myGuid = Guid.NewGuid().ToString();
var ytdl = new YoutubeDLSharp.YoutubeDL();
ytdl.YoutubeDLPath = "yt-dlp";
ytdl.FFmpegPath = "ffmpeg";
ytdl.OutputFolder = $"{Conf.WorkingDirectory}/{myGuid}";
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
var sw = new Stopwatch();
if(!Path.Exists(ytdl.OutputFolder))
{
Directory.CreateDirectory(ytdl.OutputFolder);
}
// namespace ttrss_co_client.tasks
// {
// ///<summary>download from YT, to be ripped into a podcast</summary>
// public class PodcastifyYT : Phase1Task
// {
// public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
// {
try
{
sw.Start();
var res = await ytdl.RunVideoDownload(headline.link.ToString());
sw.Stop();
// // case "podcastifyYT":
// // nameLabel = labelsWRTArticle.FirstOrDefault(l => l.caption?.StartsWith(conf.PodcastTitlePrefix) == true && l.@checked);
// // podcastName = nameLabel?.caption.Substring(conf.PodcastTitlePrefix.Length)
// // ?? hl.feed_title;
// // var YTpodcastifyResult = await podcastifyYT(hl.link.ToString(), podcastName);
// // await ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToString("o")}] - {YTpodcastifyResult.Item2}", hl.id);
// // if (YTpodcastifyResult.Item1 == true)
// // {
// // Console.WriteLine($" {hl.title} -> podcastify (YT) success, removing labels");
// // await ttrssClient.SetArticleLabel(
// // labelsWRTArticle.First(l => l.caption == action.triggerlabelCaption).id,
// // false,
// // hl.id);
// // if (nameLabel != null)
// // {
// // await ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id);
// // }
// // }
// // else
// // {
// // Console.WriteLine($" {hl.title} -> podcastify (YT) failed");
// // }
// // break;
var outputStr = $"download {(res.Success ? "success" : "fail")} in {sw.Elapsed}";
if (res.ErrorOutput != null && res.ErrorOutput.Length > 0)
{
outputStr += "\n" + string.Join('\n', res.ErrorOutput);
}
Console.WriteLine($" {headline.link} -> {res.Data}\n{outputStr}");
await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
Console.WriteLine($" {headline.title}: download trigger label removed");
// // Console.WriteLine($" youtube podcastify: {headline.link.ToString()}");
// // var myGuid = Guid.NewGuid();
// // var ytdl = new YoutubeDLSharp.YoutubeDL();
// // ytdl.YoutubeDLPath = "yt-dlp";
// // ytdl.FFmpegPath = "ffmpeg";
// // ytdl.OutputFolder = $"{Conf.WorkingDirectory}/{myGuid}";
// // ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
// // var sw = new Stopwatch();
var podcastTitle = headline.feed_title;
var titlingLabel = labelsWRTArticle.FirstOrDefault(l => l.@checked && l.caption?.ToLower().StartsWith(Conf.PodcastTitlePrefix) == true);
if(titlingLabel != null)
{
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
}
Console.WriteLine($"article {headline.id} - podcastifying; {podcastTitle}");
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - YT podcastify (dl) {(res.Success ? "success" : "failure")}; {string.Join('\n', res.ErrorOutput)}", headline.id);
if (!res.Success)
{
return null;
}
else
{
var outputFilename = res.Data;
Console.WriteLine($"{headline.title} downloaded.");
// // try
// // {
// // sw.Start();
// // var res = await ytdl.RunVideoDownload(headline.link.ToString(), overrideOptions: new YoutubeDLSharp.Options.OptionSet() { });
// // sw.Stop();
var toReturn = new WorkOrder()
{
articleId = headline.id,//<-- that way later tasks can update the note
Phase2TaskList = new Dictionary<int, string>(),
data = new Dictionary<string, string>(),
guid = Guid.Parse(myGuid)
};
toReturn.data["path"] = outputFilename;
if(!outputFilename.EndsWith(".mp3"))
{
Console.WriteLine($"{headline.title} needs conversion task.");
toReturn.Phase2TaskList[0] = "convert";
toReturn.data["conversion-target"] = outputFilename.Substring(0, res.Data.LastIndexOf('.')) + ".mp3";
}
// // var outputStr = $"download {(res.Success ? "success" : "fail")} in {sw.Elapsed}";
// // if (res.ErrorOutput != null && res.ErrorOutput.Length > 0)
// // {
// // outputStr += "\n" + string.Join('\n', res.ErrorOutput);
// // }
// // Console.WriteLine($" {headline.link} -> {res.Data}\n{outputStr}");
// // await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
// // Console.WriteLine($" {headline.title}: label removed");
// // if (!res.Success)
// // {
// // await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - standard dl failed; {string.Join('\n', res.ErrorOutput)}", hl.id);
// // return null;
// // }
// // else
// // {
// // var outputFilename = res.Data;
// // Console.WriteLine($"{headline.title} downloaded, shipping off to conversion. That task can determine if there's no work.");
// // var toReturn = new WorkOrder()
// // {
// // articleId = headline.id, //<-- that way adblocker, if I should want to suppress it, can be labelled on ttrss
// // nextTask = "convert",
// // data = new Dictionary<string, string>()
// // };
// // toReturn.data["path"] = outputFilename;
// // toReturn.data["target"] = outputFilename.Substring(0, res.Data.LastIndexOf('.')) + ".mp4";
// // return toReturn;
// // // sw.Reset();
// // // outputFilename =
// // // sw.Start();
// // // var conversionProc = Process.Start("ffmpeg", $"-y -i \"{res.Data}\" \"{outputFilename}\"");
// // // conversionProc.WaitForExit();
// // // sw.Stop();
// // // Console.WriteLine($" converted {res.Data} -> {outputFilename}");
// // // File.Delete(res.Data);
// // //outputStr += $"\nconverted in {sw.Elapsed}";
// // }
// // }
// // catch (Exception e)
// // {
// // Console.Error.WriteLine($"fatal error in standard DL for {headline.link}");
// // Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
// // await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - fatal error {e.ToString()}: {e.Message}.\n{e.StackTrace}", hl.id);
// // return null;
// // }
toReturn.Phase2TaskList[1] = "sponsorblock";
toReturn.Phase2TaskList[2] = "filemovePublish";
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/{Path.GetFileName(toReturn.data["conversion-target"])}";
return toReturn;
}
}
catch (Exception e)
{
Console.Error.WriteLine($"fatal error in yt podcastify DL for {headline.link}");
Console.Error.WriteLine($"{e.ToString()}: {e.Message}.\n{e.StackTrace}");
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - fatal error {e.ToString()}: {e.Message}.\n{e.StackTrace}", headline.id);
return null;
}
}
}
}
// }
// }
// }

View File

@ -18,7 +18,7 @@ namespace ttrss_co_client.tasks
}
File.Move(workOrder.data["path"], workOrder.data["publish-target"], true);
var article = (await TtrssClient.GetArticles(workOrder.articleId))?.FirstOrDefault();
await TtrssClient.UpdateArticleNote($"{article.note}\n[{DateTime.Now.ToString("o")}] - copied", article.id);
await TtrssClient.UpdateArticleNote($"{article.note}\n[{DateTime.Now.ToShortDateString()}] - copied", article.id);
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.Done, workOrder);
}
}

View File

@ -78,7 +78,6 @@ namespace ttrss_co_client.tasks
}
}
contentSegments.Add(new Tuple<double, double>(previousEdge, segments.First().videoDuration));
contentSegments = contentSegments.Except(contentSegments.Where(tup => tup.Item2 - tup.Item1 < 0.5)).ToList();
#region ffmpeg via intermediate files
var intermediateCount = 0;