Compare commits
No commits in common. "3d84beb640ede627cea4f94143773f4e92a8d2c4" and "036dff3b1262deac6039de4b5a567dbd14381c09" have entirely different histories.
3d84beb640
...
036dff3b12
@ -10,12 +10,6 @@ namespace ttrss_co_client.tasks
|
|||||||
public override string TaskName => "convert";
|
public override string TaskName => "convert";
|
||||||
public override async Task<Tuple<TaskStatus, WorkOrder>> ActOn(WorkOrder wo)
|
public override async Task<Tuple<TaskStatus, WorkOrder>> ActOn(WorkOrder wo)
|
||||||
{
|
{
|
||||||
var conversionFilenameTarget = wo.data["path"].Substring(0, wo.data["path"].LastIndexOf('.')) + wo.data["conversion-target"];
|
|
||||||
if(conversionFilenameTarget == wo.data["path"])
|
|
||||||
{
|
|
||||||
Console.WriteLine("no conversion needed");
|
|
||||||
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.ContinueNow, wo);
|
|
||||||
}
|
|
||||||
var article = (await TtrssClient.GetArticles(wo.articleId))?.FirstOrDefault();
|
var article = (await TtrssClient.GetArticles(wo.articleId))?.FirstOrDefault();
|
||||||
if(article == null){
|
if(article == null){
|
||||||
Console.Error.WriteLine($"article {wo.articleId} couldn't be retrieved!");
|
Console.Error.WriteLine($"article {wo.articleId} couldn't be retrieved!");
|
||||||
@ -23,14 +17,14 @@ namespace ttrss_co_client.tasks
|
|||||||
}
|
}
|
||||||
var sw = new Stopwatch();
|
var sw = new Stopwatch();
|
||||||
sw.Start();
|
sw.Start();
|
||||||
var conversionProc = Process.Start("ffmpeg", $"-y -loglevel quiet -i \"{wo.data["path"]}\" \"{conversionFilenameTarget}\"");
|
var conversionProc = Process.Start("ffmpeg", $"-y -loglevel quiet -i \"{wo.data["path"]}\" \"{wo.data["conversion-target"]}\"");
|
||||||
conversionProc.WaitForExit();
|
conversionProc.WaitForExit();
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
if(File.Exists(conversionFilenameTarget))
|
if(File.Exists(wo.data["conversion-target"]))
|
||||||
{
|
{
|
||||||
Console.WriteLine($" converted {wo.data["path"]} -> {conversionFilenameTarget}");
|
Console.WriteLine($" converted {wo.data["path"]} -> {wo.data["conversion-target"]}");
|
||||||
File.Delete(wo.data["path"]);
|
File.Delete(wo.data["path"]);
|
||||||
wo.data["path"] =conversionFilenameTarget;
|
wo.data["path"] = wo.data["conversion-target"];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,43 +11,81 @@ namespace ttrss_co_client.tasks
|
|||||||
public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
|
public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
|
||||||
{
|
{
|
||||||
Console.WriteLine($" YT podcastify: {headline.link.ToString()}");
|
Console.WriteLine($" YT podcastify: {headline.link.ToString()}");
|
||||||
|
|
||||||
var myGuid = Guid.NewGuid().ToString();
|
var myGuid = Guid.NewGuid().ToString();
|
||||||
var toReturn = new WorkOrder()
|
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))
|
||||||
{
|
{
|
||||||
articleId = headline.id,
|
Directory.CreateDirectory(ytdl.OutputFolder);
|
||||||
Phase2TaskList = new Dictionary<int, string>(),
|
}
|
||||||
data = new Dictionary<string, string>(),
|
|
||||||
guid = Guid.Parse(myGuid)
|
try
|
||||||
};
|
{
|
||||||
|
sw.Start();
|
||||||
|
var res = await ytdl.RunVideoDownload(headline.link.ToString());
|
||||||
|
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}: download trigger label removed");
|
||||||
|
|
||||||
var podcastTitle = headline.feed_title;
|
var podcastTitle = headline.feed_title;
|
||||||
var titlingLabel = labelsWRTArticle.FirstOrDefault(l => l.@checked && l.caption?.ToLower().StartsWith(Conf.PodcastTitlePrefix) == true);
|
var titlingLabel = labelsWRTArticle.FirstOrDefault(l => l.@checked && l.caption?.ToLower().StartsWith(Conf.PodcastTitlePrefix) == true);
|
||||||
if(titlingLabel != null)
|
if(titlingLabel != null)
|
||||||
{
|
{
|
||||||
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
|
|
||||||
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
|
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
|
||||||
|
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
|
||||||
}
|
}
|
||||||
Console.WriteLine($"article {headline.id} - yt podcastifying; {podcastTitle}");
|
Console.WriteLine($"article {headline.id} - podcastifying; {podcastTitle}");
|
||||||
|
|
||||||
toReturn.Phase2TaskList[0] = "yt-dlp";
|
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - YT podcastify (dl) {(res.Success ? "success" : "failure")}; {string.Join('\n', res.ErrorOutput)}", headline.id);
|
||||||
toReturn.data["ytdlp-link"] = headline.link.ToString();
|
if (!res.Success)
|
||||||
|
|
||||||
toReturn.Phase2TaskList[1] = "convert";
|
|
||||||
toReturn.data["conversion-target"] = ".mp3";
|
|
||||||
|
|
||||||
if(headline.link.Host.EndsWith("youtube.com"))
|
|
||||||
{
|
{
|
||||||
toReturn.Phase2TaskList[2] = "sponsorblock";
|
return null;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
var outputFilename = res.Data;
|
||||||
|
Console.WriteLine($"{headline.title} 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"] = 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
toReturn.Phase2TaskList[3] = "filemovePublish";
|
toReturn.Phase2TaskList[1] = "sponsorblock";
|
||||||
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/";
|
toReturn.Phase2TaskList[2] = "filemovePublish";
|
||||||
|
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/{Path.GetFileName(toReturn.data["conversion-target"])}";
|
||||||
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;
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -11,12 +11,12 @@ namespace ttrss_co_client.tasks
|
|||||||
public override string TaskName => "filemovePublish";
|
public override string TaskName => "filemovePublish";
|
||||||
public override async Task<Tuple<TaskStatus, WorkOrder>>ActOn(WorkOrder workOrder)
|
public override async Task<Tuple<TaskStatus, WorkOrder>>ActOn(WorkOrder workOrder)
|
||||||
{
|
{
|
||||||
var targetDirectory = workOrder.data["publish-target"];
|
var targetDirectory = Path.GetDirectoryName(workOrder.data["publish-target"]);
|
||||||
if(!Directory.Exists(targetDirectory))
|
if(!Directory.Exists(targetDirectory))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(targetDirectory);
|
Directory.CreateDirectory(targetDirectory);
|
||||||
}
|
}
|
||||||
File.Move(workOrder.data["path"], Path.Combine(workOrder.data["publish-target"], Path.GetFileName(workOrder.data["path"])), true);
|
File.Move(workOrder.data["path"], workOrder.data["publish-target"], true);
|
||||||
var article = (await TtrssClient.GetArticles(workOrder.articleId))?.FirstOrDefault();
|
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.ToString("o")}] - copied", article.id);
|
||||||
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.Done, workOrder);
|
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.Done, workOrder);
|
||||||
|
@ -72,6 +72,10 @@ namespace ttrss_co_client.tasks
|
|||||||
{
|
{
|
||||||
contentSegments.Add(new Tuple<double, double>(previousEdge, junkSegment.segment[0]));
|
contentSegments.Add(new Tuple<double, double>(previousEdge, junkSegment.segment[0]));
|
||||||
previousEdge = junkSegment.segment[1];
|
previousEdge = junkSegment.segment[1];
|
||||||
|
if(previousEdge < 0.5)
|
||||||
|
{
|
||||||
|
contentSegments.Clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
contentSegments.Add(new Tuple<double, double>(previousEdge, segments.First().videoDuration));
|
contentSegments.Add(new Tuple<double, double>(previousEdge, segments.First().videoDuration));
|
||||||
contentSegments = contentSegments.Except(contentSegments.Where(tup => tup.Item2 - tup.Item1 < 0.5)).ToList();
|
contentSegments = contentSegments.Except(contentSegments.Where(tup => tup.Item2 - tup.Item1 < 0.5)).ToList();
|
||||||
|
@ -11,34 +11,74 @@ namespace ttrss_co_client.tasks
|
|||||||
public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
|
public override async Task<WorkOrder> ActOn(Headline headline, IEnumerable<Label> labelsWRTArticle)
|
||||||
{
|
{
|
||||||
Console.WriteLine($" standard download: {headline.link.ToString()}");
|
Console.WriteLine($" standard download: {headline.link.ToString()}");
|
||||||
|
|
||||||
var myGuid = Guid.NewGuid().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);
|
||||||
|
}
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
sw.Start();
|
||||||
|
var res = await ytdl.RunVideoDownload(headline.link.ToString());
|
||||||
|
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");
|
||||||
|
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToString("o")}] - standard 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.");
|
||||||
|
|
||||||
var toReturn = new WorkOrder()
|
var toReturn = new WorkOrder()
|
||||||
{
|
{
|
||||||
articleId = headline.id,
|
articleId = headline.id,//<-- that way later tasks can update the note
|
||||||
Phase2TaskList = new Dictionary<int, string>(),
|
Phase2TaskList = new Dictionary<int, string>(),
|
||||||
data = new Dictionary<string, string>(),
|
data = new Dictionary<string, string>(),
|
||||||
guid = Guid.Parse(myGuid)
|
guid = Guid.Parse(myGuid)
|
||||||
};
|
};
|
||||||
|
toReturn.data["path"] = outputFilename;
|
||||||
toReturn.Phase2TaskList[0] = "yt-dlp";
|
if(!outputFilename.EndsWith(".mp4"))
|
||||||
toReturn.data["ytdlp-link"] = headline.link.ToString();
|
{
|
||||||
|
Console.WriteLine($"{headline.title} needs conversion task.");
|
||||||
toReturn.Phase2TaskList[1] = "convert";
|
toReturn.Phase2TaskList[0] = "convert";
|
||||||
toReturn.data["conversion-target"] = ".mp4";
|
toReturn.data["conversion-target"] = outputFilename.Substring(0, res.Data.LastIndexOf('.')) + ".mp4";
|
||||||
|
}
|
||||||
|
|
||||||
if(headline.link.Host.EndsWith("youtube.com"))
|
if(headline.link.Host.EndsWith("youtube.com"))
|
||||||
{
|
{
|
||||||
toReturn.Phase2TaskList[2] = "sponsorblock";
|
toReturn.Phase2TaskList[1] = "sponsorblock";
|
||||||
}
|
}
|
||||||
|
toReturn.Phase2TaskList[2] = "filemovePublish";
|
||||||
toReturn.Phase2TaskList[3] = "filemovePublish";
|
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/recent episodes/{Path.GetFileName(toReturn.data["conversion-target"])}";
|
||||||
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/recent episodes/";
|
|
||||||
|
|
||||||
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;
|
return toReturn;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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}", headline.id);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,56 +0,0 @@
|
|||||||
using System;
|
|
||||||
using System.Text;
|
|
||||||
using Newtonsoft.Json;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Diagnostics;
|
|
||||||
using System.Text.RegularExpressions;
|
|
||||||
using ttrss_co_client.ttrss;
|
|
||||||
using ttrss_co_client.ttrss.datastructures;
|
|
||||||
|
|
||||||
namespace ttrss_co_client.tasks
|
|
||||||
{
|
|
||||||
///<summary>Move to output</summary>
|
|
||||||
public class Ytdlp : Phase2Task
|
|
||||||
{
|
|
||||||
public override string TaskName => "yt-dlp";
|
|
||||||
|
|
||||||
public override async Task<Tuple<TaskStatus, WorkOrder>>ActOn(WorkOrder workOrder)
|
|
||||||
{
|
|
||||||
var article = (await TtrssClient.GetArticles(workOrder.articleId)).FirstOrDefault();
|
|
||||||
var sw = new Stopwatch();
|
|
||||||
|
|
||||||
var ytdl = new YoutubeDLSharp.YoutubeDL();
|
|
||||||
ytdl.YoutubeDLPath = "yt-dlp";
|
|
||||||
ytdl.FFmpegPath = "ffmpeg";
|
|
||||||
ytdl.OutputFolder = $"{Conf.WorkingDirectory}/{workOrder.guid}";
|
|
||||||
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
|
|
||||||
if(!Path.Exists(ytdl.OutputFolder))
|
|
||||||
{
|
|
||||||
Directory.CreateDirectory(ytdl.OutputFolder);
|
|
||||||
}
|
|
||||||
sw.Start();
|
|
||||||
var res = await ytdl.RunVideoDownload(workOrder.data["ytdlp-link"]);
|
|
||||||
sw.Stop();
|
|
||||||
|
|
||||||
if (!res.Success)
|
|
||||||
{
|
|
||||||
await TtrssClient.UpdateArticleNote($"{article.note}\n[{DateTime.Now.ToString("o")}] yt-dlp fatal error. \n{string.Join('\n', res.ErrorOutput)}", article.id);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
await TtrssClient.UpdateArticleNote($"{article.note}\n[{DateTime.Now.ToString("o")}] yt-dlp {(res.Success ? "success" : "fail")} in {sw.Elapsed}", article.id);
|
|
||||||
|
|
||||||
var outputFilename = res.Data;
|
|
||||||
foreach(char c in "'\"")
|
|
||||||
{
|
|
||||||
outputFilename = outputFilename.Replace(c, '_');
|
|
||||||
}
|
|
||||||
if(outputFilename != res.Data)
|
|
||||||
{
|
|
||||||
File.Move(res.Data, outputFilename);
|
|
||||||
}
|
|
||||||
workOrder.data["path"] = outputFilename;
|
|
||||||
|
|
||||||
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.ContinueNow, workOrder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user