102 lines
6.3 KiB
C#
102 lines
6.3 KiB
C#
|
// using System.Diagnostics;
|
||
|
// using ttrss_co_client.ttrss;
|
||
|
// using ttrss_co_client.ttrss.datastructures;
|
||
|
|
||
|
// 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)
|
||
|
// {
|
||
|
|
||
|
|
||
|
// // 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.ToLongTimeString()}] - {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;
|
||
|
|
||
|
|
||
|
// // 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();
|
||
|
|
||
|
// // 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.ToLongTimeString()}] - 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.ToLongTimeString()}] - fatal error {e.ToString()}: {e.Message}.\n{e.StackTrace}", hl.id);
|
||
|
// // return null;
|
||
|
// // }
|
||
|
|
||
|
// }
|
||
|
// }
|
||
|
// }
|