Fix more warnings

This commit is contained in:
Bond_009 2019-09-10 22:37:53 +02:00 committed by Bond_009
parent ef623f5129
commit d9a03c9bb1
70 changed files with 787 additions and 567 deletions

View File

@ -470,7 +470,7 @@ namespace Emby.Server.Implementations.Channels
_libraryManager.CreateItem(item, null);
}
await item.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
await item.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
ForceSave = !isNew && forceUpdate
}, cancellationToken);
@ -1156,7 +1156,7 @@ namespace Emby.Server.Implementations.Channels
if (isNew || forceUpdate || item.DateLastRefreshed == default(DateTime))
{
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), RefreshPriority.Normal);
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.Normal);
}
return item;

View File

@ -149,7 +149,7 @@ namespace Emby.Server.Implementations.Collections
if (options.ItemIdList.Length > 0)
{
AddToCollection(collection.Id, options.ItemIdList, false, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
AddToCollection(collection.Id, options.ItemIdList, false, new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
// The initial adding of items is going to create a local metadata file
// This will cause internet metadata to be skipped as a result
@ -158,7 +158,7 @@ namespace Emby.Server.Implementations.Collections
}
else
{
_providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), RefreshPriority.High);
_providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.High);
}
CollectionCreated?.Invoke(this, new CollectionCreatedEventArgs
@ -178,12 +178,12 @@ namespace Emby.Server.Implementations.Collections
public void AddToCollection(Guid collectionId, IEnumerable<string> ids)
{
AddToCollection(collectionId, ids, true, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)));
AddToCollection(collectionId, ids, true, new MetadataRefreshOptions(new DirectoryService(_fileSystem)));
}
public void AddToCollection(Guid collectionId, IEnumerable<Guid> ids)
{
AddToCollection(collectionId, ids.Select(i => i.ToString("N", CultureInfo.InvariantCulture)), true, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)));
AddToCollection(collectionId, ids.Select(i => i.ToString("N", CultureInfo.InvariantCulture)), true, new MetadataRefreshOptions(new DirectoryService(_fileSystem)));
}
private void AddToCollection(Guid collectionId, IEnumerable<string> ids, bool fireEvent, MetadataRefreshOptions refreshOptions)
@ -287,7 +287,7 @@ namespace Emby.Server.Implementations.Collections
}
collection.UpdateToRepository(ItemUpdateType.MetadataEdit, CancellationToken.None);
_providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
_providerManager.QueueRefresh(collection.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
ForceSave = true
}, RefreshPriority.High);

View File

@ -54,7 +54,7 @@ namespace Emby.Server.Implementations.EntryPoints
{
cancellationToken.ThrowIfCancellationRequested();
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false);
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), cancellationToken).ConfigureAwait(false);
}
}

View File

@ -519,7 +519,7 @@ namespace Emby.Server.Implementations.Library
}
public BaseItem ResolvePath(FileSystemMetadata fileInfo, Folder parent = null)
=> ResolvePath(fileInfo, new DirectoryService(_logger, _fileSystem), null, parent);
=> ResolvePath(fileInfo, new DirectoryService(_fileSystem), null, parent);
private BaseItem ResolvePath(
FileSystemMetadata fileInfo,
@ -1045,7 +1045,7 @@ namespace Emby.Server.Implementations.Library
await RootFolder.ValidateChildren(
new SimpleProgress<double>(),
cancellationToken,
new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)),
new MetadataRefreshOptions(new DirectoryService(_fileSystem)),
recursive: false).ConfigureAwait(false);
await GetUserRootFolder().RefreshMetadata(cancellationToken).ConfigureAwait(false);
@ -1053,7 +1053,7 @@ namespace Emby.Server.Implementations.Library
await GetUserRootFolder().ValidateChildren(
new SimpleProgress<double>(),
cancellationToken,
new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)),
new MetadataRefreshOptions(new DirectoryService(_fileSystem)),
recursive: false).ConfigureAwait(false);
// Quickly scan CollectionFolders for changes
@ -1074,7 +1074,7 @@ namespace Emby.Server.Implementations.Library
innerProgress.RegisterAction(pct => progress.Report(pct * .96));
// Now validate the entire media library
await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), recursive: true).ConfigureAwait(false);
await RootFolder.ValidateChildren(innerProgress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), recursive: true).ConfigureAwait(false);
progress.Report(96);
@ -2135,7 +2135,7 @@ namespace Emby.Server.Implementations.Library
if (refresh)
{
item.UpdateToRepository(ItemUpdateType.MetadataImport, CancellationToken.None);
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), RefreshPriority.Normal);
_providerManagerFactory().QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.Normal);
}
return item;
@ -2193,7 +2193,7 @@ namespace Emby.Server.Implementations.Library
{
_providerManagerFactory().QueueRefresh(
item.Id,
new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
// Need to force save to increment DateLastSaved
ForceSave = true
@ -2261,7 +2261,7 @@ namespace Emby.Server.Implementations.Library
{
_providerManagerFactory().QueueRefresh(
item.Id,
new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
// Need to force save to increment DateLastSaved
ForceSave = true
@ -2338,7 +2338,7 @@ namespace Emby.Server.Implementations.Library
{
_providerManagerFactory().QueueRefresh(
item.Id,
new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
// Need to force save to increment DateLastSaved
ForceSave = true

View File

@ -134,12 +134,13 @@ namespace Emby.Server.Implementations.Library
if (allowMediaProbe && mediaSources[0].Type != MediaSourceType.Placeholder && !mediaSources[0].MediaStreams.Any(i => i.Type == MediaStreamType.Audio || i.Type == MediaStreamType.Video))
{
await item.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
{
EnableRemoteContentProbe = true,
MetadataRefreshMode = MediaBrowser.Controller.Providers.MetadataRefreshMode.FullRefresh
}, cancellationToken).ConfigureAwait(false);
await item.RefreshMetadata(
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
EnableRemoteContentProbe = true,
MetadataRefreshMode = MetadataRefreshMode.FullRefresh
},
cancellationToken).ConfigureAwait(false);
mediaSources = GetStaticMediaSources(item, enablePathSubstitution, user);
}

View File

@ -639,7 +639,7 @@ namespace Emby.Server.Implementations.Library
{
foreach (var user in Users)
{
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false);
await user.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), cancellationToken).ConfigureAwait(false);
}
}

View File

@ -11,16 +11,17 @@ using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.Library.Validators
{
/// <summary>
/// Class PeopleValidator
/// Class PeopleValidator.
/// </summary>
public class PeopleValidator
{
/// <summary>
/// The _library manager
/// The _library manager.
/// </summary>
private readonly ILibraryManager _libraryManager;
/// <summary>
/// The _logger
/// The _logger.
/// </summary>
private readonly ILogger _logger;
@ -62,7 +63,7 @@ namespace Emby.Server.Implementations.Library.Validators
{
var item = _libraryManager.GetPerson(person);
var options = new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
var options = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
ImageRefreshMode = MetadataRefreshMode.ValidationOnly,
MetadataRefreshMode = MetadataRefreshMode.ValidationOnly
@ -96,12 +97,19 @@ namespace Emby.Server.Implementations.Library.Validators
foreach (var item in deadEntities)
{
_logger.LogInformation("Deleting dead {2} {0} {1}.", item.Id.ToString("N", CultureInfo.InvariantCulture), item.Name, item.GetType().Name);
_logger.LogInformation(
"Deleting dead {2} {0} {1}.",
item.Id.ToString("N", CultureInfo.InvariantCulture),
item.Name,
item.GetType().Name);
_libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false
}, false);
_libraryManager.DeleteItem(
item,
new DeleteOptions
{
DeleteFileLocation = false
},
false);
}
progress.Report(100);

View File

@ -1489,16 +1489,18 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
{
_logger.LogInformation("Refreshing recording parent {path}", item.Path);
_providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
{
RefreshPaths = new string[]
_providerManager.QueueRefresh(
item.Id,
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
path,
Path.GetDirectoryName(path),
Path.GetDirectoryName(Path.GetDirectoryName(path))
}
}, RefreshPriority.High);
RefreshPaths = new string[]
{
path,
Path.GetDirectoryName(path),
Path.GetDirectoryName(Path.GetDirectoryName(path))
}
},
RefreshPriority.High);
}
}

View File

@ -1226,12 +1226,13 @@ namespace Emby.Server.Implementations.LiveTv
currentChannel.AddTag("Kids");
}
//currentChannel.UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken);
await currentChannel.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
{
ForceSave = true
}, cancellationToken).ConfigureAwait(false);
currentChannel.UpdateToRepository(ItemUpdateType.MetadataImport, cancellationToken);
await currentChannel.RefreshMetadata(
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
ForceSave = true
},
cancellationToken).ConfigureAwait(false);
}
catch (OperationCanceledException)
{
@ -1245,7 +1246,7 @@ namespace Emby.Server.Implementations.LiveTv
numComplete++;
double percent = numComplete / (double)allChannelsList.Count;
progress.Report(85 * percent + 15);
progress.Report((85 * percent) + 15);
}
progress.Report(100);
@ -1278,12 +1279,14 @@ namespace Emby.Server.Implementations.LiveTv
if (item != null)
{
_libraryManager.DeleteItem(item, new DeleteOptions
{
DeleteFileLocation = false,
DeleteFromExternalProvider = false
}, false);
_libraryManager.DeleteItem(
item,
new DeleteOptions
{
DeleteFileLocation = false,
DeleteFromExternalProvider = false
},
false);
}
}

View File

@ -90,8 +90,7 @@ namespace Emby.Server.Implementations.Playlists
}
else
{
var folder = item as Folder;
if (folder != null)
if (item is Folder folder)
{
options.MediaType = folder.GetRecursiveChildren(i => !i.IsFolder && i.SupportsAddingToPlaylist)
.Select(i => i.MediaType)
@ -140,7 +139,7 @@ namespace Emby.Server.Implementations.Playlists
parentFolder.AddChild(playlist, CancellationToken.None);
await playlist.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)) { ForceSave = true }, CancellationToken.None)
await playlist.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)) { ForceSave = true }, CancellationToken.None)
.ConfigureAwait(false);
if (options.ItemIdList.Length > 0)
@ -201,7 +200,7 @@ namespace Emby.Server.Implementations.Playlists
var list = new List<LinkedChild>();
var items = (GetPlaylistItems(itemIds, playlist.MediaType, user, options))
var items = GetPlaylistItems(itemIds, playlist.MediaType, user, options)
.Where(i => i.SupportsAddingToPlaylist)
.ToList();
@ -221,18 +220,18 @@ namespace Emby.Server.Implementations.Playlists
SavePlaylistFile(playlist);
}
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
{
ForceSave = true
}, RefreshPriority.High);
_providerManager.QueueRefresh(
playlist.Id,
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
ForceSave = true
},
RefreshPriority.High);
}
public void RemoveFromPlaylist(string playlistId, IEnumerable<string> entryIds)
{
var playlist = _libraryManager.GetItemById(playlistId) as Playlist;
if (playlist == null)
if (!(_libraryManager.GetItemById(playlistId) is Playlist playlist))
{
throw new ArgumentException("No Playlist exists with the supplied Id");
}
@ -254,7 +253,7 @@ namespace Emby.Server.Implementations.Playlists
SavePlaylistFile(playlist);
}
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
_providerManager.QueueRefresh(playlist.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
ForceSave = true
@ -263,9 +262,7 @@ namespace Emby.Server.Implementations.Playlists
public void MoveItem(string playlistId, string entryId, int newIndex)
{
var playlist = _libraryManager.GetItemById(playlistId) as Playlist;
if (playlist == null)
if (!(_libraryManager.GetItemById(playlistId) is Playlist playlist))
{
throw new ArgumentException("No Playlist exists with the supplied Id");
}

View File

@ -19,16 +19,17 @@ using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.ScheduledTasks
{
/// <summary>
/// Class ChapterImagesTask
/// Class ChapterImagesTask.
/// </summary>
public class ChapterImagesTask : IScheduledTask
{
/// <summary>
/// The _logger
/// The _logger.
/// </summary>
private readonly ILogger _logger;
/// <summary>
/// The _library manager
/// The _library manager.
/// </summary>
private readonly ILibraryManager _libraryManager;
@ -53,12 +54,12 @@ namespace Emby.Server.Implementations.ScheduledTasks
}
/// <summary>
/// Creates the triggers that define when the task will run
/// Creates the triggers that define when the task will run.
/// </summary>
public IEnumerable<TaskTriggerInfo> GetDefaultTriggers()
{
return new[] {
return new[]
{
new TaskTriggerInfo
{
Type = TaskTriggerInfo.TriggerDaily,
@ -117,7 +118,7 @@ namespace Emby.Server.Implementations.ScheduledTasks
previouslyFailedImages = new List<string>();
}
var directoryService = new DirectoryService(_logger, _fileSystem);
var directoryService = new DirectoryService(_fileSystem);
foreach (var video in videos)
{

View File

@ -6,7 +6,7 @@ using MediaBrowser.Controller;
namespace Emby.Server.Implementations
{
/// <summary>
/// Extends BaseApplicationPaths to add paths that are only applicable on the server
/// Extends BaseApplicationPaths to add paths that are only applicable on the server.
/// </summary>
public class ServerApplicationPaths : BaseApplicationPaths, IServerApplicationPaths
{

View File

@ -32,7 +32,7 @@ namespace MediaBrowser.Api
if (string.IsNullOrEmpty(val))
{
return new ItemFields[] { };
return Array.Empty<ItemFields>();
}
return val.Split(',').Select(v =>
@ -41,6 +41,7 @@ namespace MediaBrowser.Api
{
return (ItemFields?)value;
}
return null;
}).Where(i => i.HasValue).Select(i => i.Value).ToArray();

View File

@ -227,15 +227,17 @@ namespace MediaBrowser.Api
//item.ProductionYear = request.ProductionYear;
//item.Name = request.Name;
return _providerManager.RefreshFullItem(item, new MetadataRefreshOptions(new DirectoryService(Logger, _fileSystem))
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
ReplaceAllMetadata = true,
ReplaceAllImages = request.ReplaceAllImages,
SearchResult = request
}, CancellationToken.None);
return _providerManager.RefreshFullItem(
item,
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
ReplaceAllMetadata = true,
ReplaceAllImages = request.ReplaceAllImages,
SearchResult = request
},
CancellationToken.None);
}
/// <summary>
@ -294,11 +296,9 @@ namespace MediaBrowser.Api
Directory.CreateDirectory(Path.GetDirectoryName(fullCachePath));
using (var stream = result.Content)
using (var filestream = _fileSystem.GetFileStream(fullCachePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
using (var filestream = _fileSystem.GetFileStream(fullCachePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
await stream.CopyToAsync(filestream).ConfigureAwait(false);
}
await stream.CopyToAsync(filestream).ConfigureAwait(false);
}
Directory.CreateDirectory(Path.GetDirectoryName(pointerCachePath));
@ -311,9 +311,6 @@ namespace MediaBrowser.Api
/// <param name="filename">The filename.</param>
/// <returns>System.String.</returns>
private string GetFullCachePath(string filename)
{
return Path.Combine(_appPaths.CachePath, "remote-images", filename.Substring(0, 1), filename);
}
=> Path.Combine(_appPaths.CachePath, "remote-images", filename.Substring(0, 1), filename);
}
}

View File

@ -63,7 +63,7 @@ namespace MediaBrowser.Api
private MetadataRefreshOptions GetRefreshOptions(RefreshItem request)
{
return new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem))
return new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
MetadataRefreshMode = request.MetadataRefreshMode,
ImageRefreshMode = request.ImageRefreshMode,

View File

@ -225,13 +225,15 @@ namespace MediaBrowser.Api
if (displayOrderChanged)
{
_providerManager.QueueRefresh(series.Id, new MetadataRefreshOptions(new DirectoryService(Logger, _fileSystem))
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
ReplaceAllMetadata = true
}, RefreshPriority.High);
_providerManager.QueueRefresh(
series.Id,
new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = MetadataRefreshMode.FullRefresh,
ReplaceAllMetadata = true
},
RefreshPriority.High);
}
}

View File

@ -279,13 +279,12 @@ namespace MediaBrowser.Api.Subtitles
await _subtitleManager.DownloadSubtitles(video, request.SubtitleId, CancellationToken.None)
.ConfigureAwait(false);
_providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions(new DirectoryService(Logger, _fileSystem)), RefreshPriority.High);
_providerManager.QueueRefresh(video.Id, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), RefreshPriority.High);
}
catch (Exception ex)
{
Logger.LogError(ex, "Error downloading subtitles");
}
});
}
}

View File

@ -413,7 +413,7 @@ namespace MediaBrowser.Api.UserLibrary
if (!hasMetdata)
{
var options = new MetadataRefreshOptions(new DirectoryService(Logger, _fileSystem))
var options = new MetadataRefreshOptions(new DirectoryService(_fileSystem))
{
MetadataRefreshMode = MetadataRefreshMode.FullRefresh,
ImageRefreshMode = MetadataRefreshMode.FullRefresh,

View File

@ -89,7 +89,7 @@ namespace MediaBrowser.Controller.Entities
{
var locations = PhysicalLocations;
var newLocations = CreateResolveArgs(new DirectoryService(Logger, FileSystem), false).PhysicalLocations;
var newLocations = CreateResolveArgs(new DirectoryService(FileSystem), false).PhysicalLocations;
if (!locations.SequenceEqual(newLocations))
{

View File

@ -1344,7 +1344,7 @@ namespace MediaBrowser.Controller.Entities
public Task RefreshMetadata(CancellationToken cancellationToken)
{
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)), cancellationToken);
return RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(FileSystem)), cancellationToken);
}
protected virtual void TriggerOnRefreshStart()
@ -2197,7 +2197,7 @@ namespace MediaBrowser.Controller.Entities
/// <returns>Task.</returns>
public virtual void ChangedExternally()
{
ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem))
ProviderManager.QueueRefresh(Id, new MetadataRefreshOptions(new DirectoryService(FileSystem))
{
}, RefreshPriority.High);

View File

@ -171,7 +171,7 @@ namespace MediaBrowser.Controller.Entities
{
var locations = PhysicalLocations;
var newLocations = CreateResolveArgs(new DirectoryService(Logger, FileSystem), false).PhysicalLocations;
var newLocations = CreateResolveArgs(new DirectoryService(FileSystem), false).PhysicalLocations;
if (!locations.SequenceEqual(newLocations))
{

View File

@ -216,7 +216,7 @@ namespace MediaBrowser.Controller.Entities
public Task ValidateChildren(IProgress<double> progress, CancellationToken cancellationToken)
{
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem)));
return ValidateChildren(progress, cancellationToken, new MetadataRefreshOptions(new DirectoryService(FileSystem)));
}
/// <summary>

View File

@ -148,7 +148,7 @@ namespace MediaBrowser.Controller.Entities
Name = newName;
return RefreshMetadata(
new MetadataRefreshOptions(new DirectoryService(Logger, FileSystem))
new MetadataRefreshOptions(new DirectoryService(FileSystem))
{
ReplaceAllMetadata = true,
ImageRefreshMode = MetadataRefreshMode.FullRefresh,

View File

@ -2,13 +2,11 @@ using System;
using System.Collections.Generic;
using System.Linq;
using MediaBrowser.Model.IO;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Controller.Providers
{
public class DirectoryService : IDirectoryService
{
private readonly ILogger _logger;
private readonly IFileSystem _fileSystem;
private readonly Dictionary<string, FileSystemMetadata[]> _cache = new Dictionary<string, FileSystemMetadata[]>(StringComparer.OrdinalIgnoreCase);
@ -17,9 +15,8 @@ namespace MediaBrowser.Controller.Providers
private readonly Dictionary<string, List<string>> _filePathCache = new Dictionary<string, List<string>>(StringComparer.OrdinalIgnoreCase);
public DirectoryService(ILogger logger, IFileSystem fileSystem)
public DirectoryService(IFileSystem fileSystem)
{
_logger = logger;
_fileSystem = fileSystem;
}
@ -27,8 +24,6 @@ namespace MediaBrowser.Controller.Providers
{
if (!_cache.TryGetValue(path, out FileSystemMetadata[] entries))
{
//_logger.LogDebug("Getting files for " + path);
entries = _fileSystem.GetFileSystemEntries(path).ToArray();
//_cache.TryAdd(path, entries);
@ -49,6 +44,7 @@ namespace MediaBrowser.Controller.Providers
list.Add(item);
}
}
return list;
}
@ -89,6 +85,5 @@ namespace MediaBrowser.Controller.Providers
return result;
}
}
}

View File

@ -24,7 +24,8 @@ namespace MediaBrowser.Controller.Subtitles
/// <summary>
/// Searches the subtitles.
/// </summary>
Task<RemoteSubtitleInfo[]> SearchSubtitles(Video video,
Task<RemoteSubtitleInfo[]> SearchSubtitles(
Video video,
string language,
bool? isPerfectMatch,
CancellationToken cancellationToken);
@ -34,8 +35,9 @@ namespace MediaBrowser.Controller.Subtitles
/// </summary>
/// <param name="request">The request.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{IEnumerable{RemoteSubtitleInfo}}.</returns>
Task<RemoteSubtitleInfo[]> SearchSubtitles(SubtitleSearchRequest request,
/// <returns>Task{RemoteSubtitleInfo[]}.</returns>
Task<RemoteSubtitleInfo[]> SearchSubtitles(
SubtitleSearchRequest request,
CancellationToken cancellationToken);
/// <summary>
@ -53,7 +55,7 @@ namespace MediaBrowser.Controller.Subtitles
/// </summary>
/// <param name="id">The identifier.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <returns>Task{SubtitleResponse}.</returns>
/// <returns><see cref="Task{SubtitleResponse}" />.</returns>
Task<SubtitleResponse> GetRemoteSubtitles(string id, CancellationToken cancellationToken);
/// <summary>

View File

@ -1,17 +1,17 @@
namespace MediaBrowser.Model.IO
{
/// <summary>
/// Class StreamDefaults
/// Class StreamDefaults.
/// </summary>
public static class StreamDefaults
{
/// <summary>
/// The default copy to buffer size
/// The default copy to buffer size.
/// </summary>
public const int DefaultCopyToBufferSize = 81920;
/// <summary>
/// The default file stream buffer size
/// The default file stream buffer size.
/// </summary>
public const int DefaultFileStreamBufferSize = 4096;
}

View File

@ -16,9 +16,8 @@ namespace MediaBrowser.Providers.Books
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
IUserDataManager userDataManager,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}

View File

@ -11,6 +11,17 @@ namespace MediaBrowser.Providers.Books
{
public class BookMetadataService : MetadataService<Book, BookInfo>
{
public BookMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Book> source, MetadataResult<Book> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
@ -20,9 +31,5 @@ namespace MediaBrowser.Providers.Books
target.Item.SeriesName = source.Item.SeriesName;
}
}
public BookMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -14,11 +14,35 @@ namespace MediaBrowser.Providers.BoxSets
{
public class BoxSetMetadataService : MetadataService<BoxSet, BoxSetInfo>
{
public BoxSetMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override bool EnableUpdatingGenresFromChildren => true;
/// <inheritdoc />
protected override bool EnableUpdatingOfficialRatingFromChildren => true;
/// <inheritdoc />
protected override bool EnableUpdatingStudiosFromChildren => true;
/// <inheritdoc />
protected override bool EnableUpdatingPremiereDateFromChildren => true;
/// <inheritdoc />
protected override IList<BaseItem> GetChildrenForMetadataUpdates(BoxSet item)
{
return item.GetLinkedChildren();
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<BoxSet> source, MetadataResult<BoxSet> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
@ -32,6 +56,7 @@ namespace MediaBrowser.Providers.BoxSets
}
}
/// <inheritdoc />
protected override ItemUpdateType BeforeSaveInternal(BoxSet item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.BeforeSaveInternal(item, isFullRefresh, currentUpdateType);
@ -47,17 +72,5 @@ namespace MediaBrowser.Providers.BoxSets
return updateType;
}
public BoxSetMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
protected override bool EnableUpdatingGenresFromChildren => true;
protected override bool EnableUpdatingOfficialRatingFromChildren => true;
protected override bool EnableUpdatingStudiosFromChildren => true;
protected override bool EnableUpdatingPremiereDateFromChildren => true;
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Channels
{
public class ChannelMetadataService : MetadataService<Channel, ItemLookupInfo>
{
public ChannelMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Channel> source, MetadataResult<Channel> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public ChannelMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -12,13 +12,20 @@ namespace MediaBrowser.Providers.Folders
{
public class CollectionFolderMetadataService : MetadataService<CollectionFolder, ItemLookupInfo>
{
public CollectionFolderMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<CollectionFolder> source, MetadataResult<CollectionFolder> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public CollectionFolderMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,16 +11,24 @@ namespace MediaBrowser.Providers.Folders
{
public class FolderMetadataService : MetadataService<Folder, ItemLookupInfo>
{
public FolderMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
// Make sure the type-specific services get picked first
public override int Order => 10;
/// <inheritdoc />
protected override void MergeData(MetadataResult<Folder> source, MetadataResult<Folder> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public FolderMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Folders
{
public class UserViewMetadataService : MetadataService<UserView, ItemLookupInfo>
{
public UserViewMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<UserView> source, MetadataResult<UserView> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public UserViewMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Genres
{
public class GenreMetadataService : MetadataService<Genre, ItemLookupInfo>
{
public GenreMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Genre> source, MetadataResult<Genre> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public GenreMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.LiveTv
{
public class LiveTvMetadataService : MetadataService<LiveTvChannel, ItemLookupInfo>
{
public LiveTvMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<LiveTvChannel> source, MetadataResult<LiveTvChannel> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public LiveTvMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -340,7 +340,7 @@ namespace MediaBrowser.Providers.Manager
if (deleted)
{
item.ValidateImages(new DirectoryService(_logger, _fileSystem));
item.ValidateImages(new DirectoryService(_fileSystem));
}
}

View File

@ -23,16 +23,14 @@ namespace MediaBrowser.Providers.Manager
protected readonly ILogger Logger;
protected readonly IProviderManager ProviderManager;
protected readonly IFileSystem FileSystem;
protected readonly IUserDataManager UserDataManager;
protected readonly ILibraryManager LibraryManager;
protected MetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager)
protected MetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, ILibraryManager libraryManager)
{
ServerConfigurationManager = serverConfigurationManager;
Logger = logger;
ProviderManager = providerManager;
FileSystem = fileSystem;
UserDataManager = userDataManager;
LibraryManager = libraryManager;
}
@ -44,7 +42,7 @@ namespace MediaBrowser.Providers.Manager
}
catch (Exception ex)
{
Logger.LogError(ex, "Error getting file {path}", path);
Logger.LogError(ex, "Error getting file {Path}", path);
return null;
}
}

View File

@ -328,7 +328,7 @@ namespace MediaBrowser.Providers.Manager
return GetImageProviders(item, libraryOptions, options,
new ImageRefreshOptions(
new DirectoryService(_logger, _fileSystem)),
new DirectoryService(_fileSystem)),
includeDisabled)
.OfType<IRemoteImageProvider>();
}
@ -507,7 +507,7 @@ namespace MediaBrowser.Providers.Manager
var imageProviders = GetImageProviders(dummy, libraryOptions, options,
new ImageRefreshOptions(
new DirectoryService(_logger, _fileSystem)),
new DirectoryService(_fileSystem)),
true)
.ToList();

View File

@ -9,17 +9,20 @@ namespace MediaBrowser.Providers.Movies
{
public class ImdbExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "IMDb";
/// <inheritdoc />
public string Key => MetadataProviders.Imdb.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://www.imdb.com/title/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
// Supports images for tv movies
var tvProgram = item as LiveTvProgram;
if (tvProgram != null && tvProgram.IsMovie)
if (item is LiveTvProgram tvProgram && tvProgram.IsMovie)
{
return true;
}
@ -28,18 +31,18 @@ namespace MediaBrowser.Providers.Movies
}
}
public class ImdbPersonExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "IMDb";
/// <inheritdoc />
public string Key => MetadataProviders.Imdb.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://www.imdb.com/name/{0}";
public bool Supports(IHasProviderIds item)
{
return item is Person;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Person;
}
}

View File

@ -1,5 +1,4 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
@ -12,6 +11,17 @@ namespace MediaBrowser.Providers.Movies
{
public class MovieMetadataService : MetadataService<Movie, MovieInfo>
{
public MovieMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override bool IsFullLocalMetadata(Movie item)
{
if (string.IsNullOrWhiteSpace(item.Overview))
@ -25,6 +35,7 @@ namespace MediaBrowser.Providers.Movies
return base.IsFullLocalMetadata(item);
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Movie> source, MetadataResult<Movie> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
@ -37,40 +48,5 @@ namespace MediaBrowser.Providers.Movies
targetItem.CollectionName = sourceItem.CollectionName;
}
}
public MovieMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
public class TrailerMetadataService : MetadataService<Trailer, TrailerInfo>
{
protected override bool IsFullLocalMetadata(Trailer item)
{
if (string.IsNullOrWhiteSpace(item.Overview))
{
return false;
}
if (!item.ProductionYear.HasValue)
{
return false;
}
return base.IsFullLocalMetadata(item);
}
protected override void MergeData(MetadataResult<Trailer> source, MetadataResult<Trailer> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
if (replaceData || target.Item.TrailerTypes.Length == 0)
{
target.Item.TrailerTypes = source.Item.TrailerTypes;
}
}
public TrailerMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -0,0 +1,49 @@
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.IO;
using MediaBrowser.Providers.Manager;
using Microsoft.Extensions.Logging;
namespace MediaBrowser.Providers.Movies
{
public class TrailerMetadataService : MetadataService<Trailer, TrailerInfo>
{
public TrailerMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override bool IsFullLocalMetadata(Trailer item)
{
if (string.IsNullOrWhiteSpace(item.Overview))
{
return false;
}
if (!item.ProductionYear.HasValue)
{
return false;
}
return base.IsFullLocalMetadata(item);
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Trailer> source, MetadataResult<Trailer> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
if (replaceData || target.Item.TrailerTypes.Length == 0)
{
target.Item.TrailerTypes = source.Item.TrailerTypes;
}
}
}
}

View File

@ -20,9 +20,8 @@ namespace MediaBrowser.Providers.Music
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
IUserDataManager userDataManager,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
@ -37,10 +36,7 @@ namespace MediaBrowser.Providers.Music
/// <inheritdoc />
protected override IList<BaseItem> GetChildrenForMetadataUpdates(MusicAlbum item)
{
return item.GetRecursiveChildren(i => i is Audio)
.ToList();
}
=> item.GetRecursiveChildren(i => i is Audio);
/// <inheritdoc />
protected override ItemUpdateType UpdateMetadataFromChildren(MusicAlbum item, IList<BaseItem> children, bool isFullRefresh, ItemUpdateType currentUpdateType)
@ -53,20 +49,18 @@ namespace MediaBrowser.Providers.Music
{
var name = children.Select(i => i.Album).FirstOrDefault(i => !string.IsNullOrEmpty(i));
if (!string.IsNullOrEmpty(name))
if (!string.IsNullOrEmpty(name)
&& !string.Equals(item.Name, name, StringComparison.Ordinal))
{
if (!string.Equals(item.Name, name, StringComparison.Ordinal))
{
item.Name = name;
updateType = updateType | ItemUpdateType.MetadataEdit;
}
item.Name = name;
updateType |= ItemUpdateType.MetadataEdit;
}
}
var songs = children.Cast<Audio>().ToArray();
updateType = updateType | SetAlbumArtistFromSongs(item, songs);
updateType = updateType | SetArtistsFromSongs(item, songs);
updateType |= SetAlbumArtistFromSongs(item, songs);
updateType |= SetArtistsFromSongs(item, songs);
}
return updateType;

View File

@ -13,26 +13,35 @@ namespace MediaBrowser.Providers.Music
{
public class ArtistMetadataService : MetadataService<MusicArtist, ArtistInfo>
{
protected override IList<BaseItem> GetChildrenForMetadataUpdates(MusicArtist item)
public ArtistMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
return item.IsAccessedByName ?
item.GetTaggedItems(new InternalItemsQuery
{
Recursive = true,
IsFolder = false
}) :
item.GetRecursiveChildren(i => i is IHasArtist && !i.IsFolder);
}
/// <inheritdoc />
protected override bool EnableUpdatingGenresFromChildren => true;
/// <inheritdoc />
protected override IList<BaseItem> GetChildrenForMetadataUpdates(MusicArtist item)
{
return item.IsAccessedByName
? item.GetTaggedItems(new InternalItemsQuery
{
Recursive = true,
IsFolder = false
})
: item.GetRecursiveChildren(i => i is IHasArtist && !i.IsFolder);
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<MusicArtist> source, MetadataResult<MusicArtist> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public ArtistMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -25,6 +25,14 @@ namespace MediaBrowser.Providers.Music
_json = json;
}
/// <inheritdoc />
public string Name => "TheAudioDB";
/// <inheritdoc />
// After embedded and fanart
public int Order => 2;
/// <inheritdoc />
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
@ -34,6 +42,7 @@ namespace MediaBrowser.Providers.Music
};
}
/// <inheritdoc />
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var id = item.GetProviderId(MetadataProviders.MusicBrainzReleaseGroup);
@ -82,6 +91,7 @@ namespace MediaBrowser.Providers.Music
return list;
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions
@ -91,13 +101,7 @@ namespace MediaBrowser.Providers.Music
});
}
public string Name => "TheAudioDB";
// After embedded and fanart
public int Order => 2;
public bool Supports(BaseItem item)
{
return item is MusicAlbum;
}
/// <inheritdoc />
public bool Supports(BaseItem item) => item is MusicAlbum;
}
}

View File

@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
@ -26,8 +27,6 @@ namespace MediaBrowser.Providers.Music
public static AudioDbAlbumProvider Current;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public AudioDbAlbumProvider(IServerConfigurationManager config, IFileSystem fileSystem, IHttpClient httpClient, IJsonSerializer json)
{
_config = config;
@ -38,11 +37,18 @@ namespace MediaBrowser.Providers.Music
Current = this;
}
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
{
return Task.FromResult((IEnumerable<RemoteSearchResult>)new List<RemoteSearchResult>());
}
/// <inheritdoc />
public string Name => "TheAudioDB";
/// <inheritdoc />
// After music brainz
public int Order => 1;
/// <inheritdoc />
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
=> Task.FromResult(Enumerable.Empty<RemoteSearchResult>());
/// <inheritdoc />
public async Task<MetadataResult<MusicAlbum>> GetMetadata(AlbumInfo info, CancellationToken cancellationToken)
{
var result = new MetadataResult<MusicAlbum>();
@ -77,7 +83,7 @@ namespace MediaBrowser.Providers.Music
if (!string.IsNullOrEmpty(result.intYearReleased))
{
item.ProductionYear = int.Parse(result.intYearReleased, _usCulture);
item.ProductionYear = int.Parse(result.intYearReleased, CultureInfo.InvariantCulture);
}
if (!string.IsNullOrEmpty(result.strGenre))
@ -126,8 +132,6 @@ namespace MediaBrowser.Providers.Music
item.Overview = (overview ?? string.Empty).StripHtml();
}
public string Name => "TheAudioDB";
internal Task EnsureInfo(string musicBrainzReleaseGroupId, CancellationToken cancellationToken)
{
var xmlPath = GetAlbumInfoPath(_config.ApplicationPaths, musicBrainzReleaseGroupId);
@ -155,20 +159,18 @@ namespace MediaBrowser.Providers.Music
Directory.CreateDirectory(Path.GetDirectoryName(path));
using (var httpResponse = await _httpClient.SendAsync(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken
}, "GET").ConfigureAwait(false))
{
using (var response = httpResponse.Content)
using (var httpResponse = await _httpClient.SendAsync(
new HttpRequestOptions
{
using (var xmlFileStream = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
}
}
Url = url,
CancellationToken = cancellationToken
},
"GET").ConfigureAwait(false))
using (var response = httpResponse.Content)
using (var xmlFileStream = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
}
}
@ -192,8 +194,6 @@ namespace MediaBrowser.Providers.Music
return Path.Combine(dataPath, "album.json");
}
// After music brainz
public int Order => 1;
public class Album
{
@ -242,6 +242,7 @@ namespace MediaBrowser.Providers.Music
public List<Album> album { get; set; }
}
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
throw new NotImplementedException();

View File

@ -25,6 +25,14 @@ namespace MediaBrowser.Providers.Music
_httpClient = httpClient;
}
/// <inheritdoc />
public string Name => "TheAudioDB";
/// <inheritdoc />
// After fanart
public int Order => 1;
/// <inheritdoc />
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
@ -36,6 +44,7 @@ namespace MediaBrowser.Providers.Music
};
}
/// <inheritdoc />
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var id = item.GetProviderId(MetadataProviders.MusicBrainzArtist);
@ -133,13 +142,7 @@ namespace MediaBrowser.Providers.Music
});
}
public string Name => "TheAudioDB";
public bool Supports(BaseItem item)
{
return item is MusicArtist;
}
// After fanart
public int Order => 1;
/// <inheritdoc />
public bool Supports(BaseItem item) => item is MusicArtist;
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Configuration;
@ -37,11 +38,18 @@ namespace MediaBrowser.Providers.Music
Current = this;
}
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
{
return Task.FromResult((IEnumerable<RemoteSearchResult>)new List<RemoteSearchResult>());
}
/// <inheritdoc />
public string Name => "TheAudioDB";
/// <inheritdoc />
// After musicbrainz
public int Order => 1;
/// <inheritdoc />
public Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
=> Task.FromResult(Enumerable.Empty<RemoteSearchResult>());
/// <inheritdoc />
public async Task<MetadataResult<MusicArtist>> GetMetadata(ArtistInfo info, CancellationToken cancellationToken)
{
var result = new MetadataResult<MusicArtist>();
@ -114,20 +122,16 @@ namespace MediaBrowser.Providers.Music
item.Overview = (overview ?? string.Empty).StripHtml();
}
public string Name => "TheAudioDB";
internal Task EnsureArtistInfo(string musicBrainzId, CancellationToken cancellationToken)
{
var xmlPath = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
var fileInfo = _fileSystem.GetFileSystemInfo(xmlPath);
if (fileInfo.Exists)
if (fileInfo.Exists
&& (DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)
{
if ((DateTime.UtcNow - _fileSystem.GetLastWriteTimeUtc(fileInfo)).TotalDays <= 2)
{
return Task.CompletedTask;
}
return Task.CompletedTask;
}
return DownloadArtistInfo(musicBrainzId, cancellationToken);
@ -141,22 +145,22 @@ namespace MediaBrowser.Providers.Music
var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
using (var httpResponse = await _httpClient.SendAsync(new HttpRequestOptions
{
Url = url,
CancellationToken = cancellationToken,
BufferContent = true
}, "GET").ConfigureAwait(false))
{
using (var response = httpResponse.Content)
using (var httpResponse = await _httpClient.SendAsync(
new HttpRequestOptions
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
Url = url,
CancellationToken = cancellationToken,
BufferContent = true
using (var xmlFileStream = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
}
},
"GET").ConfigureAwait(false))
using (var response = httpResponse.Content)
{
Directory.CreateDirectory(Path.GetDirectoryName(path));
using (var xmlFileStream = _fileSystem.GetFileStream(path, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
{
await response.CopyToAsync(xmlFileStream).ConfigureAwait(false);
}
}
}
@ -168,11 +172,7 @@ namespace MediaBrowser.Providers.Music
/// <param name="musicBrainzArtistId">The music brainz artist identifier.</param>
/// <returns>System.String.</returns>
private static string GetArtistDataPath(IApplicationPaths appPaths, string musicBrainzArtistId)
{
var dataPath = Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId);
return dataPath;
}
=> Path.Combine(GetArtistDataPath(appPaths), musicBrainzArtistId);
/// <summary>
/// Gets the artist data path.
@ -180,11 +180,7 @@ namespace MediaBrowser.Providers.Music
/// <param name="appPaths">The application paths.</param>
/// <returns>System.String.</returns>
private static string GetArtistDataPath(IApplicationPaths appPaths)
{
var dataPath = Path.Combine(appPaths.CachePath, "audiodb-artist");
return dataPath;
}
=> Path.Combine(appPaths.CachePath, "audiodb-artist");
internal static string GetArtistInfoPath(IApplicationPaths appPaths, string musicBrainzArtistId)
{
@ -242,9 +238,8 @@ namespace MediaBrowser.Providers.Music
{
public List<Artist> artists { get; set; }
}
// After musicbrainz
public int Order => 1;
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
throw new NotImplementedException();

View File

@ -6,58 +6,63 @@ namespace MediaBrowser.Providers.Music
{
public class AudioDbAlbumExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheAudioDb";
/// <inheritdoc />
public string Key => MetadataProviders.AudioDbAlbum.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://www.theaudiodb.com/album/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is MusicAlbum;
}
=> item is MusicAlbum;
}
public class AudioDbOtherAlbumExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheAudioDb Album";
/// <inheritdoc />
public string Key => MetadataProviders.AudioDbAlbum.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://www.theaudiodb.com/album/{0}";
public bool Supports(IHasProviderIds item)
{
return item is Audio;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Audio;
}
public class AudioDbArtistExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheAudioDb";
/// <inheritdoc />
public string Key => MetadataProviders.AudioDbArtist.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://www.theaudiodb.com/artist/{0}";
public bool Supports(IHasProviderIds item)
{
return item is MusicArtist;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is MusicArtist;
}
public class AudioDbOtherArtistExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheAudioDb Artist";
/// <inheritdoc />
public string Key => MetadataProviders.AudioDbArtist.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://www.theaudiodb.com/artist/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
=> item is Audio || item is MusicAlbum;
}
}

View File

@ -16,9 +16,8 @@ namespace MediaBrowser.Providers.Music
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
IUserDataManager userDataManager,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
@ -14,7 +15,6 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Providers;
using MediaBrowser.Model.Entities;
using MediaBrowser.Model.Providers;
using MediaBrowser.Model.Serialization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Logging;
@ -22,16 +22,6 @@ namespace MediaBrowser.Providers.Music
{
public class MusicBrainzAlbumProvider : IRemoteMetadataProvider<MusicAlbum, AlbumInfo>, IHasOrder
{
internal static MusicBrainzAlbumProvider Current;
private readonly IHttpClient _httpClient;
private readonly IApplicationHost _appHost;
private readonly ILogger _logger;
private readonly IJsonSerializer _json;
private Stopwatch _stopWatchMusicBrainz = new Stopwatch();
public readonly string MusicBrainzBaseUrl;
/// <summary>
/// The Jellyfin user-agent is unrestricted but source IP must not exceed
/// one request per second, therefore we rate limit to avoid throttling.
@ -47,19 +37,27 @@ namespace MediaBrowser.Providers.Music
/// </summary>
private const uint MusicBrainzQueryAttempts = 5u;
internal static MusicBrainzAlbumProvider Current;
private readonly IHttpClient _httpClient;
private readonly IApplicationHost _appHost;
private readonly ILogger _logger;
private readonly string _musicBrainzBaseUrl;
private Stopwatch _stopWatchMusicBrainz = new Stopwatch();
public MusicBrainzAlbumProvider(
IHttpClient httpClient,
IApplicationHost appHost,
ILogger logger,
IJsonSerializer json,
IConfiguration configuration)
{
_httpClient = httpClient;
_appHost = appHost;
_logger = logger;
_json = json;
MusicBrainzBaseUrl = configuration["MusicBrainz:BaseUrl"];
_musicBrainzBaseUrl = configuration["MusicBrainz:BaseUrl"];
// Use a stopwatch to ensure we don't exceed the MusicBrainz rate limit
_stopWatchMusicBrainz.Start();
@ -67,6 +65,13 @@ namespace MediaBrowser.Providers.Music
Current = this;
}
/// <inheritdoc />
public string Name => "MusicBrainz";
/// <inheritdoc />
public int Order => 0;
/// <inheritdoc />
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(AlbumInfo searchInfo, CancellationToken cancellationToken)
{
var releaseId = searchInfo.GetReleaseId();
@ -76,11 +81,11 @@ namespace MediaBrowser.Providers.Music
if (!string.IsNullOrEmpty(releaseId))
{
url = string.Format("/ws/2/release/?query=reid:{0}", releaseId);
url = "/ws/2/release/?query=reid:" + releaseId.ToString(CultureInfo.InvariantCulture);
}
else if (!string.IsNullOrEmpty(releaseGroupId))
{
url = string.Format("/ws/2/release?release-group={0}", releaseGroupId);
url = "/ws/2/release?release-group=" + releaseGroupId.ToString(CultureInfo.InvariantCulture);
}
else
{
@ -88,7 +93,9 @@ namespace MediaBrowser.Providers.Music
if (!string.IsNullOrWhiteSpace(artistMusicBrainzId))
{
url = string.Format("/ws/2/release/?query=\"{0}\" AND arid:{1}",
url = string.Format(
CultureInfo.InvariantCulture,
"/ws/2/release/?query=\"{0}\" AND arid:{1}",
WebUtility.UrlEncode(searchInfo.Name),
artistMusicBrainzId);
}
@ -97,7 +104,9 @@ namespace MediaBrowser.Providers.Music
// I'm sure there is a better way but for now it resolves search for 12" Mixes
var queryName = searchInfo.Name.Replace("\"", string.Empty);
url = string.Format("/ws/2/release/?query=\"{0}\" AND artist:\"{1}\"",
url = string.Format(
CultureInfo.InvariantCulture,
"/ws/2/release/?query=\"{0}\" AND artist:\"{1}\"",
WebUtility.UrlEncode(queryName),
WebUtility.UrlEncode(searchInfo.GetAlbumArtist()));
}
@ -106,11 +115,9 @@ namespace MediaBrowser.Providers.Music
if (!string.IsNullOrWhiteSpace(url))
{
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
using (var stream = response.Content)
{
using (var stream = response.Content)
{
return GetResultsFromResponse(stream);
}
return GetResultsFromResponse(stream);
}
}
@ -156,6 +163,7 @@ namespace MediaBrowser.Providers.Music
{
result.SetProviderId(MetadataProviders.MusicBrainzAlbum, i.ReleaseId);
}
if (!string.IsNullOrWhiteSpace(i.ReleaseGroupId))
{
result.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, i.ReleaseGroupId);
@ -168,6 +176,7 @@ namespace MediaBrowser.Providers.Music
}
}
/// <inheritdoc />
public async Task<MetadataResult<MusicAlbum>> GetMetadata(AlbumInfo id, CancellationToken cancellationToken)
{
var releaseId = id.GetReleaseId();
@ -238,8 +247,6 @@ namespace MediaBrowser.Providers.Music
return result;
}
public string Name => "MusicBrainz";
private Task<ReleaseResult> GetReleaseResult(string artistMusicBrainId, string artistName, string albumName, CancellationToken cancellationToken)
{
if (!string.IsNullOrEmpty(artistMusicBrainId))
@ -282,7 +289,9 @@ namespace MediaBrowser.Providers.Music
private async Task<ReleaseResult> GetReleaseResultByArtistName(string albumName, string artistName, CancellationToken cancellationToken)
{
var url = string.Format("/ws/2/release/?query=\"{0}\" AND artist:\"{1}\"",
var url = string.Format(
CultureInfo.InvariantCulture,
"/ws/2/release/?query=\"{0}\" AND artist:\"{1}\"",
WebUtility.UrlEncode(albumName),
WebUtility.UrlEncode(artistName));
@ -334,6 +343,7 @@ namespace MediaBrowser.Providers.Music
reader.Read();
continue;
}
using (var subReader = reader.ReadSubtree())
{
return ParseReleaseList(subReader).ToList();
@ -601,7 +611,7 @@ namespace MediaBrowser.Providers.Music
private async Task<string> GetReleaseIdFromReleaseGroupId(string releaseGroupId, CancellationToken cancellationToken)
{
var url = string.Format("/ws/2/release?release-group={0}", releaseGroupId);
var url = "/ws/2/release?release-group=" + releaseGroupId.ToString(CultureInfo.InvariantCulture);
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
using (var stream = response.Content)
@ -637,7 +647,7 @@ namespace MediaBrowser.Providers.Music
/// <returns>Task{System.String}.</returns>
private async Task<string> GetReleaseGroupFromReleaseId(string releaseEntryId, CancellationToken cancellationToken)
{
var url = string.Format("/ws/2/release-group/?query=reid:{0}", releaseEntryId);
var url = "/ws/2/release-group/?query=reid:" + releaseEntryId.ToString(CultureInfo.InvariantCulture);
using (var response = await GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
using (var stream = response.Content)
@ -687,6 +697,7 @@ namespace MediaBrowser.Providers.Music
reader.Read();
}
}
return null;
}
}
@ -734,11 +745,15 @@ namespace MediaBrowser.Providers.Music
{
var options = new HttpRequestOptions
{
Url = MusicBrainzBaseUrl.TrimEnd('/') + url,
Url = _musicBrainzBaseUrl.TrimEnd('/') + url,
CancellationToken = cancellationToken,
// MusicBrainz request a contact email address is supplied, as comment, in user agent field:
// https://musicbrainz.org/doc/XML_Web_Service/Rate_Limiting#User-Agent
UserAgent = string.Format("{0} ( {1} )", _appHost.ApplicationUserAgent, _appHost.ApplicationUserAgentAddress),
UserAgent = string.Format(
CultureInfo.InvariantCulture,
"{0} ( {1} )",
_appHost.ApplicationUserAgent,
_appHost.ApplicationUserAgentAddress),
BufferContent = false
};
@ -768,7 +783,7 @@ namespace MediaBrowser.Providers.Music
while (attempts < MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable);
// Log error if unable to query MB database due to throttling
if (attempts == MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable )
if (attempts == MusicBrainzQueryAttempts && response.StatusCode == HttpStatusCode.ServiceUnavailable)
{
_logger.LogError("GetMusicBrainzResponse: 503 Service Unavailable (throttled) response received {0} times whilst requesting {1}", attempts, options.Url);
}
@ -776,8 +791,7 @@ namespace MediaBrowser.Providers.Music
return response;
}
public int Order => 0;
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
throw new NotImplementedException();

View File

@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
@ -18,25 +19,19 @@ namespace MediaBrowser.Providers.Music
{
public class MusicBrainzArtistProvider : IRemoteMetadataProvider<MusicArtist, ArtistInfo>
{
public MusicBrainzArtistProvider()
{
}
/// <inheritdoc />
public async Task<IEnumerable<RemoteSearchResult>> GetSearchResults(ArtistInfo searchInfo, CancellationToken cancellationToken)
{
var musicBrainzId = searchInfo.GetMusicBrainzArtistId();
if (!string.IsNullOrWhiteSpace(musicBrainzId))
{
var url = string.Format("/ws/2/artist/?query=arid:{0}", musicBrainzId);
var url = "/ws/2/artist/?query=arid:{0}" + musicBrainzId.ToString(CultureInfo.InvariantCulture);
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
using (var stream = response.Content)
{
using (var stream = response.Content)
{
return GetResultsFromResponse(stream);
}
return GetResultsFromResponse(stream);
}
}
else
@ -47,15 +42,13 @@ namespace MediaBrowser.Providers.Music
var url = string.Format("/ws/2/artist/?query=\"{0}\"&dismax=true", UrlEncode(nameToSearch));
using (var response = await MusicBrainzAlbumProvider.Current.GetMusicBrainzResponse(url, cancellationToken).ConfigureAwait(false))
using (var stream = response.Content)
{
using (var stream = response.Content)
{
var results = GetResultsFromResponse(stream).ToList();
var results = GetResultsFromResponse(stream).ToList();
if (results.Count > 0)
{
return results;
}
if (results.Count > 0)
{
return results;
}
}

View File

@ -7,99 +7,113 @@ namespace MediaBrowser.Providers.Music
{
public class MusicBrainzReleaseGroupExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "MusicBrainz Release Group";
/// <inheritdoc />
public string Key => MetadataProviders.MusicBrainzReleaseGroup.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://musicbrainz.org/release-group/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
=> item is Audio || item is MusicAlbum;
}
public class MusicBrainzAlbumArtistExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "MusicBrainz Album Artist";
/// <inheritdoc />
public string Key => MetadataProviders.MusicBrainzAlbumArtist.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://musicbrainz.org/artist/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Audio;
}
=> item is Audio;
}
public class MusicBrainzAlbumExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "MusicBrainz Album";
/// <inheritdoc />
public string Key => MetadataProviders.MusicBrainzAlbum.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://musicbrainz.org/release/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
=> item is Audio || item is MusicAlbum;
}
public class MusicBrainzArtistExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "MusicBrainz";
/// <inheritdoc />
public string Key => MetadataProviders.MusicBrainzArtist.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://musicbrainz.org/artist/{0}";
public bool Supports(IHasProviderIds item)
{
return item is MusicArtist;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is MusicArtist;
}
public class MusicBrainzOtherArtistExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "MusicBrainz Artist";
/// <inheritdoc />
public string Key => MetadataProviders.MusicBrainzArtist.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://musicbrainz.org/artist/{0}";
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is Audio || item is MusicAlbum;
}
=> item is Audio || item is MusicAlbum;
}
public class MusicBrainzTrackId : IExternalId
{
/// <inheritdoc />
public string Name => "MusicBrainz Track";
/// <inheritdoc />
public string Key => MetadataProviders.MusicBrainzTrack.ToString();
/// <inheritdoc />
public string UrlFormatString => "https://musicbrainz.org/track/{0}";
public bool Supports(IHasProviderIds item)
{
return item is Audio;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Audio;
}
public class ImvdbId : IExternalId
{
/// <inheritdoc />
public string Name => "IMVDb";
/// <inheritdoc />
public string Key => "IMVDb";
/// <inheritdoc />
public string UrlFormatString => null;
/// <inheritdoc />
public bool Supports(IHasProviderIds item)
{
return item is MusicVideo;
}
=> item is MusicVideo;
}
}

View File

@ -16,9 +16,8 @@ namespace MediaBrowser.Providers.Music
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
IUserDataManager userDataManager,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.MusicGenres
{
public class MusicGenreMetadataService : MetadataService<MusicGenre, ItemLookupInfo>
{
public MusicGenreMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<MusicGenre> source, MetadataResult<MusicGenre> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public MusicGenreMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.People
{
public class PersonMetadataService : MetadataService<Person, PersonLookupInfo>
{
public PersonMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Person> source, MetadataResult<Person> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public PersonMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -32,23 +32,22 @@ namespace MediaBrowser.Providers.People
_tvDbClientManager = tvDbClientManager;
}
public string Name => ProviderName;
/// <inheritdoc />
public string Name => "TheTVDB";
public static string ProviderName => "TheTVDB";
/// <inheritdoc />
public int Order => 1;
public bool Supports(BaseItem item)
{
return item is Person;
}
/// <inheritdoc />
public bool Supports(BaseItem item) => item is Person;
/// <inheritdoc />
public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{
return new List<ImageType>
{
ImageType.Primary
};
yield return ImageType.Primary;
}
/// <inheritdoc />
public async Task<IEnumerable<RemoteImageInfo>> GetImages(BaseItem item, CancellationToken cancellationToken)
{
var seriesWithPerson = _libraryManager.GetItemList(new InternalItemsQuery
@ -104,8 +103,7 @@ namespace MediaBrowser.Providers.People
}
}
public int Order => 1;
/// <inheritdoc />
public Task<HttpResponseInfo> GetImageResponse(string url, CancellationToken cancellationToken)
{
return _httpClient.GetResponse(new HttpRequestOptions

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Photos
{
public class PhotoAlbumMetadataService : MetadataService<PhotoAlbum, ItemLookupInfo>
{
public PhotoAlbumMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<PhotoAlbum> source, MetadataResult<PhotoAlbum> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public PhotoAlbumMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Photos
{
public class PhotoMetadataService : MetadataService<Photo, ItemLookupInfo>
{
public PhotoMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Photo> source, MetadataResult<Photo> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public PhotoMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -13,11 +13,30 @@ namespace MediaBrowser.Providers.Playlists
{
public class PlaylistMetadataService : MetadataService<Playlist, ItemLookupInfo>
{
protected override IList<BaseItem> GetChildrenForMetadataUpdates(Playlist item)
public PlaylistMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
return item.GetLinkedChildren();
}
/// <inheritdoc />
protected override bool EnableUpdatingGenresFromChildren => true;
/// <inheritdoc />
protected override bool EnableUpdatingOfficialRatingFromChildren => true;
/// <inheritdoc />
protected override bool EnableUpdatingStudiosFromChildren => true;
/// <inheritdoc />
protected override IList<BaseItem> GetChildrenForMetadataUpdates(Playlist item)
=> item.GetLinkedChildren();
/// <inheritdoc />
protected override void MergeData(MetadataResult<Playlist> source, MetadataResult<Playlist> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
@ -32,15 +51,5 @@ namespace MediaBrowser.Providers.Playlists
targetItem.Shares = sourceItem.Shares;
}
}
public PlaylistMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
protected override bool EnableUpdatingGenresFromChildren => true;
protected override bool EnableUpdatingOfficialRatingFromChildren => true;
protected override bool EnableUpdatingStudiosFromChildren => true;
}
}

View File

@ -11,13 +11,19 @@ namespace MediaBrowser.Providers.Studios
{
public class StudioMetadataService : MetadataService<Studio, ItemLookupInfo>
{
public StudioMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem, ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Studio> source, MetadataResult<Studio> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public StudioMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -19,6 +19,7 @@ using MediaBrowser.Model.Globalization;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Providers;
using Microsoft.Extensions.Logging;
using static MediaBrowser.Model.IO.StreamDefaults;
namespace MediaBrowser.Providers.Subtitles
{
@ -30,8 +31,6 @@ namespace MediaBrowser.Providers.Subtitles
private readonly ILibraryMonitor _monitor;
private readonly IMediaSourceManager _mediaSourceManager;
public event EventHandler<SubtitleDownloadFailureEventArgs> SubtitleDownloadFailure;
private ILocalizationManager _localization;
public SubtitleManager(
@ -48,17 +47,18 @@ namespace MediaBrowser.Providers.Subtitles
_localization = localizationManager;
}
/// <inheritdoc />
public event EventHandler<SubtitleDownloadFailureEventArgs> SubtitleDownloadFailure;
/// <inheritdoc />
public void AddParts(IEnumerable<ISubtitleProvider> subtitleProviders)
{
_subtitleProviders = subtitleProviders
.OrderBy(i =>
{
var hasOrder = i as IHasOrder;
return hasOrder == null ? 0 : hasOrder.Order;
})
.OrderBy(i => !(i is IHasOrder hasOrder) ? 0 : hasOrder.Order)
.ToArray();
}
/// <inheritdoc />
public async Task<RemoteSubtitleInfo[]> SearchSubtitles(SubtitleSearchRequest request, CancellationToken cancellationToken)
{
if (request.Language != null)
@ -104,7 +104,7 @@ namespace MediaBrowser.Providers.Subtitles
_logger.LogError(ex, "Error downloading subtitles from {Provider}", provider.Name);
}
}
return new RemoteSubtitleInfo[] { };
return Array.Empty<RemoteSubtitleInfo>();
}
var tasks = providers.Select(async i =>
@ -120,7 +120,7 @@ namespace MediaBrowser.Providers.Subtitles
catch (Exception ex)
{
_logger.LogError(ex, "Error downloading subtitles from {0}", i.Name);
return new RemoteSubtitleInfo[] { };
return Array.Empty<RemoteSubtitleInfo>();
}
});
@ -129,6 +129,7 @@ namespace MediaBrowser.Providers.Subtitles
return results.SelectMany(i => i).ToArray();
}
/// <inheritdoc />
public Task DownloadSubtitles(Video video, string subtitleId, CancellationToken cancellationToken)
{
var libraryOptions = BaseItem.LibraryManager.GetLibraryOptions(video);
@ -136,7 +137,9 @@ namespace MediaBrowser.Providers.Subtitles
return DownloadSubtitles(video, libraryOptions, subtitleId, cancellationToken);
}
public async Task DownloadSubtitles(Video video,
/// <inheritdoc />
public async Task DownloadSubtitles(
Video video,
LibraryOptions libraryOptions,
string subtitleId,
CancellationToken cancellationToken)
@ -151,31 +154,29 @@ namespace MediaBrowser.Providers.Subtitles
var response = await GetRemoteSubtitles(subtitleId, cancellationToken).ConfigureAwait(false);
using (var stream = response.Stream)
using (var memoryStream = new MemoryStream())
{
using (var memoryStream = new MemoryStream())
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
var savePaths = new List<string>();
var saveFileName = Path.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLowerInvariant();
if (response.IsForced)
{
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
var savePaths = new List<string>();
var saveFileName = Path.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLowerInvariant();
if (response.IsForced)
{
saveFileName += ".forced";
}
saveFileName += "." + response.Format.ToLowerInvariant();
if (saveInMediaFolder)
{
savePaths.Add(Path.Combine(video.ContainingFolderPath, saveFileName));
}
savePaths.Add(Path.Combine(video.GetInternalMetadataPath(), saveFileName));
await TrySaveToFiles(memoryStream, savePaths).ConfigureAwait(false);
saveFileName += ".forced";
}
saveFileName += "." + response.Format.ToLowerInvariant();
if (saveInMediaFolder)
{
savePaths.Add(Path.Combine(video.ContainingFolderPath, saveFileName));
}
savePaths.Add(Path.Combine(video.GetInternalMetadataPath(), saveFileName));
await TrySaveToFiles(memoryStream, savePaths).ConfigureAwait(false);
}
}
catch (RateLimitExceededException)
@ -209,7 +210,7 @@ namespace MediaBrowser.Providers.Subtitles
{
Directory.CreateDirectory(Path.GetDirectoryName(savePath));
using (var fs = _fileSystem.GetFileStream(savePath, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read, true))
using (var fs = new FileStream(savePath, FileMode.Create, FileAccess.Write, FileShare.Read, DefaultFileStreamBufferSize, true))
{
await stream.CopyToAsync(fs).ConfigureAwait(false);
}
@ -237,11 +238,12 @@ namespace MediaBrowser.Providers.Subtitles
}
}
/// <inheritdoc />
public Task<RemoteSubtitleInfo[]> SearchSubtitles(Video video, string language, bool? isPerfectMatch, CancellationToken cancellationToken)
{
if (video.VideoType != VideoType.VideoFile)
{
return Task.FromResult(new RemoteSubtitleInfo[] { });
return Task.FromResult(Array.Empty<RemoteSubtitleInfo>());
}
VideoContentType mediaType;
@ -257,7 +259,7 @@ namespace MediaBrowser.Providers.Subtitles
else
{
// These are the only supported types
return Task.FromResult(new RemoteSubtitleInfo[] { });
return Task.FromResult(Array.Empty<RemoteSubtitleInfo>());
}
var request = new SubtitleSearchRequest
@ -274,9 +276,7 @@ namespace MediaBrowser.Providers.Subtitles
IsPerfectMatch = isPerfectMatch ?? false
};
var episode = video as Episode;
if (episode != null)
if (video is Episode episode)
{
request.IndexNumberEnd = episode.IndexNumberEnd;
request.SeriesName = episode.SeriesName;
@ -303,6 +303,7 @@ namespace MediaBrowser.Providers.Subtitles
return _subtitleProviders.First(i => string.Equals(id, GetProviderId(i.Name)));
}
/// <inheritdoc />
public Task DeleteSubtitles(BaseItem item, int index)
{
var stream = _mediaSourceManager.GetMediaStreams(new MediaStreamQuery
@ -328,16 +329,18 @@ namespace MediaBrowser.Providers.Subtitles
return item.RefreshMetadata(CancellationToken.None);
}
/// <inheritdoc />
public Task<SubtitleResponse> GetRemoteSubtitles(string id, CancellationToken cancellationToken)
{
var parts = id.Split(new[] { '_' }, 2);
var provider = GetProvider(parts.First());
var provider = GetProvider(parts[0]);
id = parts.Last();
return provider.GetSubtitles(id, cancellationToken);
}
/// <inheritdoc />
public SubtitleProviderInfo[] GetSupportedProviders(BaseItem video)
{
VideoContentType mediaType;
@ -353,7 +356,7 @@ namespace MediaBrowser.Providers.Subtitles
else
{
// These are the only supported types
return new SubtitleProviderInfo[] { };
return Array.Empty<SubtitleProviderInfo>();
}
return _subtitleProviders

View File

@ -16,17 +16,17 @@ namespace MediaBrowser.Providers.TV
{
public class DummySeasonProvider
{
private readonly IServerConfigurationManager _config;
private readonly ILogger _logger;
private readonly ILocalizationManager _localization;
private readonly ILibraryManager _libraryManager;
private readonly IFileSystem _fileSystem;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
public DummySeasonProvider(IServerConfigurationManager config, ILogger logger, ILocalizationManager localization, ILibraryManager libraryManager, IFileSystem fileSystem)
public DummySeasonProvider(
ILogger logger,
ILocalizationManager localization,
ILibraryManager libraryManager,
IFileSystem fileSystem)
{
_config = config;
_logger = logger;
_localization = localization;
_libraryManager = libraryManager;
@ -127,9 +127,14 @@ namespace MediaBrowser.Providers.TV
bool isVirtualItem,
CancellationToken cancellationToken)
{
var seasonName = seasonNumber == 0 ?
_libraryManager.GetLibraryOptions(series).SeasonZeroDisplayName :
(seasonNumber.HasValue ? string.Format(_localization.GetLocalizedString("NameSeasonNumber"), seasonNumber.Value.ToString(_usCulture)) : _localization.GetLocalizedString("NameSeasonUnknown"));
var seasonName = seasonNumber == 0
? _libraryManager.GetLibraryOptions(series).SeasonZeroDisplayName
: (seasonNumber.HasValue
? string.Format(
CultureInfo.InvariantCulture,
_localization.GetLocalizedString("NameSeasonNumber"),
seasonNumber.Value)
: _localization.GetLocalizedString("NameSeasonUnknown"));
_logger.LogInformation("Creating Season {0} entry for {1}", seasonName, series.Name);
@ -137,7 +142,9 @@ namespace MediaBrowser.Providers.TV
{
Name = seasonName,
IndexNumber = seasonNumber,
Id = _libraryManager.GetNewItemId((series.Id + (seasonNumber ?? -1).ToString(_usCulture) + seasonName), typeof(Season)),
Id = _libraryManager.GetNewItemId(
series.Id + (seasonNumber ?? -1).ToString(CultureInfo.InvariantCulture) + seasonName,
typeof(Season)),
IsVirtualItem = isVirtualItem,
SeriesId = series.Id,
SeriesName = series.Name
@ -147,7 +154,7 @@ namespace MediaBrowser.Providers.TV
series.AddChild(season, cancellationToken);
await season.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false);
await season.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), cancellationToken).ConfigureAwait(false);
return season;
}

View File

@ -12,6 +12,17 @@ namespace MediaBrowser.Providers.TV
{
public class EpisodeMetadataService : MetadataService<Episode, EpisodeInfo>
{
public EpisodeMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override ItemUpdateType BeforeSaveInternal(Episode item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.BeforeSaveInternal(item, isFullRefresh, currentUpdateType);
@ -54,6 +65,7 @@ namespace MediaBrowser.Providers.TV
return updateType;
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Episode> source, MetadataResult<Episode> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
@ -81,9 +93,5 @@ namespace MediaBrowser.Providers.TV
targetItem.IndexNumberEnd = sourceItem.IndexNumberEnd;
}
}
public EpisodeMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -19,6 +19,8 @@ namespace MediaBrowser.Providers.TV
{
public class MissingEpisodeProvider
{
private const double UnairedEpisodeThresholdDays = 2;
private readonly IServerConfigurationManager _config;
private readonly ILogger _logger;
private readonly ILibraryManager _libraryManager;
@ -26,9 +28,6 @@ namespace MediaBrowser.Providers.TV
private readonly IFileSystem _fileSystem;
private readonly TvDbClientManager _tvDbClientManager;
private readonly CultureInfo _usCulture = new CultureInfo("en-US");
private const double UnairedEpisodeThresholdDays = 2;
public MissingEpisodeProvider(
ILogger logger,
IServerConfigurationManager config,
@ -61,7 +60,7 @@ namespace MediaBrowser.Providers.TV
DateTime.TryParse(i.FirstAired, out var firstAired);
var seasonNumber = i.AiredSeason.GetValueOrDefault(-1);
var episodeNumber = i.AiredEpisodeNumber.GetValueOrDefault(-1);
return (seasonNumber: seasonNumber, episodeNumber: episodeNumber, firstAired: firstAired);
return (seasonNumber, episodeNumber, firstAired);
})
.Where(i => i.seasonNumber != -1 && i.episodeNumber != -1)
.OrderBy(i => i.seasonNumber)
@ -247,8 +246,9 @@ namespace MediaBrowser.Providers.TV
/// </summary>
/// <param name="allRecursiveChildren"></param>
/// <param name="episodeLookup">The episode lookup.</param>
/// <returns>Task{System.Boolean}.</returns>
private bool RemoveObsoleteOrMissingSeasons(IList<BaseItem> allRecursiveChildren,
/// <returns><see cref="bool" />.</returns>
private bool RemoveObsoleteOrMissingSeasons(
IList<BaseItem> allRecursiveChildren,
IEnumerable<(int seasonNumber, int episodeNumber, DateTime firstAired)> episodeLookup)
{
var existingSeasons = allRecursiveChildren.OfType<Season>().ToList();
@ -298,7 +298,6 @@ namespace MediaBrowser.Providers.TV
_libraryManager.DeleteItem(seasonToRemove, new DeleteOptions
{
DeleteFileLocation = true
}, false);
hasChanges = true;
@ -322,18 +321,20 @@ namespace MediaBrowser.Providers.TV
if (season == null)
{
var provider = new DummySeasonProvider(_config, _logger, _localization, _libraryManager, _fileSystem);
var provider = new DummySeasonProvider(_logger, _localization, _libraryManager, _fileSystem);
season = await provider.AddSeason(series, seasonNumber, true, cancellationToken).ConfigureAwait(false);
}
var name = $"Episode {episodeNumber.ToString(_usCulture)}";
var name = "Episode " + episodeNumber.ToString(CultureInfo.InvariantCulture);
var episode = new Episode
{
Name = name,
IndexNumber = episodeNumber,
ParentIndexNumber = seasonNumber,
Id = _libraryManager.GetNewItemId(series.Id + seasonNumber.ToString(_usCulture) + name, typeof(Episode)),
Id = _libraryManager.GetNewItemId(
series.Id + seasonNumber.ToString(CultureInfo.InvariantCulture) + name,
typeof(Episode)),
IsVirtualItem = true,
SeasonId = season?.Id ?? Guid.Empty,
SeriesId = series.Id
@ -341,7 +342,7 @@ namespace MediaBrowser.Providers.TV
season.AddChild(episode, cancellationToken);
await episode.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_logger, _fileSystem)), cancellationToken).ConfigureAwait(false);
await episode.RefreshMetadata(new MetadataRefreshOptions(new DirectoryService(_fileSystem)), cancellationToken).ConfigureAwait(false);
}
/// <summary>
@ -351,7 +352,7 @@ namespace MediaBrowser.Providers.TV
/// <param name="seasonCounts"></param>
/// <param name="episodeTuple"></param>
/// <returns>Episode.</returns>
private Episode GetExistingEpisode(IList<Episode> existingEpisodes, IReadOnlyDictionary<int, int> seasonCounts, (int seasonNumber, int episodeNumber, DateTime firstAired) episodeTuple)
private Episode GetExistingEpisode(IEnumerable<Episode> existingEpisodes, IReadOnlyDictionary<int, int> seasonCounts, (int seasonNumber, int episodeNumber, DateTime firstAired) episodeTuple)
{
var seasonNumber = episodeTuple.seasonNumber;
var episodeNumber = episodeTuple.episodeNumber;
@ -380,9 +381,6 @@ namespace MediaBrowser.Providers.TV
}
private Episode GetExistingEpisode(IEnumerable<Episode> existingEpisodes, int season, int episode)
{
return existingEpisodes
.FirstOrDefault(i => i.ParentIndexNumber == season && i.ContainsEpisodeNumber(episode));
}
=> existingEpisodes.FirstOrDefault(i => i.ParentIndexNumber == season && i.ContainsEpisodeNumber(episode));
}
}

View File

@ -15,6 +15,17 @@ namespace MediaBrowser.Providers.TV
{
public class SeasonMetadataService : MetadataService<Season, SeasonInfo>
{
public SeasonMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override ItemUpdateType BeforeSaveInternal(Season item, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.BeforeSaveInternal(item, isFullRefresh, currentUpdateType);
@ -54,13 +65,14 @@ namespace MediaBrowser.Providers.TV
return updateType;
}
/// <inheritdoc />
protected override bool EnableUpdatingPremiereDateFromChildren => true;
/// <inheritdoc />
protected override IList<BaseItem> GetChildrenForMetadataUpdates(Season item)
{
return item.GetEpisodes();
}
=> item.GetEpisodes();
/// <inheritdoc />
protected override ItemUpdateType UpdateMetadataFromChildren(Season item, IList<BaseItem> children, bool isFullRefresh, ItemUpdateType currentUpdateType)
{
var updateType = base.UpdateMetadataFromChildren(item, children, isFullRefresh, currentUpdateType);
@ -73,6 +85,7 @@ namespace MediaBrowser.Providers.TV
return updateType;
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Season> source, MetadataResult<Season> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
@ -90,9 +103,5 @@ namespace MediaBrowser.Providers.TV
return ItemUpdateType.None;
}
public SeasonMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -24,22 +24,21 @@ namespace MediaBrowser.Providers.TV
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
IUserDataManager userDataManager,
ILibraryManager libraryManager,
ILocalizationManager localization,
TvDbClientManager tvDbClientManager
)
: base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
TvDbClientManager tvDbClientManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
_localization = localization;
_tvDbClientManager = tvDbClientManager;
}
/// <inheritdoc />
protected override async Task AfterMetadataRefresh(Series item, MetadataRefreshOptions refreshOptions, CancellationToken cancellationToken)
{
await base.AfterMetadataRefresh(item, refreshOptions, cancellationToken).ConfigureAwait(false);
var seasonProvider = new DummySeasonProvider(ServerConfigurationManager, Logger, _localization, LibraryManager, FileSystem);
var seasonProvider = new DummySeasonProvider(Logger, _localization, LibraryManager, FileSystem);
await seasonProvider.Run(item, cancellationToken).ConfigureAwait(false);
// TODO why does it not register this itself omg
@ -60,6 +59,7 @@ namespace MediaBrowser.Providers.TV
}
}
/// <inheritdoc />
protected override bool IsFullLocalMetadata(Series item)
{
if (string.IsNullOrWhiteSpace(item.Overview))
@ -73,6 +73,7 @@ namespace MediaBrowser.Providers.TV
return base.IsFullLocalMetadata(item);
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Series> source, MetadataResult<Series> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);

View File

@ -7,57 +7,62 @@ namespace MediaBrowser.Providers.TV
{
public class Zap2ItExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "Zap2It";
/// <inheritdoc />
public string Key => MetadataProviders.Zap2It.ToString();
/// <inheritdoc />
public string UrlFormatString => "http://tvlistings.zap2it.com/overview.html?programSeriesId={0}";
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Series;
}
public class TvdbExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheTVDB";
/// <inheritdoc />
public string Key => MetadataProviders.Tvdb.ToString();
/// <inheritdoc />
public string UrlFormatString => TvdbUtils.TvdbBaseUrl + "?tab=series&id={0}";
public bool Supports(IHasProviderIds item)
{
return item is Series;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Series;
}
public class TvdbSeasonExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheTVDB";
/// <inheritdoc />
public string Key => MetadataProviders.Tvdb.ToString();
/// <inheritdoc />
public string UrlFormatString => null;
public bool Supports(IHasProviderIds item)
{
return item is Season;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Season;
}
public class TvdbEpisodeExternalId : IExternalId
{
/// <inheritdoc />
public string Name => "TheTVDB";
/// <inheritdoc />
public string Key => MetadataProviders.Tvdb.ToString();
/// <inheritdoc />
public string UrlFormatString => TvdbUtils.TvdbBaseUrl + "?tab=episode&id={0}";
public bool Supports(IHasProviderIds item)
{
return item is Episode;
}
/// <inheritdoc />
public bool Supports(IHasProviderIds item) => item is Episode;
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Users
{
public class UserMetadataService : MetadataService<User, ItemLookupInfo>
{
public UserMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<User> source, MetadataResult<User> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public UserMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,16 +11,24 @@ namespace MediaBrowser.Providers.Videos
{
public class VideoMetadataService : MetadataService<Video, ItemLookupInfo>
{
public VideoMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
// Make sure the type-specific services get picked first
public override int Order => 10;
/// <inheritdoc />
protected override void MergeData(MetadataResult<Video> source, MetadataResult<Video> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public VideoMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}

View File

@ -11,13 +11,20 @@ namespace MediaBrowser.Providers.Years
{
public class YearMetadataService : MetadataService<Year, ItemLookupInfo>
{
public YearMetadataService(
IServerConfigurationManager serverConfigurationManager,
ILogger logger,
IProviderManager providerManager,
IFileSystem fileSystem,
ILibraryManager libraryManager)
: base(serverConfigurationManager, logger, providerManager, fileSystem, libraryManager)
{
}
/// <inheritdoc />
protected override void MergeData(MetadataResult<Year> source, MetadataResult<Year> target, MetadataFields[] lockedFields, bool replaceData, bool mergeMetadataSettings)
{
ProviderUtils.MergeBaseItemData(source, target, lockedFields, replaceData, mergeMetadataSettings);
}
public YearMetadataService(IServerConfigurationManager serverConfigurationManager, ILogger logger, IProviderManager providerManager, IFileSystem fileSystem, IUserDataManager userDataManager, ILibraryManager libraryManager) : base(serverConfigurationManager, logger, providerManager, fileSystem, userDataManager, libraryManager)
{
}
}
}