Added Mastodon announcement; Fixed async Task issue

This commit is contained in:
2024-09-24 19:46:15 -04:00
parent 21ea17e906
commit 687076abeb
2 changed files with 26 additions and 4 deletions

View File

@@ -8,6 +8,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AnitomySharp.NET6" Version="0.5.1" />
<PackageReference Include="Mastonet" Version="3.1.2" />
<PackageReference Include="Microsoft.Extensions.Configuration" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.FileExtensions" Version="8.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />

View File

@@ -1,6 +1,7 @@
using System.ComponentModel;
using AnimeAnnouncer.Cache;
using AnimeAnnouncer.RSS;
using Mastonet;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
using TMDbLib.Client;
@@ -13,6 +14,7 @@ namespace AnimeAnnouncer
private static TMDbClient tmdbClient;
private static TMDBCache tmdbCache;
private static MastodonClient mastodonClient;
static void Main(string[] args)
{
Console.WriteLine("Starting...");
@@ -39,6 +41,14 @@ namespace AnimeAnnouncer
Console.WriteLine("Using cache");
}
String mastodonInstance = config["MastodonInstance"];
if(!String.IsNullOrEmpty(mastodonInstance))
{
String mastodonToken = config["MastodonToken"];
mastodonClient = new MastodonClient(mastodonInstance, mastodonToken);
}
nyaaIndexer.NewPost += OnNewPost;
nyaaIndexer.RssReadFinished += OnRssReadFinished;
nyaaIndexer.Start(true);
@@ -126,13 +136,13 @@ namespace AnimeAnnouncer
{
try
{
tmdbCache.SetCacheItem($"ShowCache-{title}", new TMDBCacheItem()
_ = tmdbCache.SetCacheItem($"ShowCache-{title}", new TMDBCacheItem()
{
Title = title,
ShowID = supposedShowId,
LatestSeasonNumber = latestSeason.SeasonNumber,
LastEpisodeNumber = latestSeason.EpisodeCount
}).Start();
});
Console.WriteLine($"{title} Added to cache");
}
catch(Exception ex)
@@ -156,9 +166,20 @@ namespace AnimeAnnouncer
return;
}
//
// Announce
if(mastodonClient != null)
{
try
{
_ = mastodonClient.PublishStatus($"<p>Finished Dubbed Airing Anime</p> {title} has finished airing! Season {season} Episode {episode} is now available for download. ", Visibility.Public);
//AnnounceFinishedSeason(title);
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
}
Console.WriteLine($"Choosing {title} as a finished season!");
}
}