Compare commits

..

No commits in common. "c4b6a79273325c15c56acf6b9a8f7d72bdf1d2a9" and "3936850913930f52ed80ef63bf1b2a119e8560ee" have entirely different histories.

5 changed files with 13 additions and 172 deletions

View File

@ -7,13 +7,5 @@ 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; }
}
} }
} }

View File

@ -1,6 +1,5 @@
using Newtonsoft.Json; using Newtonsoft.Json;
using System.Linq; using System.Linq;
using System.Diagnostics;
namespace ttrss_co_client namespace ttrss_co_client
{ {
@ -15,89 +14,16 @@ 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 miscTasks = new List<Task>(); var apiLevel = await ttrssClient.GetApiLevel();
var unreadFeeds = await ttrssClient.GetFeeds(cat_id: -3, unread_only: true); Console.WriteLine($"api level: {apiLevel}");
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 resulted = Directory.GetFiles("tmp", "*.*", SearchOption.AllDirectories); var loggedout = await ttrssClient.Logout();
if(resulted.Count() > 0) Console.WriteLine($"logged out: {loggedout}");
{
foreach(var f in resulted) loggedin = await ttrssClient.IsLoggedIn();
{ 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")
{ {
@ -127,52 +53,5 @@ 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);
}
} }
} }

View File

@ -1,18 +1,5 @@
{ {
"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"
}
]
} }

View File

@ -10,7 +10,6 @@
<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>

View File

@ -6,6 +6,7 @@ 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
{ {
@ -160,7 +161,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 = false, bool is_cat,
int limit = 60, int limit = 60,
int skip = 0, int skip = 0,
/*string filter,*/ /*string filter,*/
@ -189,23 +190,6 @@ 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)
{ {
@ -241,7 +225,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 = viewmodestr, view_mode = view_mode.ToString("D"),
include_attachments = include_attachments, include_attachments = include_attachments,
since_id = since_id, since_id = since_id,
include_nested = include_nested, include_nested = include_nested,