Skip to content

Commit

Permalink
Update Shoko.Plugin.Abstractions to 3.0.0-alpha11
Browse files Browse the repository at this point in the history
  • Loading branch information
harshithmohan authored and fearnlj01 committed Aug 9, 2024
1 parent 1427c20 commit 307c5f6
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 16 deletions.
9 changes: 5 additions & 4 deletions Helpers/DiscordHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Tasks;
using NLog;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.DataModels.Shoko;
using Shoko.Plugin.WebhookDump.Models.AniDB;
using Shoko.Plugin.WebhookDump.Models.Discord;
using Shoko.Plugin.WebhookDump.Settings;
Expand Down Expand Up @@ -64,7 +65,7 @@ public async Task<string> SendWebhook(IVideoFile file, string dumpResult, AniDBS
}
}

public async Task PatchWebhook(IVideoFile file, IAnime anime, IEpisode episode, MemoryStream imageStream, string messageId)
public async Task PatchWebhook(IVideoFile file, IShokoSeries anime, IEpisode episode, MemoryStream imageStream, string messageId)
{
_logger.Info(CultureInfo.InvariantCulture, "Attempting to update Discord message (fileId={fileId}, messageId={messageId})", file.VideoID, messageId);

Expand Down Expand Up @@ -124,7 +125,7 @@ private Webhook GetUnmatchedWebhook(IVideoFile file, string dumpResult, AniDBSea
};
}

private Webhook GetMatchedWebhook(IVideoFile file, IAnime anime, IEpisode episode)
private Webhook GetMatchedWebhook(IVideoFile file, IShokoSeries anime, IEpisode episode)
{
UriBuilder publicUrl = new(_settings.Shoko.PublicUrl)
{
Expand Down Expand Up @@ -186,7 +187,7 @@ private static List<WebhookField> GetUnmatchedFields(string dumpResult, AniDBSea
return output;
}

private static List<WebhookField> GetMatchedFields(IAnime series, IEpisode episode)
private static List<WebhookField> GetMatchedFields(IShokoSeries series, IEpisode episode)
{
AnimeTitle episodeTitle = episode.Titles.FirstOrDefault(t => t.Language == TitleLanguage.English);
string episodeNumber = episode.EpisodeNumber.ToString("00", CultureInfo.InvariantCulture);
Expand All @@ -211,7 +212,7 @@ private static WebhookFooter GetFooter(IVideoFile file)
{
return new WebhookFooter()
{
Text = $"File ID: {file.VideoID} | CRC: {file.VideoInfo.Hashes.CRC}{(file.FileName.Contains($"[{file.VideoInfo.Hashes.CRC}]") ? " | CRC in filename" : string.Empty)}"
Text = $"File ID: {file.VideoID} | CRC: {file.Video?.Hashes.CRC}{(file.FileName.Contains($"[{file.Video?.Hashes.CRC}]") ? " | CRC in filename" : string.Empty)}"
};
}

Expand Down
3 changes: 2 additions & 1 deletion Helpers/Interfaces/IDiscordHelper.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
using System.IO;
using System.Threading.Tasks;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.DataModels.Shoko;
using Shoko.Plugin.WebhookDump.Models.AniDB;

namespace Shoko.Plugin.WebhookDump.Apis;

public interface IDiscordHelper
{
void Dispose();
Task PatchWebhook(IVideoFile file, IAnime anime, IEpisode episode, MemoryStream imageStream, string messageId);
Task PatchWebhook(IVideoFile file, IShokoSeries anime, IEpisode episode, MemoryStream imageStream, string messageId);
Task<string> SendWebhook(IVideoFile file, string dumpResult, AniDBSearchResult searchResult);
Task<bool> GetMessageReactionState(string messageId);
}
3 changes: 2 additions & 1 deletion Helpers/Interfaces/IShokoHelper.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.IO;
using System.Threading.Tasks;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.DataModels.Shoko;
using Shoko.Plugin.WebhookDump.Models.AniDB;

namespace Shoko.Plugin.WebhookDump.Apis;
Expand All @@ -10,7 +11,7 @@ public interface IShokoHelper
void Dispose();
Task DumpFile(int fileId);
Task<MemoryStream> GetImageStream(AniDBPoster poster);
Task<AniDBPoster> GetSeriesPoster(IAnime anime);
Task<AniDBPoster> GetSeriesPoster(IShokoSeries anime);
Task<AniDBSearchResult> MatchTitle(string filename);
Task ScanFile(IVideoFile file, int autoMatchAttempts = 1);
Task ScanFileById(int fileId);
Expand Down
3 changes: 2 additions & 1 deletion Helpers/ShokoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Threading.Tasks;
using NLog;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.DataModels.Shoko;
using Shoko.Plugin.WebhookDump.Models.AniDB;
using Shoko.Plugin.WebhookDump.Settings;

Expand Down Expand Up @@ -113,7 +114,7 @@ public async Task ScanFileById(int fileId)
}
}

public async Task<AniDBPoster> GetSeriesPoster(IAnime anime)
public async Task<AniDBPoster> GetSeriesPoster(IShokoSeries anime)
{
try
{
Expand Down
16 changes: 8 additions & 8 deletions WebhookDump.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using NLog;
using Shoko.Plugin.Abstractions;
using Shoko.Plugin.Abstractions.DataModels;
using Shoko.Plugin.Abstractions.DataModels.Shoko;
using Shoko.Plugin.WebhookDump.Apis;
using Shoko.Plugin.WebhookDump.Models.AniDB;
using Shoko.Plugin.WebhookDump.Settings;
Expand Down Expand Up @@ -68,7 +68,7 @@ public void Load()

private void OnFileNotMatched(object sender, FileNotMatchedEventArgs fileNotMatchedEvent)
{
IVideoFile fileInfo = fileNotMatchedEvent.FileInfo;
IVideoFile fileInfo = fileNotMatchedEvent.File;
int matchAttempts = fileNotMatchedEvent.AutoMatchAttempts;

if (!IsProbablyAnime(fileInfo) || fileNotMatchedEvent.HasCrossReferences)
Expand All @@ -79,7 +79,7 @@ private void OnFileNotMatched(object sender, FileNotMatchedEventArgs fileNotMatc
if (matchAttempts == 1)
{
_fileTracker.TryAddFile(fileInfo);
_ = Task.Run(() => _shokoHelper.DumpFile(fileInfo.VideoID)).ConfigureAwait(false); ;
_ = Task.Run(() => _shokoHelper.DumpFile(fileInfo.VideoID)).ConfigureAwait(false);
}

if (
Expand All @@ -99,19 +99,19 @@ private void OnFileNotMatched(object sender, FileNotMatchedEventArgs fileNotMatc
}
}

private async void OnFileMatched(object sender, FileMatchedEventArgs fileMatchedEvent)
private async void OnFileMatched(object sender, FileEventArgs fileMatchedEvent)
{
IVideoFile fileInfo = fileMatchedEvent.FileInfo;
IVideoFile fileInfo = fileMatchedEvent.File;

if (fileMatchedEvent.AnimeInfo.Count == 0 || fileMatchedEvent.EpisodeInfo.Count == 0)
if (fileMatchedEvent.Series.Count == 0 || fileMatchedEvent.Episodes.Count == 0)
{
// we don't want the plugin to panic here... so we'll just ignore that this ever happened.
// This appears to happen for when a series is new to Shoko, the episode info is pulled after the XRefs are created and matched.
return;
}

IAnime animeInfo = fileMatchedEvent.AnimeInfo[0];
IEpisode episodeInfo = fileMatchedEvent.EpisodeInfo[0];
IShokoSeries animeInfo = fileMatchedEvent.Series[0];
IShokoEpisode episodeInfo = fileMatchedEvent.Episodes[0];

if (!_fileTracker.TryRemoveFile(fileInfo.VideoID))
{
Expand Down
2 changes: 1 addition & 1 deletion WebhookDump.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<PackageReference Include="NLog" Version="5.1.2">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Shoko.Plugin.Abstractions" Version="3.0.0-alpha1">
<PackageReference Include="Shoko.Plugin.Abstractions" Version="3.0.0-alpha11">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>
Expand Down

0 comments on commit 307c5f6

Please sign in to comment.