Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
kookxiang committed Sep 29, 2021
1 parent e7dcf23 commit 264f674
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 11 deletions.
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Bangumi/API/Character.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ internal class Character
[JsonIgnore]
public string Name => Plugin.Instance.Configuration.TranslationPreference switch
{
TranslationPreferenceType.Chinese => ChineseName,
TranslationPreferenceType.Chinese => string.IsNullOrEmpty(ChineseName) ? OriginalName : ChineseName,
TranslationPreferenceType.Original => OriginalName,
_ => OriginalName
};
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Bangumi/API/Episode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ internal class Episode
[JsonIgnore]
public string Name => Plugin.Instance.Configuration.TranslationPreference switch
{
TranslationPreferenceType.Chinese => ChineseName,
TranslationPreferenceType.Chinese => string.IsNullOrEmpty(ChineseName) ? OriginalName : ChineseName,
TranslationPreferenceType.Original => OriginalName,
_ => OriginalName
};
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Bangumi/API/Staff.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal class Staff
[JsonIgnore]
public string Name => Plugin.Instance.Configuration.TranslationPreference switch
{
TranslationPreferenceType.Chinese => ChineseName,
TranslationPreferenceType.Chinese => string.IsNullOrEmpty(ChineseName) ? OriginalName : ChineseName,
TranslationPreferenceType.Original => OriginalName,
_ => OriginalName
};
Expand Down
2 changes: 1 addition & 1 deletion Jellyfin.Plugin.Bangumi/API/Subject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ internal class Subject : StatusCode
[JsonIgnore]
public string Name => Plugin.Instance.Configuration.TranslationPreference switch
{
TranslationPreferenceType.Chinese => ChineseName,
TranslationPreferenceType.Chinese => string.IsNullOrEmpty(ChineseName) ? OriginalName : ChineseName,
TranslationPreferenceType.Original => OriginalName,
_ => OriginalName
};
Expand Down
29 changes: 22 additions & 7 deletions Jellyfin.Plugin.Bangumi/Providers/EpisodeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,31 @@ public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, Cancell
token.ThrowIfCancellationRequested();
var result = new MetadataResult<Episode>();

var fileName = Path.GetFileName(info.Path);
if (string.IsNullOrEmpty(fileName))
return result;

var seriesId = info.SeriesProviderIds?.GetValueOrDefault(Constants.ProviderName);
if (string.IsNullOrEmpty(seriesId))
return result;

var episodeListData = await Api.GetEpisodeList(seriesId, token);
if (episodeListData?.Episodes == null)
return result;

var episodeIndex = info.IndexNumber;
if (episodeIndex == null)
if (episodeIndex > 2 * episodeListData.EpisodeCount)
{
var fileName = Path.GetFileName(info.Path);
if (string.IsNullOrEmpty(fileName))
return result;
_log.LogWarning($"file {fileName} has incorrect episode index {episodeIndex}, reset to null");
episodeIndex = null;
}
else if (episodeIndex > episodeListData.EpisodeCount)
{
_log.LogWarning($"file {fileName} may have incorrect episode index {episodeIndex}");
}

if (episodeIndex == null)
{
foreach (var regex in EpisodeFileNameRegex)
{
if (!regex.IsMatch(fileName))
Expand All @@ -64,10 +78,11 @@ public async Task<MetadataResult<Episode>> GetMetadata(EpisodeInfo info, Cancell

_log.LogInformation($"use episode number {episodeIndex} from file name {fileName}");
}
else
{
_log.LogInformation($"use exists episode number {episodeIndex} from file name {fileName}");
}

var episodeListData = await Api.GetEpisodeList(seriesId, token);
if (episodeListData?.Episodes == null)
return result;

var episode = info.ProviderIds?.ContainsKey(Constants.ProviderName) == true
? episodeListData.Episodes.Find(x => $"{x.Id}" == info.ProviderIds[Constants.ProviderName])
Expand Down

0 comments on commit 264f674

Please sign in to comment.