Skip to content

Commit

Permalink
feat: basic auto-scheduling of tmdb data updates
Browse files Browse the repository at this point in the history
when any linked anidb anime gets new files or episodes changes.
  • Loading branch information
revam committed Sep 16, 2024
1 parent dd7d684 commit 270ba2c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -886,9 +886,16 @@ public async Task<bool> UpdateShow(int showId, bool forceRefresh = false, bool d
// Abort if we're within a certain time frame as to not try and get us rate-limited.
var tmdbShow = _tmdbShows.GetByTmdbShowID(showId) ?? new(showId);
var newlyAdded = tmdbShow.CreatedAt == tmdbShow.LastUpdatedAt;
var xrefs = _xrefAnidbTmdbShows.GetByTmdbShowID(showId);
if (!forceRefresh && tmdbShow.CreatedAt != tmdbShow.LastUpdatedAt && tmdbShow.LastUpdatedAt > DateTime.Now.AddHours(-1))
{
_logger.LogInformation("Skipping update of show {ShowID} as it was last updated {LastUpdatedAt}", showId, tmdbShow.LastUpdatedAt);

// Do the auto-matching if we're not doing a quick refresh.
if (!quickRefresh)
foreach (var xref in xrefs)
_linkingService.MatchAnidbToTmdbEpisodes(xref.AnidbAnimeID, xref.TmdbShowID, null, true, true);

return false;
}

Expand All @@ -902,8 +909,6 @@ public async Task<bool> UpdateShow(int showId, bool forceRefresh = false, bool d
var settings = _settingsProvider.GetSettings();
var preferredTitleLanguages = settings.TMDB.DownloadAllTitles ? null : Languages.PreferredNamingLanguages.Select(a => a.Language).ToHashSet();
var preferredOverviewLanguages = settings.TMDB.DownloadAllOverviews ? null : Languages.PreferredDescriptionNamingLanguages.Select(a => a.Language).ToHashSet();

var xrefs = _xrefAnidbTmdbShows.GetByTmdbShowID(showId);
var shouldFireEvents = !quickRefresh || xrefs.Count > 0;
var updated = tmdbShow.Populate(show);
var (titlesUpdated, overviewsUpdated) = UpdateTitlesAndOverviewsWithTuple(tmdbShow, show.Translations, preferredTitleLanguages, preferredOverviewLanguages);
Expand Down
4 changes: 4 additions & 0 deletions Shoko.Server/Scheduling/Jobs/AniDB/GetAniDBAnimeJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,10 @@ await scheduler.StartJob<GetAniDBAnimeJob>(c =>

foreach (var video in videos)
await scheduler.StartJob<RenameMoveFileJob>(job => job.VideoLocalID = video.VideoLocalID).ConfigureAwait(false);

if (isNew || animeEpisodeChanges.Count > 0)
foreach (var xref in anime.TmdbShowCrossReferences)
await scheduler.StartJob<UpdateTmdbShowJob>(job => job.TmdbShowID = xref.TmdbShowID).ConfigureAwait(false);
}

await ProcessRelations(response).ConfigureAwait(false);
Expand Down
5 changes: 5 additions & 0 deletions Shoko.Server/Scheduling/Jobs/Shoko/ProcessFileJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Shoko.Server.Scheduling.Concurrency;
using Shoko.Server.Scheduling.Jobs.Actions;
using Shoko.Server.Scheduling.Jobs.AniDB;
using Shoko.Server.Scheduling.Jobs.TMDB;
using Shoko.Server.Services;
using Shoko.Server.Settings;
using Shoko.Server.Utilities;
Expand Down Expand Up @@ -311,6 +312,10 @@ await scheduler.StartJob<GetAniDBAnimeJob>(c =>
c.DownloadRelations = _settings.AutoGroupSeries || _settings.AniDb.DownloadRelatedAnime;
}).ConfigureAwait(false);
}

var tmdbShowXrefs = RepoFactory.CrossRef_AniDB_TMDB_Show.GetByAnidbAnimeID(animeID);
foreach (var xref in tmdbShowXrefs)
await scheduler.StartJob<UpdateTmdbShowJob>(job => job.TmdbShowID = xref.TmdbShowID).ConfigureAwait(false);
}
}

Expand Down

0 comments on commit 270ba2c

Please sign in to comment.