Skip to content

Commit

Permalink
Fix References to AniDBTitleHelper
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Mar 12, 2024
1 parent d98b506 commit 9c0ae92
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using Shoko.Server.Models;
using Shoko.Server.Providers.AniDB.HTTP;
using Shoko.Server.Providers.AniDB.Interfaces;
using Shoko.Server.Providers.AniDB.Titles;
using Shoko.Server.Repositories;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.AniDB;
Expand Down Expand Up @@ -648,7 +649,8 @@ public List<CL_AnimeSearch> OnlineAnimeTitleSearch(string titleQuery)
else
{
// title search so look at the web cache
foreach (var tit in Utils.AniDBTitleHelper.SearchTitle(HttpUtility.UrlDecode(titleQuery)))
var titleHelper = Utils.ServiceContainer.GetRequiredService<AniDBTitleHelper>();
foreach (var tit in titleHelper.SearchTitle(HttpUtility.UrlDecode(titleQuery)))
{
var res = new CL_AnimeSearch
{
Expand Down
14 changes: 7 additions & 7 deletions Shoko.Server/API/v3/Controllers/SeriesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
using Shoko.Server.API.v3.Models.Common;
using Shoko.Server.API.v3.Models.Shoko;
using Shoko.Server.Models;
using Shoko.Server.Providers.AniDB.Interfaces;
using Shoko.Server.Providers.TvDB;
using Shoko.Server.Repositories;
using Shoko.Server.Settings;
Expand All @@ -31,6 +30,7 @@
using AniDBEpisodeType = Shoko.Models.Enums.EpisodeType;
using DataSource = Shoko.Server.API.v3.Models.Common.DataSource;
using Quartz;
using Shoko.Server.Providers.AniDB.Titles;
using Shoko.Server.Scheduling;
using Shoko.Server.Scheduling.Jobs.Shoko;

Expand All @@ -42,17 +42,17 @@ namespace Shoko.Server.API.v3.Controllers;
[Authorize]
public class SeriesController : BaseController
{
private readonly AniDBTitleHelper _titleHelper;
private readonly SeriesFactory _seriesFactory;
private readonly IHttpConnectionHandler _httpHandler;
private readonly ISchedulerFactory _schedulerFactory;
private readonly JobFactory _jobFactory;

public SeriesController(IHttpConnectionHandler httpHandler, ISettingsProvider settingsProvider, SeriesFactory seriesFactory, ISchedulerFactory schedulerFactory, JobFactory jobFactory) : base(settingsProvider)
public SeriesController(ISettingsProvider settingsProvider, SeriesFactory seriesFactory, ISchedulerFactory schedulerFactory, JobFactory jobFactory, AniDBTitleHelper titleHelper) : base(settingsProvider)
{
_httpHandler = httpHandler;
_seriesFactory = seriesFactory;
_schedulerFactory = schedulerFactory;
_jobFactory = jobFactory;
_titleHelper = titleHelper;
}

#region Return messages
Expand Down Expand Up @@ -1928,7 +1928,7 @@ [FromQuery] [Range(1, int.MaxValue)] int page = 1)
}

// Check the title cache for a match.
var result = Utils.AniDBTitleHelper.SearchAnimeID(animeID);
var result = _titleHelper.SearchAnimeID(animeID);
if (result != null)
{
return new ListResult<Series.AniDB>(1,
Expand All @@ -1940,7 +1940,7 @@ [FromQuery] [Range(1, int.MaxValue)] int page = 1)

// Return all known entries on anidb if no query is given.
if (string.IsNullOrEmpty(query))
return Utils.AniDBTitleHelper.GetAll()
return _titleHelper.GetAll()
.OrderBy(anime => anime.AnimeID)
.Select(result =>
{
Expand All @@ -1956,7 +1956,7 @@ [FromQuery] [Range(1, int.MaxValue)] int page = 1)
.ToListResult(page, pageSize);

// Search the title cache for anime matching the query.
return Utils.AniDBTitleHelper.SearchTitle(query, fuzzy)
return _titleHelper.SearchTitle(query, fuzzy)
.Select(result =>
{
var series = RepoFactory.AnimeSeries.GetByAnimeID(result.AnimeID);
Expand Down
8 changes: 5 additions & 3 deletions Shoko.Server/API/v3/Helpers/SeriesFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public class SeriesFactory
{
private readonly HttpContext _context;
private readonly CrossRef_Anime_StaffRepository _crossRefAnimeStaffRepository;
private readonly AniDBTitleHelper _titleHelper;
private readonly AnimeCharacterRepository _animeCharacterRepository;
private readonly AnimeStaffRepository _animeStaffRepository;
private readonly CustomTagRepository _customTagRepository;
Expand All @@ -37,10 +38,11 @@ public class SeriesFactory
private readonly ISchedulerFactory _schedulerFactory;
private readonly JobFactory _jobFactory;

public SeriesFactory(IHttpContextAccessor context, ISchedulerFactory schedulerFactory, JobFactory jobFactory)
public SeriesFactory(IHttpContextAccessor context, ISchedulerFactory schedulerFactory, JobFactory jobFactory, AniDBTitleHelper titleHelper)
{
_schedulerFactory = schedulerFactory;
_jobFactory = jobFactory;
_titleHelper = titleHelper;
_context = context.HttpContext;
_crossRefAnimeStaffRepository = RepoFactory.CrossRef_Anime_Staff;
_animeCharacterRepository = RepoFactory.AnimeCharacter;
Expand Down Expand Up @@ -560,7 +562,7 @@ private void SetAniDBTitles(Series.AniDB aniDB, AniDB_Anime_Relation relation, S
return;
}

var result = Utils.AniDBTitleHelper.SearchAnimeID(relation.RelatedAnimeID);
var result = _titleHelper.SearchAnimeID(relation.RelatedAnimeID);
if (result != null)
{
aniDB.Type = SeriesType.Unknown;
Expand Down Expand Up @@ -637,7 +639,7 @@ private void SetAniDBTitles(Series.AniDB aniDB, AniDB_Anime_Similar similar, SVR
return;
}

var result = Utils.AniDBTitleHelper.SearchAnimeID(similar.SimilarAnimeID);
var result = _titleHelper.SearchAnimeID(similar.SimilarAnimeID);
if (result != null)
{
aniDB.Type = SeriesType.Unknown;
Expand Down
2 changes: 2 additions & 0 deletions Shoko.Server/Providers/AniDB/AniDBStartup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Microsoft.Extensions.DependencyInjection;
using Shoko.Server.Providers.AniDB.HTTP;
using Shoko.Server.Providers.AniDB.Interfaces;
using Shoko.Server.Providers.AniDB.Titles;
using Shoko.Server.Providers.AniDB.UDP;

namespace Shoko.Server.Providers.AniDB;
Expand All @@ -13,6 +14,7 @@ public static IServiceCollection AddAniDB(this IServiceCollection services)
{
services.AddSingleton<HttpAnimeParser>();
services.AddSingleton<ImageHttpClientFactory>();
services.AddSingleton<AniDBTitleHelper>();
services.AddSingleton<AnimeCreator>();
services.AddSingleton<HttpXmlUtils>();
services.AddSingleton<UDPRateLimiter>();
Expand Down
5 changes: 0 additions & 5 deletions Shoko.Server/Utilities/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ namespace Shoko.Server.Utilities;

public static class Utils
{
private static AniDBTitleHelper s_aniDBTitleHelper;
public static ShokoServer ShokoServer { get; set; }
public static IServiceProvider ServiceContainer { get; set; }
public static ISettingsProvider SettingsProvider { get; set; }

public static AniDBTitleHelper AniDBTitleHelper
{
get => s_aniDBTitleHelper ??= new AniDBTitleHelper(ServiceContainer.GetRequiredService<ISettingsProvider>());
}
private static string _applicationPath { get; set; } = null;
public static string ApplicationPath
{
Expand Down

0 comments on commit 9c0ae92

Please sign in to comment.