Merge pull request #7 from cxfksword/dandan

Optimize identity
This commit is contained in:
cxfksword
2023-01-07 16:06:48 +08:00
committed by GitHub
3 changed files with 48 additions and 29 deletions

View File

@@ -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<LibraryEvent>(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<LibraryEvent>(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<BaseItem> 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);
}

View File

@@ -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
}
/// <summary>
/// Library item was removed.
/// </summary>
/// <param name="sender">The sending entity.</param>
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
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);
}
/// <summary>
/// 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);
}
/// <summary>
/// Library item was removed.
/// </summary>
/// <param name="sender">The sending entity.</param>
/// <param name="itemChangeEventArgs">The <see cref="ItemChangeEventArgs"/>.</param>
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);
}
/// <inheritdoc />
public void Dispose()
{

View File

@@ -24,7 +24,7 @@ namespace Jellyfin.Plugin.Danmu.Scrapers.Dandan.ExternalId
public ExternalIdMediaType? Type => null;
/// <inheritdoc />
public string UrlFormatString => "#";
public string UrlFormatString => "https://api.dandanplay.net/api/v2/bangumi/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Season;