mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-07-19 04:34:18 +01:00
fixes #795 - Support reading Xbmc nfo's
This commit is contained in:
34
MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs
Normal file
34
MediaBrowser.XbmcMetadata/Providers/AlbumNfoProvider.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.XbmcMetadata.Parsers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class AlbumNfoProvider : BaseNfoProvider<MusicAlbum>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public AlbumNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected override void Fetch(LocalMetadataResult<MusicAlbum> result, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
new BaseNfoParser<MusicAlbum>(_logger, _config).Fetch(result.Item, path, cancellationToken);
|
||||
}
|
||||
|
||||
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||
{
|
||||
return directoryService.GetFile(Path.Combine(info.Path, "album.nfo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
34
MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs
Normal file
34
MediaBrowser.XbmcMetadata/Providers/ArtistNfoProvider.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities.Audio;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.XbmcMetadata.Parsers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class ArtistNfoProvider : BaseNfoProvider<MusicArtist>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public ArtistNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected override void Fetch(LocalMetadataResult<MusicArtist> result, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
new BaseNfoParser<MusicArtist>(_logger, _config).Fetch(result.Item, path, cancellationToken);
|
||||
}
|
||||
|
||||
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||
{
|
||||
return directoryService.GetFile(Path.Combine(info.Path, "artist.nfo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
89
MediaBrowser.XbmcMetadata/Providers/BaseNfoProvider.cs
Normal file
89
MediaBrowser.XbmcMetadata/Providers/BaseNfoProvider.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public abstract class BaseNfoProvider<T> : ILocalMetadataProvider<T>, IHasChangeMonitor
|
||||
where T : IHasMetadata, new()
|
||||
{
|
||||
protected IFileSystem FileSystem;
|
||||
|
||||
public async Task<LocalMetadataResult<T>> GetMetadata(ItemInfo info, CancellationToken cancellationToken)
|
||||
{
|
||||
var result = new LocalMetadataResult<T>();
|
||||
|
||||
var file = GetXmlFile(info, new DirectoryService(new NullLogger()));
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
|
||||
var path = file.FullName;
|
||||
|
||||
await XmlProviderUtils.XmlParsingResourcePool.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
try
|
||||
{
|
||||
result.Item = new T();
|
||||
|
||||
Fetch(result, path, cancellationToken);
|
||||
result.HasMetadata = true;
|
||||
}
|
||||
catch (FileNotFoundException)
|
||||
{
|
||||
result.HasMetadata = false;
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
result.HasMetadata = false;
|
||||
}
|
||||
finally
|
||||
{
|
||||
XmlProviderUtils.XmlParsingResourcePool.Release();
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
protected abstract void Fetch(LocalMetadataResult<T> result, string path, CancellationToken cancellationToken);
|
||||
|
||||
protected BaseNfoProvider(IFileSystem fileSystem)
|
||||
{
|
||||
FileSystem = fileSystem;
|
||||
}
|
||||
|
||||
protected abstract FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService);
|
||||
|
||||
public bool HasChanged(IHasMetadata item, IDirectoryService directoryService, DateTime date)
|
||||
{
|
||||
var file = GetXmlFile(new ItemInfo { IsInMixedFolder = item.IsInMixedFolder, Path = item.Path }, directoryService);
|
||||
|
||||
if (file == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return file.Exists && FileSystem.GetLastWriteTimeUtc(file) > date;
|
||||
}
|
||||
|
||||
public string Name
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Xbmc Nfo";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static class XmlProviderUtils
|
||||
{
|
||||
internal static readonly SemaphoreSlim XmlParsingResourcePool = new SemaphoreSlim(4, 4);
|
||||
}
|
||||
}
|
||||
55
MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs
Normal file
55
MediaBrowser.XbmcMetadata/Providers/BaseVideoNfoProvider.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.XbmcMetadata.Parsers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class BaseVideoNfoProvider<T> : BaseNfoProvider<T>
|
||||
where T : Video, new ()
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public BaseVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected override void Fetch(LocalMetadataResult<T> result, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var chapters = new List<ChapterInfo>();
|
||||
|
||||
new MovieNfoParser(_logger, _config).Fetch(result.Item, chapters, path, cancellationToken);
|
||||
|
||||
result.Chapters = chapters;
|
||||
}
|
||||
|
||||
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||
{
|
||||
var path = GetMovieSavePath(info);
|
||||
|
||||
return directoryService.GetFile(path);
|
||||
}
|
||||
|
||||
public static string GetMovieSavePath(ItemInfo item)
|
||||
{
|
||||
if (Directory.Exists(item.Path))
|
||||
{
|
||||
var path = item.Path;
|
||||
|
||||
return Path.Combine(path, Path.GetFileNameWithoutExtension(path) + ".nfo");
|
||||
}
|
||||
|
||||
return Path.ChangeExtension(item.Path, ".nfo");
|
||||
}
|
||||
}
|
||||
}
|
||||
44
MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs
Normal file
44
MediaBrowser.XbmcMetadata/Providers/EpisodeNfoProvider.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.XbmcMetadata.Parsers;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class EpisodeNfoProvider : BaseNfoProvider<Episode>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public EpisodeNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected override void Fetch(LocalMetadataResult<Episode> result, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
var images = new List<LocalImageInfo>();
|
||||
var chapters = new List<ChapterInfo>();
|
||||
|
||||
new EpisodeNfoParser(_logger, _config).Fetch(result.Item, images, chapters, path, cancellationToken);
|
||||
|
||||
result.Images = images;
|
||||
result.Chapters = chapters;
|
||||
}
|
||||
|
||||
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||
{
|
||||
var path = Path.ChangeExtension(info.Path, ".nfo");
|
||||
|
||||
return directoryService.GetFile(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
45
MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs
Normal file
45
MediaBrowser.XbmcMetadata/Providers/MovieNfoProvider.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.Entities.Movies;
|
||||
using MediaBrowser.Model.Logging;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class MovieNfoProvider : BaseVideoNfoProvider<Movie>
|
||||
{
|
||||
public MovieNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class MusicVideoNfoProvider : BaseVideoNfoProvider<MusicVideo>
|
||||
{
|
||||
public MusicVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class AdultVideoNfoProvider : BaseVideoNfoProvider<AdultVideo>
|
||||
{
|
||||
public AdultVideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class VideoNfoProvider : BaseVideoNfoProvider<Video>
|
||||
{
|
||||
public VideoNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config) : base(fileSystem, logger, config)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
public class TrailerNfoProvider : BaseVideoNfoProvider<Trailer>
|
||||
{
|
||||
public TrailerNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem, logger, config)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
35
MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs
Normal file
35
MediaBrowser.XbmcMetadata/Providers/SeasonNfoProvider.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.XbmcMetadata.Parsers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class SeasonNfoProvider : BaseNfoProvider<Season>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public SeasonNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected override void Fetch(LocalMetadataResult<Season> result, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
new SeasonNfoParser(_logger, _config).Fetch(result.Item, path, cancellationToken);
|
||||
}
|
||||
|
||||
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||
{
|
||||
return directoryService.GetFile(Path.Combine(info.Path, "season.nfo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
34
MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs
Normal file
34
MediaBrowser.XbmcMetadata/Providers/SeriesNfoProvider.cs
Normal file
@@ -0,0 +1,34 @@
|
||||
using MediaBrowser.Common.Configuration;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.Providers;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MediaBrowser.XbmcMetadata.Parsers;
|
||||
using System.IO;
|
||||
using System.Threading;
|
||||
|
||||
namespace MediaBrowser.XbmcMetadata.Providers
|
||||
{
|
||||
public class SeriesNfoProvider : BaseNfoProvider<Series>
|
||||
{
|
||||
private readonly ILogger _logger;
|
||||
private readonly IConfigurationManager _config;
|
||||
|
||||
public SeriesNfoProvider(IFileSystem fileSystem, ILogger logger, IConfigurationManager config)
|
||||
: base(fileSystem)
|
||||
{
|
||||
_logger = logger;
|
||||
_config = config;
|
||||
}
|
||||
|
||||
protected override void Fetch(LocalMetadataResult<Series> result, string path, CancellationToken cancellationToken)
|
||||
{
|
||||
new SeriesNfoParser(_logger, _config).Fetch(result.Item, path, cancellationToken);
|
||||
}
|
||||
|
||||
protected override FileSystemInfo GetXmlFile(ItemInfo info, IDirectoryService directoryService)
|
||||
{
|
||||
return directoryService.GetFile(Path.Combine(info.Path, "series.nfo"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user