more debug info, and log out after awaiting final tasks

like updating notes
This commit is contained in:
Adam R Grey 2023-04-05 12:43:58 -04:00
parent c4b6a79273
commit c4263ff759
2 changed files with 80 additions and 55 deletions

View File

@ -19,7 +19,7 @@ namespace ttrss_co_client
var unreadFeeds = await ttrssClient.GetFeeds(cat_id: -3, unread_only: true); var unreadFeeds = await ttrssClient.GetFeeds(cat_id: -3, unread_only: true);
foreach (var uf in unreadFeeds) foreach (var uf in unreadFeeds)
{ {
Console.WriteLine($"unread feed: {uf.title}");
var headlines = await ttrssClient.GetHeadlines(uf.id, view_mode: ttrss.ApiClient.VIEWMODE.Unread); var headlines = await ttrssClient.GetHeadlines(uf.id, view_mode: ttrss.ApiClient.VIEWMODE.Unread);
foreach (var hl in headlines) foreach (var hl in headlines)
{ {
@ -30,6 +30,7 @@ namespace ttrss_co_client
{ {
foreach(var action in actionsForFeed) foreach(var action in actionsForFeed)
{ {
Console.WriteLine($" {hl.title} -> action: {action.command}");
var noteString = hl.note; var noteString = hl.note;
if (!string.IsNullOrWhiteSpace(noteString)) if (!string.IsNullOrWhiteSpace(noteString))
{ {
@ -42,12 +43,17 @@ namespace ttrss_co_client
miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {stdDLResult.Item2}", hl.id)); miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {stdDLResult.Item2}", hl.id));
if (stdDLResult.Item1 == true) if (stdDLResult.Item1 == true)
{ {
Console.WriteLine($" {hl.title} -> dl success, removing label");
miscTasks.Add( miscTasks.Add(
ttrssClient.SetArticleLabel( ttrssClient.SetArticleLabel(
labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id,
false, false,
hl.id)); hl.id));
} }
else
{
Console.WriteLine($" {hl.title} -> dl failed");
}
break; break;
case "podcastify": case "podcastify":
var nameLabel = labelsWRTFeed.FirstOrDefault(l => l.caption?.StartsWith(conf.PodcastTitlePrefix) == true); var nameLabel = labelsWRTFeed.FirstOrDefault(l => l.caption?.StartsWith(conf.PodcastTitlePrefix) == true);
@ -57,6 +63,7 @@ namespace ttrss_co_client
miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {podcastifyResult.Item2}", hl.id)); miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {podcastifyResult.Item2}", hl.id));
if (podcastifyResult.Item1 == true) if (podcastifyResult.Item1 == true)
{ {
Console.WriteLine($" {hl.title} -> podcastify success, removing labels");
miscTasks.Add( miscTasks.Add(
ttrssClient.SetArticleLabel( ttrssClient.SetArticleLabel(
labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id, labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id,
@ -67,6 +74,10 @@ namespace ttrss_co_client
miscTasks.Add(ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id)); miscTasks.Add(ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id));
} }
} }
else
{
Console.WriteLine($" {hl.title} -> podcastify failed");
}
break; break;
default: default:
noteString += $"[{DateTime.Now.ToLongTimeString()}] - feed configured but action not recognized"; noteString += $"[{DateTime.Now.ToLongTimeString()}] - feed configured but action not recognized";
@ -79,9 +90,9 @@ namespace ttrss_co_client
} }
miscTasks.Add(ttrssClient.Logout());
Console.WriteLine($"awaiting remaining download tasks"); Console.WriteLine($"awaiting remaining download tasks");
Task.WaitAll(miscTasks.ToArray()); Task.WaitAll(miscTasks.ToArray());
await ttrssClient.Logout();
Console.WriteLine($"done, moving files from temporary location"); Console.WriteLine($"done, moving files from temporary location");
var resulted = Directory.GetFiles("tmp", "*.*", SearchOption.AllDirectories); var resulted = Directory.GetFiles("tmp", "*.*", SearchOption.AllDirectories);
@ -129,11 +140,12 @@ namespace ttrss_co_client
private static async Task<Tuple<bool, string>> standardDL(string articleLink) private static async Task<Tuple<bool, string>> standardDL(string articleLink)
{ {
Console.WriteLine($" standard downloading {articleLink}");
var ytdl = new YoutubeDLSharp.YoutubeDL(); var ytdl = new YoutubeDLSharp.YoutubeDL();
ytdl.YoutubeDLPath = "yt-dlp"; ytdl.YoutubeDLPath = "yt-dlp";
ytdl.FFmpegPath = "ffmpeg"; ytdl.FFmpegPath = "ffmpeg";
ytdl.OutputFolder = "./tmp/recent episodes"; ytdl.OutputFolder = "./tmp/recent episodes";
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].mp4"; ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
var sw = new Stopwatch(); var sw = new Stopwatch();
sw.Start(); sw.Start();
var res = await ytdl.RunVideoDownload(articleLink); var res = await ytdl.RunVideoDownload(articleLink);
@ -143,6 +155,20 @@ namespace ttrss_co_client
{ {
outputStr += "\n" + string.Join('\n', res.ErrorOutput); outputStr += "\n" + string.Join('\n', res.ErrorOutput);
} }
Console.WriteLine($" download {(res.Success ? "success" : "failed")}: {articleLink} -> {res.Data}");
if(!res.Data.EndsWith(".mp4"))
{
Console.WriteLine("must convert video");
sw.Reset();
var outputFilename = res.Data.Substring(0, res.Data.LastIndexOf('.')) + ".mp4";
sw.Start();
var conversionProc =Process.Start("ffmpeg", $"-y -i \"{res.Data}\" \"{outputFilename}\"");
conversionProc.WaitForExit();
sw.Stop();
Console.WriteLine($" converted {res.Data} -> {outputFilename}");
File.Delete(res.Data);
outputStr += $"\nconverted in {sw.Elapsed}";
}
return new Tuple<bool, string>(res.Success, outputStr); return new Tuple<bool, string>(res.Success, outputStr);
} }
private static async Task<Tuple<bool, string>> podcastify(string articleLink, string podcastName) private static async Task<Tuple<bool, string>> podcastify(string articleLink, string podcastName)
@ -154,7 +180,7 @@ namespace ttrss_co_client
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s"; ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
var sw = new Stopwatch(); var sw = new Stopwatch();
sw.Start(); sw.Start();
var res = await ytdl.RunVideoDownload(articleLink); var res = await ytdl.RunAudioDownload(articleLink);
sw.Stop(); sw.Stop();
var outputStr = $"{(res.Success ? "Success" : "fail")} in {sw.Elapsed}"; var outputStr = $"{(res.Success ? "Success" : "fail")} in {sw.Elapsed}";
if(res.ErrorOutput != null && res.ErrorOutput.Length > 0) if(res.ErrorOutput != null && res.ErrorOutput.Length > 0)

View File

@ -12,5 +12,4 @@
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" /> <PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="youtubedlsharp" Version="0.4.3" /> <PackageReference Include="youtubedlsharp" Version="0.4.3" />
</ItemGroup> </ItemGroup>
</Project> </Project>