update image saver
This commit is contained in:
parent
9c86c8fe2b
commit
ac3ec6d185
|
@ -995,7 +995,7 @@ namespace Emby.Server.Implementations.Connect
|
||||||
|
|
||||||
if (changed)
|
if (changed)
|
||||||
{
|
{
|
||||||
await _providerManager.SaveImage(user, imageUrl, null, ImageType.Primary, null, CancellationToken.None).ConfigureAwait(false);
|
await _providerManager.SaveImage(user, imageUrl, ImageType.Primary, null, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
await user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
|
await user.RefreshMetadata(new MetadataRefreshOptions(_fileSystem)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2760,7 +2760,6 @@ namespace Emby.Server.Implementations.Library
|
||||||
return ItemRepository.UpdatePeople(item.Id, people);
|
return ItemRepository.UpdatePeople(item.Id, people);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly SemaphoreSlim _dynamicImageResourcePool = new SemaphoreSlim(1, 1);
|
|
||||||
public async Task<ItemImageInfo> ConvertImageToLocal(IHasImages item, ItemImageInfo image, int imageIndex)
|
public async Task<ItemImageInfo> ConvertImageToLocal(IHasImages item, ItemImageInfo image, int imageIndex)
|
||||||
{
|
{
|
||||||
foreach (var url in image.Path.Split('|'))
|
foreach (var url in image.Path.Split('|'))
|
||||||
|
@ -2769,7 +2768,7 @@ namespace Emby.Server.Implementations.Library
|
||||||
{
|
{
|
||||||
_logger.Debug("ConvertImageToLocal item {0} - image url: {1}", item.Id, url);
|
_logger.Debug("ConvertImageToLocal item {0} - image url: {1}", item.Id, url);
|
||||||
|
|
||||||
await _providerManagerFactory().SaveImage(item, url, _dynamicImageResourcePool, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false);
|
await _providerManagerFactory().SaveImage(item, url, image.Type, imageIndex, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
var newImage = item.GetImageInfo(image.Type, imageIndex);
|
var newImage = item.GetImageInfo(image.Type, imageIndex);
|
||||||
|
|
||||||
|
|
|
@ -210,7 +210,7 @@ namespace MediaBrowser.Api.Images
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
private async Task DownloadRemoteImage(BaseItem item, BaseDownloadRemoteImage request)
|
private async Task DownloadRemoteImage(BaseItem item, BaseDownloadRemoteImage request)
|
||||||
{
|
{
|
||||||
await _providerManager.SaveImage(item, request.ImageUrl, null, request.Type, null, CancellationToken.None).ConfigureAwait(false);
|
await _providerManager.SaveImage(item, request.ImageUrl, request.Type, null, CancellationToken.None).ConfigureAwait(false);
|
||||||
|
|
||||||
await item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
|
await item.UpdateToRepository(ItemUpdateType.ImageUpdate, CancellationToken.None).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -788,7 +788,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
query.IsVirtualUnaired,
|
query.IsVirtualUnaired,
|
||||||
query.IsUnaired);
|
query.IsUnaired);
|
||||||
|
|
||||||
if (collapseBoxSetItems)
|
if (collapseBoxSetItems && user != null)
|
||||||
{
|
{
|
||||||
items = CollapseBoxSetItemsIfNeeded(items, query, queryParent, user, configurationManager);
|
items = CollapseBoxSetItemsIfNeeded(items, query, queryParent, user, configurationManager);
|
||||||
}
|
}
|
||||||
|
@ -1119,13 +1119,11 @@ namespace MediaBrowser.Controller.Entities
|
||||||
InternalItemsQuery query,
|
InternalItemsQuery query,
|
||||||
ILibraryManager libraryManager, bool enableSorting)
|
ILibraryManager libraryManager, bool enableSorting)
|
||||||
{
|
{
|
||||||
var user = query.User;
|
|
||||||
|
|
||||||
items = items.DistinctBy(i => i.GetPresentationUniqueKey(), StringComparer.OrdinalIgnoreCase);
|
items = items.DistinctBy(i => i.GetPresentationUniqueKey(), StringComparer.OrdinalIgnoreCase);
|
||||||
|
|
||||||
if (query.SortBy.Length > 0)
|
if (query.SortBy.Length > 0)
|
||||||
{
|
{
|
||||||
items = libraryManager.Sort(items, user, query.SortBy, query.SortOrder);
|
items = libraryManager.Sort(items, query.User, query.SortBy, query.SortOrder);
|
||||||
}
|
}
|
||||||
|
|
||||||
var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray();
|
var itemsArray = totalRecordLimit.HasValue ? items.Take(totalRecordLimit.Value).ToArray() : items.ToArray();
|
||||||
|
|
|
@ -47,12 +47,11 @@ namespace MediaBrowser.Controller.Providers
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="item">The item.</param>
|
/// <param name="item">The item.</param>
|
||||||
/// <param name="url">The URL.</param>
|
/// <param name="url">The URL.</param>
|
||||||
/// <param name="resourcePool">The resource pool.</param>
|
|
||||||
/// <param name="type">The type.</param>
|
/// <param name="type">The type.</param>
|
||||||
/// <param name="imageIndex">Index of the image.</param>
|
/// <param name="imageIndex">Index of the image.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
Task SaveImage(IHasImages item, string url, SemaphoreSlim resourcePool, ImageType type, int? imageIndex, CancellationToken cancellationToken);
|
Task SaveImage(IHasImages item, string url, ImageType type, int? imageIndex, CancellationToken cancellationToken);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the image.
|
/// Saves the image.
|
||||||
|
|
|
@ -16,7 +16,6 @@ using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using MediaBrowser.Controller.IO;
|
|
||||||
using MediaBrowser.Model.IO;
|
using MediaBrowser.Model.IO;
|
||||||
|
|
||||||
namespace MediaBrowser.Providers.Manager
|
namespace MediaBrowser.Providers.Manager
|
||||||
|
@ -234,6 +233,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
return retryPath;
|
return retryPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private SemaphoreSlim _imageSaveSemaphore = new SemaphoreSlim(1, 1);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Saves the image to location.
|
/// Saves the image to location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -247,11 +247,13 @@ namespace MediaBrowser.Providers.Manager
|
||||||
|
|
||||||
var parentFolder = Path.GetDirectoryName(path);
|
var parentFolder = Path.GetDirectoryName(path);
|
||||||
|
|
||||||
_libraryMonitor.ReportFileSystemChangeBeginning(path);
|
await _imageSaveSemaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||||
_libraryMonitor.ReportFileSystemChangeBeginning(parentFolder);
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
_libraryMonitor.ReportFileSystemChangeBeginning(path);
|
||||||
|
_libraryMonitor.ReportFileSystemChangeBeginning(parentFolder);
|
||||||
|
|
||||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
|
||||||
// If the file is currently hidden we'll have to remove that or the save will fail
|
// If the file is currently hidden we'll have to remove that or the save will fail
|
||||||
|
@ -283,6 +285,8 @@ namespace MediaBrowser.Providers.Manager
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
_imageSaveSemaphore.Release();
|
||||||
|
|
||||||
_libraryMonitor.ReportFileSystemChangeComplete(path, false);
|
_libraryMonitor.ReportFileSystemChangeComplete(path, false);
|
||||||
_libraryMonitor.ReportFileSystemChangeComplete(parentFolder, false);
|
_libraryMonitor.ReportFileSystemChangeComplete(parentFolder, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -253,7 +253,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ProviderManager.SaveImage(personEntity, imageUrl, null, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
await ProviderManager.SaveImage(personEntity, imageUrl, ImageType.Primary, null, cancellationToken).ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|
|
@ -123,12 +123,11 @@ namespace MediaBrowser.Providers.Manager
|
||||||
return Task.FromResult(ItemUpdateType.None);
|
return Task.FromResult(ItemUpdateType.None);
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task SaveImage(IHasImages item, string url, SemaphoreSlim resourcePool, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
public async Task SaveImage(IHasImages item, string url, ImageType type, int? imageIndex, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var response = await _httpClient.GetResponse(new HttpRequestOptions
|
var response = await _httpClient.GetResponse(new HttpRequestOptions
|
||||||
{
|
{
|
||||||
CancellationToken = cancellationToken,
|
CancellationToken = cancellationToken,
|
||||||
ResourcePool = resourcePool,
|
|
||||||
Url = url,
|
Url = url,
|
||||||
BufferContent = false
|
BufferContent = false
|
||||||
|
|
||||||
|
|
|
@ -127,14 +127,7 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using (var stream = await _httpClient.Get(new HttpRequestOptions
|
using (var stream = await OmdbProvider.GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
ResourcePool = OmdbProvider.ResourcePool,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
BufferContent = true
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
{
|
||||||
var resultList = new List<SearchResult>();
|
var resultList = new List<SearchResult>();
|
||||||
|
|
||||||
|
|
|
@ -296,14 +296,7 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
|
|
||||||
var url = string.Format("https://www.omdbapi.com/?i={0}&plot=full&tomatoes=true&r=json", imdbParam);
|
var url = string.Format("https://www.omdbapi.com/?i={0}&plot=full&tomatoes=true&r=json", imdbParam);
|
||||||
|
|
||||||
using (var stream = await _httpClient.Get(new HttpRequestOptions
|
using (var stream = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
ResourcePool = ResourcePool,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
BufferContent = true
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
{
|
||||||
var rootObject = _jsonSerializer.DeserializeFromStream<RootObject>(stream);
|
var rootObject = _jsonSerializer.DeserializeFromStream<RootObject>(stream);
|
||||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
@ -337,14 +330,7 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
|
|
||||||
var url = string.Format("https://www.omdbapi.com/?i={0}&season={1}&detail=full", imdbParam, seasonId);
|
var url = string.Format("https://www.omdbapi.com/?i={0}&season={1}&detail=full", imdbParam, seasonId);
|
||||||
|
|
||||||
using (var stream = await _httpClient.Get(new HttpRequestOptions
|
using (var stream = await GetOmdbResponse(_httpClient, url, cancellationToken).ConfigureAwait(false))
|
||||||
{
|
|
||||||
Url = url,
|
|
||||||
ResourcePool = ResourcePool,
|
|
||||||
CancellationToken = cancellationToken,
|
|
||||||
BufferContent = true
|
|
||||||
|
|
||||||
}).ConfigureAwait(false))
|
|
||||||
{
|
{
|
||||||
var rootObject = _jsonSerializer.DeserializeFromStream<SeasonRootObject>(stream);
|
var rootObject = _jsonSerializer.DeserializeFromStream<SeasonRootObject>(stream);
|
||||||
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
|
@ -354,6 +340,17 @@ namespace MediaBrowser.Providers.Omdb
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Task<Stream> GetOmdbResponse(IHttpClient httpClient, string url, CancellationToken cancellationToken)
|
||||||
|
{
|
||||||
|
return httpClient.Get(new HttpRequestOptions
|
||||||
|
{
|
||||||
|
Url = url,
|
||||||
|
ResourcePool = ResourcePool,
|
||||||
|
CancellationToken = cancellationToken,
|
||||||
|
BufferContent = true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
internal string GetDataFilePath(string imdbId)
|
internal string GetDataFilePath(string imdbId)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(imdbId))
|
if (string.IsNullOrEmpty(imdbId))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user