Compare commits
2 Commits
3936850913
...
c4b6a79273
Author | SHA1 | Date | |
---|---|---|---|
c4b6a79273 | |||
6432ad672b |
@ -7,5 +7,13 @@ 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 PodcastTitlePrefix { get; set; }
|
||||||
|
public string OnDoneCopy { get; set; }
|
||||||
|
public IEnumerable<FeedAction> feedActions { get; set; }
|
||||||
|
public class FeedAction
|
||||||
|
{
|
||||||
|
public string triggerlabelCaption { get; set; }
|
||||||
|
public string command { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
135
Program.cs
135
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,89 @@ 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 miscTasks = new List<Task>();
|
||||||
Console.WriteLine($"api level: {apiLevel}");
|
var unreadFeeds = await ttrssClient.GetFeeds(cat_id: -3, unread_only: true);
|
||||||
|
foreach (var uf in unreadFeeds)
|
||||||
|
{
|
||||||
|
|
||||||
|
var headlines = await ttrssClient.GetHeadlines(uf.id, view_mode: ttrss.ApiClient.VIEWMODE.Unread);
|
||||||
|
foreach (var hl in headlines)
|
||||||
|
{
|
||||||
|
var labelsWRTFeed = (await ttrssClient.GetLabels(hl.id));
|
||||||
|
var actionsForFeed = conf.feedActions.Where(fa =>
|
||||||
|
labelsWRTFeed.Where(l => l.@checked).Select(l => l.caption).Contains(fa.triggerlabelCaption))?.ToList();
|
||||||
|
if(actionsForFeed != null && actionsForFeed.Any())
|
||||||
|
{
|
||||||
|
foreach(var action in actionsForFeed)
|
||||||
|
{
|
||||||
|
var noteString = hl.note;
|
||||||
|
if (!string.IsNullOrWhiteSpace(noteString))
|
||||||
|
{
|
||||||
|
noteString += $"{hl.note}\n";
|
||||||
|
}
|
||||||
|
switch (action.command)
|
||||||
|
{
|
||||||
|
case "dl":
|
||||||
|
var stdDLResult = await standardDL(hl.link.ToString());
|
||||||
|
miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {stdDLResult.Item2}", hl.id));
|
||||||
|
if (stdDLResult.Item1 == true)
|
||||||
|
{
|
||||||
|
miscTasks.Add(
|
||||||
|
ttrssClient.SetArticleLabel(
|
||||||
|
labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id,
|
||||||
|
false,
|
||||||
|
hl.id));
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "podcastify":
|
||||||
|
var nameLabel = labelsWRTFeed.FirstOrDefault(l => l.caption?.StartsWith(conf.PodcastTitlePrefix) == true);
|
||||||
|
var podcastName = nameLabel?.caption.Substring(conf.PodcastTitlePrefix.Length)
|
||||||
|
?? hl.feed_title;
|
||||||
|
var podcastifyResult = await podcastify(hl.link.ToString(), podcastName);
|
||||||
|
miscTasks.Add(ttrssClient.UpdateArticleNote($"{noteString}[{DateTime.Now.ToLongTimeString()}] - {podcastifyResult.Item2}", hl.id));
|
||||||
|
if (podcastifyResult.Item1 == true)
|
||||||
|
{
|
||||||
|
miscTasks.Add(
|
||||||
|
ttrssClient.SetArticleLabel(
|
||||||
|
labelsWRTFeed.First(l => l.caption == action.triggerlabelCaption).id,
|
||||||
|
false,
|
||||||
|
hl.id));
|
||||||
|
if(nameLabel != null)
|
||||||
|
{
|
||||||
|
miscTasks.Add(ttrssClient.SetArticleLabel(nameLabel.id, false, hl.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
noteString += $"[{DateTime.Now.ToLongTimeString()}] - feed configured but action not recognized";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
miscTasks.Add(ttrssClient.UpdateArticleNote(noteString, hl.id));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
miscTasks.Add(ttrssClient.Logout());
|
||||||
|
Console.WriteLine($"awaiting remaining download tasks");
|
||||||
|
Task.WaitAll(miscTasks.ToArray());
|
||||||
|
Console.WriteLine($"done, moving files from temporary location");
|
||||||
|
|
||||||
var loggedout = await ttrssClient.Logout();
|
var resulted = Directory.GetFiles("tmp", "*.*", SearchOption.AllDirectories);
|
||||||
Console.WriteLine($"logged out: {loggedout}");
|
if(resulted.Count() > 0)
|
||||||
|
{
|
||||||
loggedin = await ttrssClient.IsLoggedIn();
|
foreach(var f in resulted)
|
||||||
Console.WriteLine($"logged in: {loggedin}");
|
{
|
||||||
|
var moveTarget = Path.Combine(conf.OnDoneCopy, f.Substring("tmp/".Length));
|
||||||
|
if(!Path.Exists(Path.GetDirectoryName(moveTarget)))
|
||||||
|
{
|
||||||
|
Directory.CreateDirectory(Path.GetDirectoryName(moveTarget));
|
||||||
|
}
|
||||||
|
File.Move(f, moveTarget);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Console.WriteLine($"done for real");
|
||||||
}
|
}
|
||||||
static Configuration Configure(string configurationPath = "appsettings.json")
|
static Configuration Configure(string configurationPath = "appsettings.json")
|
||||||
{
|
{
|
||||||
@ -53,5 +127,52 @@ 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/recent episodes";
|
||||||
|
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].mp4";
|
||||||
|
var sw = new Stopwatch();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
private static async Task<Tuple<bool, string>> podcastify(string articleLink, string podcastName)
|
||||||
|
{
|
||||||
|
var ytdl = new YoutubeDLSharp.YoutubeDL();
|
||||||
|
ytdl.YoutubeDLPath = "yt-dlp";
|
||||||
|
ytdl.FFmpegPath = "ffmpeg";
|
||||||
|
ytdl.OutputFolder = $"./tmp/podcasts/{podcastName}";
|
||||||
|
ytdl.OutputFileTemplate = "%(upload_date)s - %(title)s - [%(id)s].%(ext)s";
|
||||||
|
var sw = new Stopwatch();
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
if(!res.Data.EndsWith(".mp3"))
|
||||||
|
{
|
||||||
|
sw.Reset();
|
||||||
|
var outputFilename = res.Data.Substring(0, res.Data.LastIndexOf('.')) + ".mp3";
|
||||||
|
sw.Start();
|
||||||
|
var conversionProc =Process.Start("ffmpeg", $"-y -i \"{res.Data}\" \"{outputFilename}\"");
|
||||||
|
conversionProc.WaitForExit();
|
||||||
|
sw.Stop();
|
||||||
|
File.Delete(res.Data);
|
||||||
|
outputStr += $"\nconverted in {sw.Elapsed}";
|
||||||
|
}
|
||||||
|
return new Tuple<bool, string>(res.Success, outputStr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,5 +1,18 @@
|
|||||||
{
|
{
|
||||||
"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",
|
||||||
|
"podcastTitlePrefix": "[podcast title] - ",
|
||||||
|
"onDoneCopy":"./",
|
||||||
|
"feedActions":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"triggerlabelCaption":"dl plz",
|
||||||
|
"command":"dl"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"triggerlabelCaption":"podcastify plz",
|
||||||
|
"command":"podcastify"
|
||||||
|
}
|
||||||
|
]
|
||||||
}
|
}
|
@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<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