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
|
#nullable disable
|
||||||
|
|
||||||
#pragma warning disable CS1591
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
@ -18,12 +16,14 @@ using MediaBrowser.Model.IO;
|
|||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using PlaylistsNET.Content;
|
using PlaylistsNET.Content;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Playlists
|
namespace MediaBrowser.Providers.Playlists;
|
||||||
{
|
|
||||||
public class PlaylistItemsProvider : ICustomMetadataProvider<Playlist>,
|
/// <summary>
|
||||||
|
/// Local playlist provider.
|
||||||
|
/// </summary>
|
||||||
|
public class PlaylistItemsProvider : ILocalMetadataProvider<Playlist>,
|
||||||
IHasOrder,
|
IHasOrder,
|
||||||
IForcedProvider,
|
IForcedProvider,
|
||||||
IPreRefreshProvider,
|
|
||||||
IHasItemChangeMonitor
|
IHasItemChangeMonitor
|
||||||
{
|
{
|
||||||
private readonly IFileSystem _fileSystem;
|
private readonly IFileSystem _fileSystem;
|
||||||
@ -31,6 +31,12 @@ namespace MediaBrowser.Providers.Playlists
|
|||||||
private readonly ILogger<PlaylistItemsProvider> _logger;
|
private readonly ILogger<PlaylistItemsProvider> _logger;
|
||||||
private readonly CollectionType[] _ignoredCollections = [CollectionType.livetv, CollectionType.boxsets, CollectionType.playlists];
|
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)
|
public PlaylistItemsProvider(ILogger<PlaylistItemsProvider> logger, ILibraryManager libraryManager, IFileSystem fileSystem)
|
||||||
{
|
{
|
||||||
_logger = logger;
|
_logger = logger;
|
||||||
@ -38,30 +44,53 @@ namespace MediaBrowser.Providers.Playlists
|
|||||||
_fileSystem = fileSystem;
|
_fileSystem = fileSystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string Name => "Playlist Reader";
|
/// <inheritdoc />
|
||||||
|
public string Name => "Playlist Item Provider";
|
||||||
|
|
||||||
// Run last
|
/// <inheritdoc />
|
||||||
public int Order => 100;
|
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;
|
var path = item.Path;
|
||||||
if (!Playlist.IsPlaylistFile(path))
|
if (!Playlist.IsPlaylistFile(path))
|
||||||
{
|
{
|
||||||
return Task.FromResult(ItemUpdateType.None);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var extension = Path.GetExtension(path);
|
var extension = Path.GetExtension(path);
|
||||||
if (!Playlist.SupportedExtensions.Contains(extension ?? string.Empty, StringComparison.OrdinalIgnoreCase))
|
if (!Playlist.SupportedExtensions.Contains(extension ?? string.Empty, StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
return Task.FromResult(ItemUpdateType.None);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = GetItems(path, extension).ToArray();
|
var items = GetItems(path, extension).ToArray();
|
||||||
|
if (items.Length > 0)
|
||||||
|
{
|
||||||
|
result.HasMetadata = true;
|
||||||
item.LinkedChildren = items;
|
item.LinkedChildren = items;
|
||||||
|
}
|
||||||
|
|
||||||
return Task.FromResult(ItemUpdateType.MetadataImport);
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
private IEnumerable<LinkedChild> GetItems(string path, string extension)
|
private IEnumerable<LinkedChild> GetItems(string path, string extension)
|
||||||
@ -179,10 +208,10 @@ namespace MediaBrowser.Providers.Playlists
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
public bool HasChanged(BaseItem item, IDirectoryService directoryService)
|
||||||
{
|
{
|
||||||
var path = item.Path;
|
var path = item.Path;
|
||||||
|
|
||||||
if (!string.IsNullOrWhiteSpace(path) && item.IsFileProtocol)
|
if (!string.IsNullOrWhiteSpace(path) && item.IsFileProtocol)
|
||||||
{
|
{
|
||||||
var file = directoryService.GetFile(path);
|
var file = directoryService.GetFile(path);
|
||||||
@ -196,4 +225,3 @@ namespace MediaBrowser.Providers.Playlists
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user