ttrss-co-pilot/tasks/PodcastifyYT.cs

59 lines
2.3 KiB
C#

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 toReturn = new WorkOrder()
{
articleId = headline.id,
Phase2TaskList = new Dictionary<int, string>(),
data = new Dictionary<string, string>(),
guid = Guid.Parse(myGuid)
};
var podcastTitle = headline.feed_title;
var titlingLabel = labelsWRTArticle.FirstOrDefault(l => l.@checked && l.caption?.ToLower().StartsWith(Conf.PodcastTitlePrefix) == true);
if(titlingLabel != null)
{
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
}
Console.WriteLine($"article {headline.id} - yt podcastifying; {podcastTitle}");
toReturn.Phase2TaskList[0] = "yt-dlp";
toReturn.data["ytdlp-link"] = headline.link.ToString();
toReturn.Phase2TaskList[1] = "convert";
toReturn.data["conversion-target"] = ".mp3";
if(headline.link.Host.EndsWith("youtube.com"))
{
toReturn.Phase2TaskList[2] = "sponsorblock";
}
toReturn.Phase2TaskList[3] = "filemovePublish";
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/";
toReturn.Phase2TaskList[4] = "markread";
toReturn.Phase2TaskList[5] = "chatmessage";
toReturn.data["chatmessage"] = "new podcast (via YT) from ";
await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
Console.WriteLine($" {headline.title}: download trigger label removed");
return toReturn;
}
}
}