convert seems to work
This commit is contained in:
parent
826b181cf1
commit
02d6e4a0ae
33
Program.cs
33
Program.cs
@ -113,22 +113,23 @@ namespace ttrss_co_client
|
||||
}
|
||||
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)
|
||||
{
|
||||
//todo: solve the halting problem
|
||||
//ok but seriously,
|
||||
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);
|
||||
}
|
||||
//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,10 +158,12 @@ 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:
|
||||
// :)
|
||||
// :)
|
||||
break;
|
||||
case Phase2Task.TaskStatus.ContinueNow:
|
||||
remainingWork.Add(wo.Item2);
|
||||
@ -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();
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
@ -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; }
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user