convert seems to work

This commit is contained in:
Adam R Grey 2023-04-07 23:54:09 -04:00
parent 826b181cf1
commit 02d6e4a0ae
4 changed files with 63 additions and 30 deletions

View File

@ -113,10 +113,6 @@ namespace ttrss_co_client
}
Console.WriteLine($"{remainingWork.Count} phase 2 workorders, between pulled from ttrss and read from files");
while(remainingWork.Count > 0)
{
//todo: solve the halting problem
//ok but seriously,
Phase2Task.TtrssClient = ttrssClient;
Phase2Task.Conf = conf;
var phase2TaskTypes = AppDomain.CurrentDomain.GetAssemblies()
@ -129,6 +125,11 @@ namespace ttrss_co_client
var concretion = (Phase2Task) Activator.CreateInstance(phase2TaskType);
phase2TaskConcretions.Add(concretion);
}
while(remainingWork.Count > 0)
{
//todo: solve the halting problem
//ok but seriously, maybe I could time out work orders after a while? but converting a 3-hour 4k video could easily take an hour!
Console.WriteLine($"{phase2TaskConcretions.Count()} phase 2 task types understood");
var Phase2Tasks = new List<Task<Tuple<Phase2Task.TaskStatus, WorkOrder>>>();
@ -157,6 +158,8 @@ namespace ttrss_co_client
foreach(var lingeringTask in Phase2Tasks)
{
var wo = await lingeringTask;
//if you tell me it's done, or you need to continue now.... I believe you.
//TODO: be smart enough to override?
switch (wo.Item1)
{
case Phase2Task.TaskStatus.Done:
@ -170,7 +173,7 @@ namespace ttrss_co_client
break;
}
}
Console.WriteLine($"{remainingWork.Count} phase 2 tasks not complete - should be picked up next run..");
Console.WriteLine($"{remainingWork.Count} phase 2 tasks to be re-looped.");
}
#endregion
await ttrssClient.Logout();

View File

@ -1,15 +1,45 @@
// 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>ffmpegify</summary>
// public class Convert : Phase2Task
// {
// public override async Task<WorkOrder> ActOn(WorkOrder wo)
// {
namespace ttrss_co_client.tasks
{
///<summary>ffmpegify</summary>
public class Convert : Phase2Task
{
public override string TaskName => "convert";
public override async Task<Tuple<TaskStatus, WorkOrder>> ActOn(WorkOrder wo)
{
var article = (await TtrssClient.GetArticles(wo.articleId))?.FirstOrDefault();
if(article == null){
Console.Error.WriteLine($"article {wo.articleId} couldn't be retrieved!");
return null;
}
var sw = new Stopwatch();
sw.Start();
var conversionProc = Process.Start("ffmpeg", $"-y -i \"{wo.data["path"]}\" \"{wo.data["conversion-target"]}\"");
conversionProc.WaitForExit();
sw.Stop();
if(File.Exists(wo.data["conversion-target"]))
{
Console.WriteLine($" converted {wo.data["path"]} -> {wo.data["conversion-target"]}");
File.Delete(wo.data["path"]);
wo.data["path"] = wo.data["conversion-target"];
}
// }
// }
// }
var outputStr = $"converted in {sw.Elapsed}";
Console.WriteLine(outputStr);
//re-get, in case conversion took a long time
article = (await TtrssClient.GetArticles(wo.articleId))?.FirstOrDefault();
await TtrssClient.UpdateArticleNote($"{article.note}\n{outputStr}", article.id);
var toReturn = new Tuple<TaskStatus, WorkOrder>(TaskStatus.ContinueNow, wo);
if(!wo.Phase2TaskList.Any())
{
Console.Error.WriteLine($"work order {wo.guid} came to conversion, but thinks its done?");
return new Tuple<TaskStatus, WorkOrder>(TaskStatus.Done, null);
}
return toReturn;
}
}
}

View File

@ -6,7 +6,7 @@ namespace ttrss_co_client.tasks
///<summary>convert, rip ads, etc</summary>
public abstract class Phase2Task
{
public string TaskName { get { return this.GetType().ToString(); } }
public virtual string TaskName { get { return this.GetType().ToString(); } }
public static ApiClient TtrssClient { get; set; }
public static Configuration Conf { get; set; }

View File

@ -33,9 +33,9 @@ namespace ttrss_co_client.tasks
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.ToLongTimeString()}] - standard dl {(res.Success ? "success" : "failure")}; {string.Join('\n', res.ErrorOutput)}", headline.id);
if (!res.Success)
{
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToLongTimeString()}] - standard dl failed; {string.Join('\n', res.ErrorOutput)}", headline.id);
return null;
}
else