Fix all warnings in MediaBrowser.Providers

This commit is contained in:
Bond_009 2023-01-11 10:36:18 +01:00
parent 6dbdb4e9af
commit b934b346e1
21 changed files with 193 additions and 164 deletions

View File

@ -264,7 +264,8 @@ namespace MediaBrowser.Providers.Manager
var fileStreamOptions = AsyncFile.WriteOptions; var fileStreamOptions = AsyncFile.WriteOptions;
fileStreamOptions.Mode = FileMode.Create; fileStreamOptions.Mode = FileMode.Create;
fileStreamOptions.PreallocationSize = source.Length; fileStreamOptions.PreallocationSize = source.Length;
await using (var fs = new FileStream(path, fileStreamOptions)) var fs = new FileStream(path, fileStreamOptions);
await using (fs.ConfigureAwait(false))
{ {
await source.CopyToAsync(fs, cancellationToken).ConfigureAwait(false); await source.CopyToAsync(fs, cancellationToken).ConfigureAwait(false);
} }

View File

@ -502,15 +502,17 @@ namespace MediaBrowser.Providers.Manager
break; break;
} }
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await using (stream.ConfigureAwait(false))
await _providerManager.SaveImage( {
item, await _providerManager.SaveImage(
stream, item,
response.Content.Headers.ContentType?.MediaType, stream,
type, response.Content.Headers.ContentType?.MediaType,
null, type,
cancellationToken).ConfigureAwait(false); null,
cancellationToken).ConfigureAwait(false);
}
result.UpdateType |= ItemUpdateType.ImageUpdate; result.UpdateType |= ItemUpdateType.ImageUpdate;
return true; return true;
@ -626,14 +628,18 @@ namespace MediaBrowser.Providers.Manager
} }
} }
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await _providerManager.SaveImage( await using (stream.ConfigureAwait(false))
item, {
stream, await _providerManager.SaveImage(
response.Content.Headers.ContentType?.MediaType, item,
imageType, stream,
null, response.Content.Headers.ContentType?.MediaType,
cancellationToken).ConfigureAwait(false); imageType,
null,
cancellationToken).ConfigureAwait(false);
}
result.UpdateType |= ItemUpdateType.ImageUpdate; result.UpdateType |= ItemUpdateType.ImageUpdate;
} }
catch (HttpRequestException) catch (HttpRequestException)

View File

@ -182,14 +182,17 @@ namespace MediaBrowser.Providers.Manager
contentType = MimeTypes.GetMimeType(url); contentType = MimeTypes.GetMimeType(url);
} }
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await SaveImage( await using (stream.ConfigureAwait(false))
item, {
stream, await SaveImage(
contentType, item,
type, stream,
imageIndex, contentType,
cancellationToken).ConfigureAwait(false); type,
imageIndex,
cancellationToken).ConfigureAwait(false);
}
} }
/// <inheritdoc/> /// <inheritdoc/>

View File

@ -34,10 +34,6 @@
<CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>../jellyfin.ruleset</CodeAnalysisRuleSet>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<CodeAnalysisTreatWarningsAsErrors>false</CodeAnalysisTreatWarningsAsErrors>
</PropertyGroup>
<!-- Code Analyzers--> <!-- Code Analyzers-->
<ItemGroup Condition=" '$(Configuration)' == 'Debug' "> <ItemGroup Condition=" '$(Configuration)' == 'Debug' ">
<PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3"> <PackageReference Include="Microsoft.CodeAnalysis.BannedApiAnalyzers" Version="3.3.3">

View File

@ -140,7 +140,7 @@ namespace MediaBrowser.Providers.MediaInfo
if (attachmentStream is not null) if (attachmentStream is not null)
{ {
return await ExtractAttachment(item, attachmentStream, mediaSource, cancellationToken); return await ExtractAttachment(item, attachmentStream, mediaSource, cancellationToken).ConfigureAwait(false);
} }
// Fall back to EmbeddedImage streams // Fall back to EmbeddedImage streams

View File

@ -557,7 +557,7 @@ namespace MediaBrowser.Providers.MediaInfo
CancellationToken cancellationToken) CancellationToken cancellationToken)
{ {
var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1); var startIndex = currentStreams.Count == 0 ? 0 : (currentStreams.Select(i => i.Index).Max() + 1);
var externalSubtitleStreams = await _subtitleResolver.GetExternalStreamsAsync(video, startIndex, options.DirectoryService, false, cancellationToken); var externalSubtitleStreams = await _subtitleResolver.GetExternalStreamsAsync(video, startIndex, options.DirectoryService, false, cancellationToken).ConfigureAwait(false);
var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.Default || var enableSubtitleDownloading = options.MetadataRefreshMode == MetadataRefreshMode.Default ||
options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh; options.MetadataRefreshMode == MetadataRefreshMode.FullRefresh;
@ -611,7 +611,7 @@ namespace MediaBrowser.Providers.MediaInfo
// Rescan // Rescan
if (downloadedLanguages.Count > 0) if (downloadedLanguages.Count > 0)
{ {
externalSubtitleStreams = await _subtitleResolver.GetExternalStreamsAsync(video, startIndex, options.DirectoryService, true, cancellationToken); externalSubtitleStreams = await _subtitleResolver.GetExternalStreamsAsync(video, startIndex, options.DirectoryService, true, cancellationToken).ConfigureAwait(false);
} }
} }

View File

@ -4,6 +4,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text.Json; using System.Text.Json;
using System.Threading; using System.Threading;
@ -42,11 +43,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
/// <inheritdoc /> /// <inheritdoc />
public IEnumerable<ImageType> GetSupportedImages(BaseItem item) public IEnumerable<ImageType> GetSupportedImages(BaseItem item)
{ {
return new List<ImageType> yield return ImageType.Primary;
{ yield return ImageType.Disc;
ImageType.Primary,
ImageType.Disc
};
} }
/// <inheritdoc /> /// <inheritdoc />
@ -60,16 +58,19 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id); var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
await using FileStream jsonStream = AsyncFile.OpenRead(path); FileStream jsonStream = AsyncFile.OpenRead(path);
var obj = await JsonSerializer.DeserializeAsync<AudioDbAlbumProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (jsonStream.ConfigureAwait(false))
if (obj is not null && obj.album is not null && obj.album.Count > 0)
{ {
return GetImages(obj.album[0]); var obj = await JsonSerializer.DeserializeAsync<AudioDbAlbumProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
if (obj is not null && obj.album is not null && obj.album.Count > 0)
{
return GetImages(obj.album[0]);
}
} }
} }
return new List<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
private IEnumerable<RemoteImageInfo> GetImages(AudioDbAlbumProvider.Album item) private IEnumerable<RemoteImageInfo> GetImages(AudioDbAlbumProvider.Album item)

View File

@ -68,14 +68,17 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
var path = GetAlbumInfoPath(_config.ApplicationPaths, id); var path = GetAlbumInfoPath(_config.ApplicationPaths, id);
await using FileStream jsonStream = AsyncFile.OpenRead(path); FileStream jsonStream = AsyncFile.OpenRead(path);
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (jsonStream.ConfigureAwait(false))
if (obj is not null && obj.album is not null && obj.album.Count > 0)
{ {
result.Item = new MusicAlbum(); var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
result.HasMetadata = true;
ProcessResult(result.Item, obj.album[0], info.MetadataLanguage); if (obj is not null && obj.album is not null && obj.album.Count > 0)
{
result.Item = new MusicAlbum();
result.HasMetadata = true;
ProcessResult(result.Item, obj.album[0], info.MetadataLanguage);
}
} }
} }
@ -173,13 +176,18 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
Directory.CreateDirectory(Path.GetDirectoryName(path)); Directory.CreateDirectory(Path.GetDirectoryName(path));
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false); using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false);
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await using (stream.ConfigureAwait(false))
var fileStreamOptions = AsyncFile.WriteOptions; {
fileStreamOptions.Mode = FileMode.Create; var fileStreamOptions = AsyncFile.WriteOptions;
fileStreamOptions.PreallocationSize = stream.Length; fileStreamOptions.Mode = FileMode.Create;
await using var xmlFileStream = new FileStream(path, fileStreamOptions); fileStreamOptions.PreallocationSize = stream.Length;
await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false); var xmlFileStream = new FileStream(path, fileStreamOptions);
await using (xmlFileStream.ConfigureAwait(false))
{
await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false);
}
}
} }
private static string GetAlbumDataPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId) private static string GetAlbumDataPath(IApplicationPaths appPaths, string musicBrainzReleaseGroupId)

View File

@ -62,12 +62,15 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id); var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
await using FileStream jsonStream = AsyncFile.OpenRead(path); FileStream jsonStream = AsyncFile.OpenRead(path);
var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (jsonStream.ConfigureAwait(false))
if (obj is not null && obj.artists is not null && obj.artists.Count > 0)
{ {
return GetImages(obj.artists[0]); var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
if (obj is not null && obj.artists is not null && obj.artists.Count > 0)
{
return GetImages(obj.artists[0]);
}
} }
} }

View File

@ -67,14 +67,17 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
var path = GetArtistInfoPath(_config.ApplicationPaths, id); var path = GetArtistInfoPath(_config.ApplicationPaths, id);
await using FileStream jsonStream = AsyncFile.OpenRead(path); FileStream jsonStream = AsyncFile.OpenRead(path);
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (jsonStream.ConfigureAwait(false))
if (obj is not null && obj.artists is not null && obj.artists.Count > 0)
{ {
result.Item = new MusicArtist(); var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, _jsonOptions, cancellationToken).ConfigureAwait(false);
result.HasMetadata = true;
ProcessResult(result.Item, obj.artists[0], info.MetadataLanguage); if (obj is not null && obj.artists is not null && obj.artists.Count > 0)
{
result.Item = new MusicArtist();
result.HasMetadata = true;
ProcessResult(result.Item, obj.artists[0], info.MetadataLanguage);
}
} }
} }
@ -151,16 +154,21 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false); using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false);
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await using (stream.ConfigureAwait(false))
{
var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId);
Directory.CreateDirectory(Path.GetDirectoryName(path));
var path = GetArtistInfoPath(_config.ApplicationPaths, musicBrainzId); var fileStreamOptions = AsyncFile.WriteOptions;
Directory.CreateDirectory(Path.GetDirectoryName(path)); fileStreamOptions.Mode = FileMode.Create;
fileStreamOptions.PreallocationSize = stream.Length;
var fileStreamOptions = AsyncFile.WriteOptions; var xmlFileStream = new FileStream(path, fileStreamOptions);
fileStreamOptions.Mode = FileMode.Create; await using (xmlFileStream.ConfigureAwait(false))
fileStreamOptions.PreallocationSize = stream.Length; {
await using var xmlFileStream = new FileStream(path, fileStreamOptions); await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false);
await stream.CopyToAsync(xmlFileStream, cancellationToken).ConfigureAwait(false); }
}
} }
/// <summary> /// <summary>

View File

@ -137,29 +137,31 @@ namespace MediaBrowser.Providers.Plugins.Omdb
var url = OmdbProvider.GetOmdbUrl(urlQuery.ToString()); var url = OmdbProvider.GetOmdbUrl(urlQuery.ToString());
using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false); using var response = await _httpClientFactory.CreateClient(NamedClient.Default).GetAsync(url, cancellationToken).ConfigureAwait(false);
await using var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false); var stream = await response.Content.ReadAsStreamAsync(cancellationToken).ConfigureAwait(false);
await using (stream.ConfigureAwait(false))
if (isSearch)
{ {
var searchResultList = await JsonSerializer.DeserializeAsync<SearchResultList>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false); if (isSearch)
if (searchResultList?.Search is not null)
{ {
var resultCount = searchResultList.Search.Count; var searchResultList = await JsonSerializer.DeserializeAsync<SearchResultList>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
var result = new RemoteSearchResult[resultCount]; if (searchResultList?.Search is not null)
for (var i = 0; i < resultCount; i++)
{ {
result[i] = ResultToMetadataResult(searchResultList.Search[i], searchInfo, indexNumberEnd); var resultCount = searchResultList.Search.Count;
} var result = new RemoteSearchResult[resultCount];
for (var i = 0; i < resultCount; i++)
{
result[i] = ResultToMetadataResult(searchResultList.Search[i], searchInfo, indexNumberEnd);
}
return result; return result;
}
} }
} else
else
{
var result = await JsonSerializer.DeserializeAsync<SearchResult>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
if (string.Equals(result?.Response, "true", StringComparison.OrdinalIgnoreCase))
{ {
return new[] { ResultToMetadataResult(result, searchInfo, indexNumberEnd) }; var result = await JsonSerializer.DeserializeAsync<SearchResult>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
if (string.Equals(result?.Response, "true", StringComparison.OrdinalIgnoreCase))
{
return new[] { ResultToMetadataResult(result, searchInfo, indexNumberEnd) };
}
} }
} }

View File

@ -234,15 +234,21 @@ namespace MediaBrowser.Providers.Plugins.Omdb
internal async Task<RootObject> GetRootObject(string imdbId, CancellationToken cancellationToken) internal async Task<RootObject> GetRootObject(string imdbId, CancellationToken cancellationToken)
{ {
var path = await EnsureItemInfo(imdbId, cancellationToken).ConfigureAwait(false); var path = await EnsureItemInfo(imdbId, cancellationToken).ConfigureAwait(false);
await using var stream = AsyncFile.OpenRead(path); var stream = AsyncFile.OpenRead(path);
return await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (stream.ConfigureAwait(false))
{
return await JsonSerializer.DeserializeAsync<RootObject>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
}
} }
internal async Task<SeasonRootObject> GetSeasonRootObject(string imdbId, int seasonId, CancellationToken cancellationToken) internal async Task<SeasonRootObject> GetSeasonRootObject(string imdbId, int seasonId, CancellationToken cancellationToken)
{ {
var path = await EnsureSeasonInfo(imdbId, seasonId, cancellationToken).ConfigureAwait(false); var path = await EnsureSeasonInfo(imdbId, seasonId, cancellationToken).ConfigureAwait(false);
await using var stream = AsyncFile.OpenRead(path); var stream = AsyncFile.OpenRead(path);
return await JsonSerializer.DeserializeAsync<SeasonRootObject>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (stream.ConfigureAwait(false))
{
return await JsonSerializer.DeserializeAsync<SeasonRootObject>(stream, _jsonOptions, cancellationToken).ConfigureAwait(false);
}
} }
/// <summary>Gets OMDB URL.</summary> /// <summary>Gets OMDB URL.</summary>
@ -317,8 +323,11 @@ namespace MediaBrowser.Providers.Plugins.Omdb
imdbParam)); imdbParam));
var rootObject = await _httpClientFactory.CreateClient(NamedClient.Default).GetFromJsonAsync<RootObject>(url, _jsonOptions, cancellationToken).ConfigureAwait(false); var rootObject = await _httpClientFactory.CreateClient(NamedClient.Default).GetFromJsonAsync<RootObject>(url, _jsonOptions, cancellationToken).ConfigureAwait(false);
await using FileStream jsonFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous); FileStream jsonFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (jsonFileStream.ConfigureAwait(false))
{
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, _jsonOptions, cancellationToken).ConfigureAwait(false);
}
return path; return path;
} }
@ -357,8 +366,11 @@ namespace MediaBrowser.Providers.Plugins.Omdb
seasonId)); seasonId));
var rootObject = await _httpClientFactory.CreateClient(NamedClient.Default).GetFromJsonAsync<SeasonRootObject>(url, _jsonOptions, cancellationToken).ConfigureAwait(false); var rootObject = await _httpClientFactory.CreateClient(NamedClient.Default).GetFromJsonAsync<SeasonRootObject>(url, _jsonOptions, cancellationToken).ConfigureAwait(false);
await using FileStream jsonFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous); FileStream jsonFileStream = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, _jsonOptions, cancellationToken).ConfigureAwait(false); await using (jsonFileStream.ConfigureAwait(false))
{
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, _jsonOptions, cancellationToken).ConfigureAwait(false);
}
return path; return path;
} }

View File

@ -138,9 +138,15 @@ namespace MediaBrowser.Providers.Plugins.StudioImages
var httpClient = _httpClientFactory.CreateClient(NamedClient.Default); var httpClient = _httpClientFactory.CreateClient(NamedClient.Default);
Directory.CreateDirectory(Path.GetDirectoryName(file)); Directory.CreateDirectory(Path.GetDirectoryName(file));
await using var response = await httpClient.GetStreamAsync(url, cancellationToken).ConfigureAwait(false); var response = await httpClient.GetStreamAsync(url, cancellationToken).ConfigureAwait(false);
await using var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous); await using (response.ConfigureAwait(false))
await response.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false); {
var fileStream = new FileStream(file, FileMode.Create, FileAccess.Write, FileShare.None, IODefaults.FileStreamBufferSize, FileOptions.Asynchronous);
await using (fileStream.ConfigureAwait(false))
{
await response.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);
}
}
} }
return file; return file;

View File

@ -81,8 +81,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.BoxSets
var backdrops = collection.Images.Backdrops; var backdrops = collection.Images.Backdrops;
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count); var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language));
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language));
return remoteImages; return remoteImages;
} }

View File

@ -100,9 +100,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.Movies
var logos = movie.Images.Logos; var logos = movie.Images.Logos;
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count); var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language));
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language));
_tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language));
return remoteImages; return remoteImages;
} }

View File

@ -69,12 +69,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.People
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var profiles = personResult.Images.Profiles; return _tmdbClientManager.ConvertProfilesToRemoteImageInfo(personResult.Images.Profiles, language);
var remoteImages = new List<RemoteImageInfo>(profiles.Count);
_tmdbClientManager.ConvertProfilesToRemoteImageInfo(profiles, language, remoteImages);
return remoteImages;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -89,11 +89,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new List<RemoteImageInfo>(stills.Count); return _tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language);
_tmdbClientManager.ConvertStillsToRemoteImageInfo(stills, language, remoteImages);
return remoteImages;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -80,11 +80,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
return Enumerable.Empty<RemoteImageInfo>(); return Enumerable.Empty<RemoteImageInfo>();
} }
var remoteImages = new List<RemoteImageInfo>(posters.Count); return _tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages);
return remoteImages;
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -83,9 +83,9 @@ namespace MediaBrowser.Providers.Plugins.Tmdb.TV
var logos = series.Images.Logos; var logos = series.Images.Logos;
var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count); var remoteImages = new List<RemoteImageInfo>(posters.Count + backdrops.Count + logos.Count);
_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertPostersToRemoteImageInfo(posters, language));
_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertBackdropsToRemoteImageInfo(backdrops, language));
_tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language, remoteImages); remoteImages.AddRange(_tmdbClientManager.ConvertLogosToRemoteImageInfo(logos, language));
return remoteImages; return remoteImages;
} }

View File

@ -531,55 +531,45 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// </summary> /// </summary>
/// <param name="images">The input images.</param> /// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param> /// <returns>The remote images.</returns>
public void ConvertPostersToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results) public IEnumerable<RemoteImageInfo> ConvertPostersToRemoteImageInfo(IReadOnlyList<ImageData> images, string requestLanguage)
{ => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.PosterSize, ImageType.Primary, requestLanguage);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.PosterSize, ImageType.Primary, requestLanguage, results);
}
/// <summary> /// <summary>
/// Converts backdrop <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. /// Converts backdrop <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary> /// </summary>
/// <param name="images">The input images.</param> /// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param> /// <returns>The remote images.</returns>
public void ConvertBackdropsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results) public IEnumerable<RemoteImageInfo> ConvertBackdropsToRemoteImageInfo(IReadOnlyList<ImageData> images, string requestLanguage)
{ => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.BackdropSize, ImageType.Backdrop, requestLanguage);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.BackdropSize, ImageType.Backdrop, requestLanguage, results);
}
/// <summary> /// <summary>
/// Converts logo <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. /// Converts logo <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary> /// </summary>
/// <param name="images">The input images.</param> /// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param> /// <returns>The remote images.</returns>
public void ConvertLogosToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results) public IEnumerable<RemoteImageInfo> ConvertLogosToRemoteImageInfo(IReadOnlyList<ImageData> images, string requestLanguage)
{ => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.LogoSize, ImageType.Logo, requestLanguage);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.LogoSize, ImageType.Logo, requestLanguage, results);
}
/// <summary> /// <summary>
/// Converts profile <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. /// Converts profile <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary> /// </summary>
/// <param name="images">The input images.</param> /// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param> /// <returns>The remote images.</returns>
public void ConvertProfilesToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results) public IEnumerable<RemoteImageInfo> ConvertProfilesToRemoteImageInfo(IReadOnlyList<ImageData> images, string requestLanguage)
{ => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.ProfileSize, ImageType.Primary, requestLanguage);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.ProfileSize, ImageType.Primary, requestLanguage, results);
}
/// <summary> /// <summary>
/// Converts still <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. /// Converts still <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
/// </summary> /// </summary>
/// <param name="images">The input images.</param> /// <param name="images">The input images.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param> /// <returns>The remote images.</returns>
public void ConvertStillsToRemoteImageInfo(List<ImageData> images, string requestLanguage, List<RemoteImageInfo> results) public IEnumerable<RemoteImageInfo> ConvertStillsToRemoteImageInfo(IReadOnlyList<ImageData> images, string requestLanguage)
{ => ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.StillSize, ImageType.Primary, requestLanguage);
ConvertToRemoteImageInfo(images, Plugin.Instance.Configuration.StillSize, ImageType.Primary, requestLanguage, results);
}
/// <summary> /// <summary>
/// Converts <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s. /// Converts <see cref="ImageData"/>s into <see cref="RemoteImageInfo"/>s.
@ -588,8 +578,8 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
/// <param name="size">The size of the image to fetch.</param> /// <param name="size">The size of the image to fetch.</param>
/// <param name="type">The type of the image.</param> /// <param name="type">The type of the image.</param>
/// <param name="requestLanguage">The requested language.</param> /// <param name="requestLanguage">The requested language.</param>
/// <param name="results">The collection to add the remote images into.</param> /// <returns>The remote images.</returns>
private void ConvertToRemoteImageInfo(List<ImageData> images, string size, ImageType type, string requestLanguage, List<RemoteImageInfo> results) private IEnumerable<RemoteImageInfo> ConvertToRemoteImageInfo(IReadOnlyList<ImageData> images, string size, ImageType type, string requestLanguage)
{ {
// sizes provided are for original resolution, don't store them when downloading scaled images // sizes provided are for original resolution, don't store them when downloading scaled images
var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase); var scaleImage = !string.Equals(size, "original", StringComparison.OrdinalIgnoreCase);
@ -598,7 +588,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
{ {
var image = images[i]; var image = images[i];
results.Add(new RemoteImageInfo yield return new RemoteImageInfo
{ {
Url = GetUrl(size, image.FilePath), Url = GetUrl(size, image.FilePath),
CommunityRating = image.VoteAverage, CommunityRating = image.VoteAverage,
@ -609,7 +599,7 @@ namespace MediaBrowser.Providers.Plugins.Tmdb
ProviderName = TmdbUtils.ProviderName, ProviderName = TmdbUtils.ProviderName,
Type = type, Type = type,
RatingType = RatingType.Score RatingType = RatingType.Score
}); };
} }
} }

View File

@ -188,10 +188,16 @@ namespace MediaBrowser.Providers.Subtitles
{ {
var saveInMediaFolder = libraryOptions.SaveSubtitlesWithMedia; var saveInMediaFolder = libraryOptions.SaveSubtitlesWithMedia;
await using var stream = response.Stream; var memoryStream = new MemoryStream();
await using var memoryStream = new MemoryStream(); await using (memoryStream.ConfigureAwait(false))
await stream.CopyToAsync(memoryStream).ConfigureAwait(false); {
memoryStream.Position = 0; var stream = response.Stream;
await using (stream.ConfigureAwait(false))
{
await stream.CopyToAsync(memoryStream).ConfigureAwait(false);
memoryStream.Position = 0;
}
}
var savePaths = new List<string>(); var savePaths = new List<string>();
var saveFileName = Path.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLowerInvariant(); var saveFileName = Path.GetFileNameWithoutExtension(video.Path) + "." + response.Language.ToLowerInvariant();