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,22 +113,23 @@ namespace ttrss_co_client
} }
Console.WriteLine($"{remainingWork.Count} phase 2 workorders, between pulled from ttrss and read from files"); Console.WriteLine($"{remainingWork.Count} phase 2 workorders, between pulled from ttrss and read from files");
Phase2Task.TtrssClient = ttrssClient;
Phase2Task.Conf = conf;
var phase2TaskTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(Phase2Task)) && !type.IsAbstract)
.ToList();
var phase2TaskConcretions = new List<Phase2Task>();
foreach (var phase2TaskType in phase2TaskTypes)
{
var concretion = (Phase2Task) Activator.CreateInstance(phase2TaskType);
phase2TaskConcretions.Add(concretion);
}
while(remainingWork.Count > 0) while(remainingWork.Count > 0)
{ {
//todo: solve the halting problem //todo: solve the halting problem
//ok but seriously, //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!
Phase2Task.TtrssClient = ttrssClient;
Phase2Task.Conf = conf;
var phase2TaskTypes = AppDomain.CurrentDomain.GetAssemblies()
.SelectMany(domainAssembly => domainAssembly.GetTypes())
.Where(type => type.IsSubclassOf(typeof(Phase2Task)) && !type.IsAbstract)
.ToList();
var phase2TaskConcretions = new List<Phase2Task>();
foreach (var phase2TaskType in phase2TaskTypes)
{
var concretion = (Phase2Task) Activator.CreateInstance(phase2TaskType);
phase2TaskConcretions.Add(concretion);
}
Console.WriteLine($"{phase2TaskConcretions.Count()} phase 2 task types understood"); Console.WriteLine($"{phase2TaskConcretions.Count()} phase 2 task types understood");
var Phase2Tasks = new List<Task<Tuple<Phase2Task.TaskStatus, WorkOrder>>>(); var Phase2Tasks = new List<Task<Tuple<Phase2Task.TaskStatus, WorkOrder>>>();
@ -157,10 +158,12 @@ namespace ttrss_co_client
foreach(var lingeringTask in Phase2Tasks) foreach(var lingeringTask in Phase2Tasks)
{ {
var wo = await lingeringTask; 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) switch (wo.Item1)
{ {
case Phase2Task.TaskStatus.Done: case Phase2Task.TaskStatus.Done:
// :) // :)
break; break;
case Phase2Task.TaskStatus.ContinueNow: case Phase2Task.TaskStatus.ContinueNow:
remainingWork.Add(wo.Item2); remainingWork.Add(wo.Item2);
@ -170,7 +173,7 @@ namespace ttrss_co_client
break; 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 #endregion
await ttrssClient.Logout(); await ttrssClient.Logout();

View File

@ -1,15 +1,45 @@
// using System.Diagnostics; using System.Diagnostics;
// using ttrss_co_client.ttrss; using ttrss_co_client.ttrss;
// using ttrss_co_client.ttrss.datastructures; using ttrss_co_client.ttrss.datastructures;
// namespace ttrss_co_client.tasks namespace ttrss_co_client.tasks
// { {
// ///<summary>ffmpegify</summary> ///<summary>ffmpegify</summary>
// public class Convert : Phase2Task public class Convert : Phase2Task
// { {
// public override async Task<WorkOrder> ActOn(WorkOrder wo) 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> ///<summary>convert, rip ads, etc</summary>
public abstract class Phase2Task 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 ApiClient TtrssClient { get; set; }
public static Configuration Conf { 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}"); Console.WriteLine($" {headline.link} -> {res.Data}\n{outputStr}");
await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id); await TtrssClient.SetArticleLabel(labelsWRTArticle.First(l => l.caption?.ToLower() == this.TriggerLabel.ToLower()).id, false, headline.id);
Console.WriteLine($" {headline.title}: label removed"); 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) if (!res.Success)
{ {
await TtrssClient.UpdateArticleNote($"{headline.note}\n[{DateTime.Now.ToLongTimeString()}] - standard dl failed; {string.Join('\n', res.ErrorOutput)}", headline.id);
return null; return null;
} }
else else