per feed internal actions
This commit is contained in:
parent
3936850913
commit
6432ad672b
@ -7,5 +7,12 @@ namespace ttrss_co_client
|
|||||||
public Uri BaseURI { get; set; }
|
public Uri BaseURI { get; set; }
|
||||||
public string Username { get; set; }
|
public string Username { get; set; }
|
||||||
public string Password { get; set; }
|
public string Password { get; set; }
|
||||||
|
public string CopilotDoneCaption { get; set; }
|
||||||
|
public IEnumerable<FeedAction> feedActions{get;set;}
|
||||||
|
public class FeedAction
|
||||||
|
{
|
||||||
|
public string feedurl { get; set; }
|
||||||
|
public string command { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
74
Program.cs
74
Program.cs
@ -1,5 +1,6 @@
|
|||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Diagnostics;
|
||||||
|
|
||||||
namespace ttrss_co_client
|
namespace ttrss_co_client
|
||||||
{
|
{
|
||||||
@ -14,16 +15,52 @@ namespace ttrss_co_client
|
|||||||
var loggedin = await ttrssClient.IsLoggedIn();
|
var loggedin = await ttrssClient.IsLoggedIn();
|
||||||
Console.WriteLine($"logged in: {loggedin}");
|
Console.WriteLine($"logged in: {loggedin}");
|
||||||
|
|
||||||
var apiLevel = await ttrssClient.GetApiLevel();
|
var doneLabelCaption = conf.CopilotDoneCaption.ToLower();
|
||||||
Console.WriteLine($"api level: {apiLevel}");
|
|
||||||
|
|
||||||
|
var miscTasks = new List<Task>();
|
||||||
|
var unreadFeeds = await ttrssClient.GetFeeds(cat_id: -3, unread_only: true);
|
||||||
|
foreach (var uf in unreadFeeds)
|
||||||
|
{
|
||||||
|
var actionForFeed = conf.feedActions.FirstOrDefault(fa => fa.feedurl == uf.feed_url.ToString());
|
||||||
|
if (actionForFeed != null)
|
||||||
|
{
|
||||||
|
var headlines = await ttrssClient.GetHeadlines(uf.id, view_mode: ttrss.ApiClient.VIEWMODE.Unread);
|
||||||
|
foreach (var hl in headlines)
|
||||||
|
{
|
||||||
|
var doneLabel = (await ttrssClient.GetLabels(hl.id)).First(l => l.caption?.ToLower() == doneLabelCaption);
|
||||||
|
if (!doneLabel.@checked)
|
||||||
|
{
|
||||||
|
var noteString = hl.note;
|
||||||
|
if (!string.IsNullOrWhiteSpace(noteString))
|
||||||
|
{
|
||||||
|
noteString += $"{hl.note}\n";
|
||||||
|
}
|
||||||
|
switch (actionForFeed.command)
|
||||||
|
{
|
||||||
|
case "dl":
|
||||||
|
var tr = await standardDL(hl.link.ToString());
|
||||||
|
miscTasks.Add(ttrssClient.UpdateArticleNote($"[{DateTime.Now.ToLongTimeString()}] - {tr.Item2}", hl.id));
|
||||||
|
if (tr.Item1 == true)
|
||||||
|
{
|
||||||
|
miscTasks.Add(ttrssClient.SetArticleLabel(doneLabel.id, true, hl.id));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
noteString += $"[{DateTime.Now.ToLongTimeString()}] - feed configured but action not recognized";
|
||||||
|
miscTasks.Add(ttrssClient.SetArticleLabel(doneLabel.id, true, hl.id));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
miscTasks.Add(ttrssClient.UpdateArticleNote(noteString, hl.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
var loggedout = await ttrssClient.Logout();
|
|
||||||
Console.WriteLine($"logged out: {loggedout}");
|
|
||||||
|
|
||||||
loggedin = await ttrssClient.IsLoggedIn();
|
miscTasks.Add(ttrssClient.Logout());
|
||||||
Console.WriteLine($"logged in: {loggedin}");
|
Console.WriteLine($"awaiting remaining tasks");
|
||||||
|
Task.WaitAll(miscTasks.ToArray());
|
||||||
|
Console.WriteLine($"done");
|
||||||
}
|
}
|
||||||
static Configuration Configure(string configurationPath = "appsettings.json")
|
static Configuration Configure(string configurationPath = "appsettings.json")
|
||||||
{
|
{
|
||||||
@ -53,5 +90,28 @@ namespace ttrss_co_client
|
|||||||
return conf;
|
return conf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static async Task<Tuple<bool, string>> standardDL(string articleLink)
|
||||||
|
{
|
||||||
|
var ytdl = new YoutubeDLSharp.YoutubeDL();
|
||||||
|
ytdl.YoutubeDLPath = "yt-dlp";
|
||||||
|
ytdl.FFmpegPath = "ffmpeg";
|
||||||
|
ytdl.OutputFolder = "./tmp/";
|
||||||
|
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].mp4";
|
||||||
|
var sw = new Stopwatch();
|
||||||
|
// var data = await ytdl.RunVideoDataFetch(articleLink);
|
||||||
|
// if (data.Data.ReleaseDate != null && data.Data.ReleaseDate > DateTime.Now)
|
||||||
|
// {
|
||||||
|
// return new Tuple<bool, string>(false, $"release date in future? {data.Data.ReleaseDate}");
|
||||||
|
// }
|
||||||
|
sw.Start();
|
||||||
|
var res = await ytdl.RunVideoDownload(articleLink);
|
||||||
|
sw.Stop();
|
||||||
|
var outputStr = $"{(res.Success ? "Success" : "fail")} in {sw.Elapsed}";
|
||||||
|
if(res.ErrorOutput != null && res.ErrorOutput.Length > 0)
|
||||||
|
{
|
||||||
|
outputStr += "\n" + string.Join('\n', res.ErrorOutput);
|
||||||
|
}
|
||||||
|
return new Tuple<bool, string>(res.Success, outputStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,12 @@
|
|||||||
{
|
{
|
||||||
"BaseUri": "https://ttrss.example.com/api/",
|
"BaseUri": "https://ttrss.example.com/api/",
|
||||||
"username": "guy who didn't configure",
|
"username": "guy who didn't configure",
|
||||||
"password": "sordph1sh"
|
"password": "sordph1sh",
|
||||||
|
"feedactions":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"feedurl":"youtube.com/a_channel",
|
||||||
|
"command":"dl"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
@ -8,8 +8,9 @@
|
|||||||
<Nullable>disable</Nullable>
|
<Nullable>disable</Nullable>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
|
||||||
|
<PackageReference Include="youtubedlsharp" Version="0.4.3" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
@ -6,7 +6,6 @@ using ttrss_co_client.ttrss.messages;
|
|||||||
using ttrss_co_client.ttrss.datastructures;
|
using ttrss_co_client.ttrss.datastructures;
|
||||||
|
|
||||||
// https://tt-rss.org/wiki/ApiReference
|
// https://tt-rss.org/wiki/ApiReference
|
||||||
//TODO: a lot of these are a given at API level 1, so double check all necessary API levels
|
|
||||||
|
|
||||||
namespace ttrss_co_client.ttrss
|
namespace ttrss_co_client.ttrss
|
||||||
{
|
{
|
||||||
@ -161,7 +160,7 @@ namespace ttrss_co_client.ttrss
|
|||||||
public enum SORTORDER { Default, OldestFirst, NewestFirst }
|
public enum SORTORDER { Default, OldestFirst, NewestFirst }
|
||||||
public async Task<IEnumerable<Headline>> GetHeadlines(
|
public async Task<IEnumerable<Headline>> GetHeadlines(
|
||||||
int feed_id,
|
int feed_id,
|
||||||
bool is_cat,
|
bool is_cat = false,
|
||||||
int limit = 60,
|
int limit = 60,
|
||||||
int skip = 0,
|
int skip = 0,
|
||||||
/*string filter,*/
|
/*string filter,*/
|
||||||
@ -190,6 +189,23 @@ namespace ttrss_co_client.ttrss
|
|||||||
assertApiLevel(4);
|
assertApiLevel(4);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string viewmodestr = "all_articles";
|
||||||
|
switch(view_mode)
|
||||||
|
{
|
||||||
|
case VIEWMODE.Unread:
|
||||||
|
viewmodestr = "unread";
|
||||||
|
break;
|
||||||
|
case VIEWMODE.Adaptive:
|
||||||
|
viewmodestr = "adaptive";
|
||||||
|
break;
|
||||||
|
case VIEWMODE.Marked:
|
||||||
|
viewmodestr = "marked";
|
||||||
|
break;
|
||||||
|
case VIEWMODE.Updated:
|
||||||
|
viewmodestr = "updated";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
string sortOrderString = "";
|
string sortOrderString = "";
|
||||||
if (order_by != SORTORDER.Default)
|
if (order_by != SORTORDER.Default)
|
||||||
{
|
{
|
||||||
@ -225,7 +241,7 @@ namespace ttrss_co_client.ttrss
|
|||||||
skip = skip,
|
skip = skip,
|
||||||
show_excerpt = show_excerpt,
|
show_excerpt = show_excerpt,
|
||||||
show_content = show_content,
|
show_content = show_content,
|
||||||
view_mode = view_mode.ToString("D"),
|
view_mode = viewmodestr,
|
||||||
include_attachments = include_attachments,
|
include_attachments = include_attachments,
|
||||||
since_id = since_id,
|
since_id = since_id,
|
||||||
include_nested = include_nested,
|
include_nested = include_nested,
|
||||||
|
Loading…
Reference in New Issue
Block a user