Skip to content

Commit

Permalink
fix: if possible, match shikimori series via MAL ID
Browse files Browse the repository at this point in the history
  • Loading branch information
tie committed Mar 4, 2024
1 parent 30790cc commit 277180e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
5 changes: 4 additions & 1 deletion Helpers/ApiCallHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,15 @@ public async Task<Anime> GetAnime(int id, string? alternativeId = null, bool get

if (anime.Related != null) {
convertedAnime.RelatedAnime = new List<RelatedAnime>();
foreach (ShikimoriRelated shikimoriRelated in anime.Related.Where(related => related.Anime != null && related.RelationEnum == null)) {
foreach (ShikimoriRelated shikimoriRelated in anime.Related.Where(related => related.Anime != null)) {
RelationType? convertedAnimeRelationType = null;
switch (shikimoriRelated.RelationEnum) {
case ShikimoriRelation.Sequel:
convertedAnimeRelationType = RelationType.Sequel;
break;
case ShikimoriRelation.Prequel:
convertedAnimeRelationType = RelationType.Prequel;
break;
case ShikimoriRelation.Sidestory:
convertedAnimeRelationType = RelationType.Side_Story;
break;
Expand Down
1 change: 1 addition & 0 deletions Models/Shikimori/ShikimoriRelated.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public ShikimoriRelation? RelationEnum {

public enum ShikimoriRelation {
Sequel,
Prequel,
Sidestory,
Alternativeversion
}
15 changes: 9 additions & 6 deletions UpdateProviderStatus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,19 +220,22 @@ await CheckUserListAnimeStatus(_apiIds, _animeType == typeof(Episode)
break;
}

var animeType = _animeType == typeof(Episode) ? "series" : "movie";
var searchTitle = _animeType == typeof(Episode) ? episode.SeriesName : video.Name;
_logger.LogInformation($"({_apiName}) Searching for {animeType}: {searchTitle}");
List<Anime> animeList = await _apiCallHelpers.SearchAnime(_animeType == typeof(Episode) ? episode.SeriesName : video.Name);
bool found = false;
if (animeList != null) {
foreach (var anime in animeList) {
var checkMalId = _apiName == ApiName.Annict || _apiName == ApiName.Shikimori;
var checkTitle = _apiName != ApiName.Annict;
var checkMalId = _apiName == ApiName.Annict ||
_apiName == ApiName.Shikimori && _apiIds.MyAnimeList != null && anime.Id > 0;
if (checkMalId && _apiIds.MyAnimeList != null && anime.Id == _apiIds.MyAnimeList ||
checkTitle && TitleCheck(anime, episode, movie)) {
_logger.LogInformation($"({_apiName}) Found matching {(_animeType == typeof(Episode) ? "series" : "movie")}: {GetAnimeTitle(anime)}");
!checkMalId && TitleCheck(anime, episode, movie)) {
_logger.LogInformation($"({_apiName}) Found matching {animeType}: {GetAnimeTitle(anime)}");
Anime matchingAnime = anime;
if (_animeType == typeof(Episode)) {
int episodeNumber = episode.IndexNumber.Value;
if (_apiName != ApiName.Annict) {
if (!checkMalId) {
// should have already found the appropriate series/season/movie, no need to do other checks
if (episode?.Season.IndexNumber is > 1) {
// if this is not the first season, then we need to lookup the related season.
Expand Down Expand Up @@ -727,7 +730,7 @@ private async Task<Anime> GetDifferentSeasonAnime(int animeId, int seasonNumber,
initialSeason = nextSeason;
}
} else {
_logger.LogInformation($"({_apiName}) Could not find any related anime");
_logger.LogInformation($"({_apiName}) Could not find any related anime sequel");
return null;
}

Expand Down

0 comments on commit 277180e

Please sign in to comment.