mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-07-09 03:04:24 -04:00
Merge pull request #12053 from Shadowghost/fix-local-playlist-scanning
Rewrite PlaylistItemsProvider as ILocalMetadataProvider
This commit is contained in:
commit
cbbe5db813
@ -1,7 +1,5 @@
|
||||
#nullable disable
|
||||
|
||||
#pragma warning disable CS1591
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
@ -18,19 +16,27 @@ using MediaBrowser.Model.IO;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using PlaylistsNET.Content;
|
||||
|
||||
namespace MediaBrowser.Providers.Playlists
|
||||
{
|
||||
public class PlaylistItemsProvider : ICustomMetadataProvider<Playlist>,
|
||||
namespace MediaBrowser.Providers.Playlists;
|
||||
|
||||
/// <summary>
|
||||
/// Local playlist provider.
|
||||
/// </summary>
|
||||
public class PlaylistItemsProvider : ILocalMetadataProvider<Playlist>,
|
||||
IHasOrder,
|
||||
IForcedProvider,
|
||||
IPreRefreshProvider,
|
||||
IHasItemChangeMonitor
|
||||
{
|
||||
{
|
||||
private readonly IFileSystem _fileSystem;
|
||||
private readonly ILibraryManager _libraryManager;
|
||||
private readonly ILogger<PlaylistItemsProvider> _logger;
|
||||
private readonly CollectionType[] _ignoredCollections = [CollectionType.livetv, CollectionType.boxsets, CollectionType.playlists];
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PlaylistItemsProvider"/> class.
|
||||
/// </summary>
|
||||
/// <param name="logger">Instance of the <see cref="ILogger{PlaylistItemsProvider}"/> interface.</param>
|
||||
/// <param name="libraryManager">Instance of the <see cref="ILibraryManager"/> interface.</param>
|
||||
/// <param name="fileSystem">Instance of the <see cref="IFileSystem"/> interface.</param>
|
||||
public PlaylistItemsProvider(ILogger<PlaylistItemsProvider> logger, ILibraryManager libraryManager, IFileSystem fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
@ -38,30 +44,53 @@ namespace MediaBrowser.Providers.Playlists
|
||||
_fileSystem = fileSystem;
|
||||
}
|
||||
|
||||
public string Name => "Playlist Reader";
|
||||
/// <inheritdoc />
|
||||
public string Name => "Playlist Item Provider";
|
||||
|
||||
// Run last
|
||||
/// <inheritdoc />
|
||||
public int Order => 100;
|
||||
|
||||
public Task<ItemUpdateType> FetchAsync(Playlist item, MetadataRefreshOptions options, CancellationToken cancellationToken)
|
||||
/// <inheritdoc />
|
||||
public Task<MetadataResult<Playlist>> GetMetadata(
|
||||
ItemInfo info,
|
||||
IDirectoryService directoryService,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new MetadataResult<Playlist>()
|
||||
{
|
||||
Item = new Playlist
|
||||
{
|
||||
Path = info.Path
|
||||
}
|
||||
};
|
||||
Fetch(result);
|
||||
|
||||
return Task.FromResult(result);
|
||||
}
|
||||
|
||||
private void Fetch(MetadataResult<Playlist> result)
|
||||
{
|
||||
var item = result.Item;
|
||||
var path = item.Path;
|
||||
if (!Playlist.IsPlaylistFile(path))
|
||||
{
|
||||
return Task.FromResult(ItemUpdateType.None);
|
||||
return;
|
||||
}
|
||||
|
||||
var extension = Path.GetExtension(path);
|
||||
if (!Playlist.SupportedExtensions.Contains(extension ?? string.Empty, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return Task.FromResult(ItemUpdateType.None);
|
||||
return;
|
||||
}
|
||||
|
||||
var items = GetItems(path, extension).ToArray();
|
||||
|
||||
if (items.Length > 0)
|
||||
{
|
||||
result.HasMetadata = true;
|
||||
item.LinkedChildren = items;
|
||||
}
|
||||
|
||||
return Task.FromResult(ItemUpdateType.MetadataImport);
|
||||
return;
|
||||
}
|
||||
|
||||
private IEnumerable<LinkedChild> GetItems(string path, string extension)
|
||||
@ -179,10 +208,10 @@ namespace MediaBrowser.Providers.Playlists
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
||||
{
|
||||
var path = item.Path;
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(path) && item.IsFileProtocol)
|
||||
{
|
||||
var file = directoryService.GetFile(path);
|
||||
@ -195,5 +224,4 @@ namespace MediaBrowser.Providers.Playlists
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user