diff --git a/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs b/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs index 99d0266..a559793 100644 --- a/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs +++ b/Jellyfin.Plugin.Danmu/LibraryManagerEventsHelper.cs @@ -166,9 +166,21 @@ public class LibraryManagerEventsHelper : IDisposable queuedMovieUpdates.Add(ev); } break; + case Series when ev.EventType is EventType.Add: + _logger.LogInformation("Series add: {0}", ev.Item.Name); + _pendingAddEventCache.Set(ev.Item.Id, ev, _expiredOption); + break; case Series when ev.EventType is EventType.Update: _logger.LogInformation("Series update: {0}", ev.Item.Name); - queuedShowUpdates.Add(ev); + if (_pendingAddEventCache.TryGetValue(ev.Item.Id, out LibraryEvent addSerieEv)) + { + // 紧跟add事件的update事件不需要处理 + _pendingAddEventCache.Remove(ev.Item.Id); + } + else + { + queuedShowUpdates.Add(ev); + } break; case Season when ev.EventType is EventType.Add: _logger.LogInformation("Season add: {0}", ev.Item.Name); @@ -578,7 +590,7 @@ public class LibraryManagerEventsHelper : IDisposable // 调用UpdateToRepositoryAsync后,但未完成时,会导致GetEpisodes返回缺少正在处理的集数,所以采用统一最后处理 private async Task ProcessQueuedUpdateMeta(List queue) { - if (queue.Count <= 0) + if (queue == null || queue.Count <= 0) { return; } @@ -587,14 +599,17 @@ public class LibraryManagerEventsHelper : IDisposable { // 获取最新的item数据 var item = _libraryManager.GetItemById(queueItem.Id); - // 合并新添加的provider id - foreach (var pair in queueItem.ProviderIds) + if (item != null) { - item.ProviderIds[pair.Key] = pair.Value; - } + // 合并新添加的provider id + foreach (var pair in queueItem.ProviderIds) + { + item.ProviderIds[pair.Key] = pair.Value; + } - // Console.WriteLine(JsonSerializer.Serialize(item)); - await item.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); + // Console.WriteLine(JsonSerializer.Serialize(item)); + await item.UpdateToRepositoryAsync(ItemUpdateType.MetadataEdit, CancellationToken.None).ConfigureAwait(false); + } } _logger.LogInformation("更新epid到元数据完成。item数:{0}", queue.Count); } diff --git a/Jellyfin.Plugin.Danmu/PluginStartup.cs b/Jellyfin.Plugin.Danmu/PluginStartup.cs index 14c20a1..dbfde1c 100644 --- a/Jellyfin.Plugin.Danmu/PluginStartup.cs +++ b/Jellyfin.Plugin.Danmu/PluginStartup.cs @@ -16,6 +16,7 @@ using MediaBrowser.Controller.Entities.Movies; using MediaBrowser.Controller.Entities.TV; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Providers; +using Jellyfin.Plugin.Danmu.Core.Extensions; namespace Jellyfin.Plugin.Danmu { @@ -56,25 +57,7 @@ namespace Jellyfin.Plugin.Danmu } - /// - /// Library item was removed. - /// - /// The sending entity. - /// The . - private void LibraryManagerItemRemoved(object sender, ItemChangeEventArgs itemChangeEventArgs) - { - if (itemChangeEventArgs.Item is not Movie and not Episode and not Series and not Season) - { - return; - } - if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual) - { - return; - } - - _libraryManagerEventsHelper.QueueItem(itemChangeEventArgs.Item, EventType.Remove); - } /// /// Library item was added. @@ -89,7 +72,8 @@ namespace Jellyfin.Plugin.Danmu return; } - if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual) + // 当剧集没有SXX/Season XX季文件夹时,LocationType就是Virtual,动画经常没有季文件夹 + if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual && itemChangeEventArgs.Item is not Season) { return; } @@ -111,7 +95,7 @@ namespace Jellyfin.Plugin.Danmu return; } - if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual) + if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual && itemChangeEventArgs.Item is not Season) { return; } @@ -119,6 +103,26 @@ namespace Jellyfin.Plugin.Danmu _libraryManagerEventsHelper.QueueItem(itemChangeEventArgs.Item, EventType.Update); } + /// + /// Library item was removed. + /// + /// The sending entity. + /// The . + private void LibraryManagerItemRemoved(object sender, ItemChangeEventArgs itemChangeEventArgs) + { + if (itemChangeEventArgs.Item is not Movie and not Episode and not Series and not Season) + { + return; + } + + if (itemChangeEventArgs.Item.LocationType == LocationType.Virtual) + { + return; + } + + _libraryManagerEventsHelper.QueueItem(itemChangeEventArgs.Item, EventType.Remove); + } + /// public void Dispose() { diff --git a/Jellyfin.Plugin.Danmu/Scrapers/Dandan/ExternalId/SeasonExternalId.cs b/Jellyfin.Plugin.Danmu/Scrapers/Dandan/ExternalId/SeasonExternalId.cs index 2519921..0c0b41e 100644 --- a/Jellyfin.Plugin.Danmu/Scrapers/Dandan/ExternalId/SeasonExternalId.cs +++ b/Jellyfin.Plugin.Danmu/Scrapers/Dandan/ExternalId/SeasonExternalId.cs @@ -24,7 +24,7 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Dandan.ExternalId public ExternalIdMediaType? Type => null; /// - public string UrlFormatString => "#"; + public string UrlFormatString => "https://api.dandanplay.net/api/v2/bangumi/{0}"; /// public bool Supports(IHasProviderIds item) => item is Season;