Compare commits
2 Commits
036dff3b12
...
3d84beb640
Author | SHA1 | Date | |
---|---|---|---|
3d84beb640 | |||
3958eee080 |
@ -10,6 +10,12 @@ 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!");
|
||||||
@ -17,14 +23,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"]}\" \"{wo.data["conversion-target"]}\"");
|
var conversionProc = Process.Start("ffmpeg", $"-y -loglevel quiet -i \"{wo.data["path"]}\" \"{conversionFilenameTarget}\"");
|
||||||
conversionProc.WaitForExit();
|
conversionProc.WaitForExit();
|
||||||
sw.Stop();
|
sw.Stop();
|
||||||
if(File.Exists(wo.data["conversion-target"]))
|
if(File.Exists(conversionFilenameTarget))
|
||||||
{
|
{
|
||||||
Console.WriteLine($" converted {wo.data["path"]} -> {wo.data["conversion-target"]}");
|
Console.WriteLine($" converted {wo.data["path"]} -> {conversionFilenameTarget}");
|
||||||
File.Delete(wo.data["path"]);
|
File.Delete(wo.data["path"]);
|
||||||
wo.data["path"] = wo.data["conversion-target"];
|
wo.data["path"] =conversionFilenameTarget;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -11,81 +11,43 @@ 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 ytdl = new YoutubeDLSharp.YoutubeDL();
|
var toReturn = new WorkOrder()
|
||||||
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);
|
articleId = headline.id,
|
||||||
}
|
Phase2TaskList = new Dictionary<int, string>(),
|
||||||
|
data = new Dictionary<string, string>(),
|
||||||
try
|
guid = Guid.Parse(myGuid)
|
||||||
{
|
};
|
||||||
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)
|
||||||
{
|
{
|
||||||
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
|
|
||||||
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
|
podcastTitle = titlingLabel.caption.Substring(Conf.PodcastTitlePrefix.Length);
|
||||||
|
await TtrssClient.SetArticleLabel(titlingLabel.id, false, headline.id);
|
||||||
}
|
}
|
||||||
Console.WriteLine($"article {headline.id} - podcastifying; {podcastTitle}");
|
Console.WriteLine($"article {headline.id} - yt 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);
|
toReturn.Phase2TaskList[0] = "yt-dlp";
|
||||||
if (!res.Success)
|
toReturn.data["ytdlp-link"] = headline.link.ToString();
|
||||||
{
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
var outputFilename = res.Data;
|
|
||||||
Console.WriteLine($"{headline.title} downloaded.");
|
|
||||||
|
|
||||||
var toReturn = new WorkOrder()
|
toReturn.Phase2TaskList[1] = "convert";
|
||||||
|
toReturn.data["conversion-target"] = ".mp3";
|
||||||
|
|
||||||
|
if(headline.link.Host.EndsWith("youtube.com"))
|
||||||
{
|
{
|
||||||
articleId = headline.id,//<-- that way later tasks can update the note
|
toReturn.Phase2TaskList[2] = "sponsorblock";
|
||||||
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[1] = "sponsorblock";
|
toReturn.Phase2TaskList[3] = "filemovePublish";
|
||||||
toReturn.Phase2TaskList[2] = "filemovePublish";
|
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/Podcasts/{podcastTitle}/";
|
||||||
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 = Path.GetDirectoryName(workOrder.data["publish-target"]);
|
var targetDirectory = workOrder.data["publish-target"];
|
||||||
if(!Directory.Exists(targetDirectory))
|
if(!Directory.Exists(targetDirectory))
|
||||||
{
|
{
|
||||||
Directory.CreateDirectory(targetDirectory);
|
Directory.CreateDirectory(targetDirectory);
|
||||||
}
|
}
|
||||||
File.Move(workOrder.data["path"], workOrder.data["publish-target"], true);
|
File.Move(workOrder.data["path"], Path.Combine(workOrder.data["publish-target"], Path.GetFileName(workOrder.data["path"])), 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,10 +72,6 @@ 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,74 +11,34 @@ 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,//<-- that way later tasks can update the note
|
articleId = headline.id,
|
||||||
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;
|
|
||||||
if(!outputFilename.EndsWith(".mp4"))
|
toReturn.Phase2TaskList[0] = "yt-dlp";
|
||||||
{
|
toReturn.data["ytdlp-link"] = headline.link.ToString();
|
||||||
Console.WriteLine($"{headline.title} needs conversion task.");
|
|
||||||
toReturn.Phase2TaskList[0] = "convert";
|
toReturn.Phase2TaskList[1] = "convert";
|
||||||
toReturn.data["conversion-target"] = outputFilename.Substring(0, res.Data.LastIndexOf('.')) + ".mp4";
|
toReturn.data["conversion-target"] = ".mp4";
|
||||||
}
|
|
||||||
|
|
||||||
if(headline.link.Host.EndsWith("youtube.com"))
|
if(headline.link.Host.EndsWith("youtube.com"))
|
||||||
{
|
{
|
||||||
toReturn.Phase2TaskList[1] = "sponsorblock";
|
toReturn.Phase2TaskList[2] = "sponsorblock";
|
||||||
}
|
}
|
||||||
toReturn.Phase2TaskList[2] = "filemovePublish";
|
|
||||||
toReturn.data["publish-target"] = $"{Conf.OnDoneCopy}/recent episodes/{Path.GetFileName(toReturn.data["conversion-target"])}";
|
toReturn.Phase2TaskList[3] = "filemovePublish";
|
||||||
|
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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
56
tasks/Ytdlp.cs
Normal file
56
tasks/Ytdlp.cs
Normal file
@ -0,0 +1,56 @@
|
|||||||
|
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