mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 05:47:14 -04:00
Use streams instead of strings
This commit is contained in:
parent
f38970cbd3
commit
2a574914ea
@ -1038,6 +1038,7 @@ namespace Emby.Server.Implementations
|
|||||||
}
|
}
|
||||||
|
|
||||||
var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly);
|
var directories = Directory.EnumerateDirectories(path, "*.*", SearchOption.TopDirectoryOnly);
|
||||||
|
var jsonOptions = JsonDefaults.GetOptions();
|
||||||
|
|
||||||
foreach (var dir in directories)
|
foreach (var dir in directories)
|
||||||
{
|
{
|
||||||
@ -1046,8 +1047,8 @@ namespace Emby.Server.Implementations
|
|||||||
var metafile = Path.Combine(dir, "meta.json");
|
var metafile = Path.Combine(dir, "meta.json");
|
||||||
if (File.Exists(metafile))
|
if (File.Exists(metafile))
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(metafile);
|
using FileStream jsonStream = File.OpenRead(metafile);
|
||||||
var manifest = JsonSerializer.Deserialize<PluginManifest>(jsonString, JsonDefaults.GetOptions());
|
var manifest = JsonSerializer.DeserializeAsync<PluginManifest>(jsonStream, jsonOptions).GetAwaiter().GetResult();
|
||||||
|
|
||||||
if (!Version.TryParse(manifest.TargetAbi, out var targetAbi))
|
if (!Version.TryParse(manifest.TargetAbi, out var targetAbi))
|
||||||
{
|
{
|
||||||
|
@ -340,8 +340,8 @@ namespace Emby.Server.Implementations.Channels
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(path);
|
using FileStream jsonStream = File.OpenRead(path);
|
||||||
return JsonSerializer.Deserialize<List<MediaSourceInfo>>(jsonString, JsonDefaults.GetOptions()) ?? new List<MediaSourceInfo>();
|
return JsonSerializer.DeserializeAsync<List<MediaSourceInfo>>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult();
|
||||||
}
|
}
|
||||||
catch
|
catch
|
||||||
{
|
{
|
||||||
|
@ -46,8 +46,8 @@ namespace Emby.Server.Implementations.Library
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jsonString = await File.ReadAllTextAsync(cacheFilePath, cancellationToken).ConfigureAwait(false);
|
await using FileStream jsonStream = File.OpenRead(cacheFilePath);
|
||||||
JsonSerializer.Deserialize<MediaInfo>(jsonString, JsonDefaults.GetOptions());
|
await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// _logger.LogDebug("Found cached media info");
|
// _logger.LogDebug("Found cached media info");
|
||||||
}
|
}
|
||||||
|
@ -641,8 +641,8 @@ namespace Emby.Server.Implementations.Library
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var json = await File.ReadAllTextAsync(cacheFilePath, cancellationToken).ConfigureAwait(false);
|
await using FileStream jsonStream = File.OpenRead(cacheFilePath);
|
||||||
mediaInfo = JsonSerializer.Deserialize<MediaInfo>(json, JsonDefaults.GetOptions());
|
mediaInfo = await JsonSerializer.DeserializeAsync<MediaInfo>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// _logger.LogDebug("Found cached media info");
|
// _logger.LogDebug("Found cached media info");
|
||||||
}
|
}
|
||||||
|
@ -44,8 +44,8 @@ namespace Emby.Server.Implementations.LiveTv.EmbyTV
|
|||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var json = File.ReadAllText(_dataPath);
|
using FileStream jsonStream = File.OpenRead(_dataPath);
|
||||||
_items = JsonSerializer.Deserialize<T[]>(json, JsonDefaults.GetOptions());
|
_items = JsonSerializer.DeserializeAsync<T[]>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
@ -139,15 +139,8 @@ namespace Emby.Server.Implementations.ScheduledTasks
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var jsonString = File.ReadAllText(path);
|
using FileStream jsonStream = File.OpenRead(path);
|
||||||
if (!string.IsNullOrWhiteSpace(jsonString))
|
_lastExecutionResult = JsonSerializer.DeserializeAsync<TaskResult>(jsonStream, JsonDefaults.GetOptions()).GetAwaiter().GetResult();
|
||||||
{
|
|
||||||
_lastExecutionResult = JsonSerializer.Deserialize<TaskResult>(jsonString, JsonDefaults.GetOptions());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
_logger.LogDebug("Scheduled Task history file {path} is empty. Skipping deserialization.", path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -57,8 +57,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||||||
|
|
||||||
var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
|
var path = AudioDbAlbumProvider.GetAlbumInfoPath(_config.ApplicationPaths, id);
|
||||||
|
|
||||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
await using FileStream jsonStream = File.OpenRead(path);
|
||||||
var obj = JsonSerializer.Deserialize<AudioDbAlbumProvider.RootObject>(jsonString, JsonDefaults.GetOptions());
|
var obj = await JsonSerializer.DeserializeAsync<AudioDbAlbumProvider.RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (obj != null && obj.album != null && obj.album.Count > 0)
|
if (obj != null && obj.album != null && obj.album.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -64,8 +64,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||||||
|
|
||||||
var path = GetAlbumInfoPath(_config.ApplicationPaths, id);
|
var path = GetAlbumInfoPath(_config.ApplicationPaths, id);
|
||||||
|
|
||||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
await using FileStream jsonStream = File.OpenRead(path);
|
||||||
var obj = JsonSerializer.Deserialize<RootObject>(jsonString, JsonDefaults.GetOptions());
|
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (obj != null && obj.album != null && obj.album.Count > 0)
|
if (obj != null && obj.album != null && obj.album.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -59,8 +59,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||||||
|
|
||||||
var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
|
var path = AudioDbArtistProvider.GetArtistInfoPath(_config.ApplicationPaths, id);
|
||||||
|
|
||||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
await using FileStream jsonStream = File.OpenRead(path);
|
||||||
var obj = JsonSerializer.Deserialize<AudioDbArtistProvider.RootObject>(jsonString, JsonDefaults.GetOptions());
|
var obj = await JsonSerializer.DeserializeAsync<AudioDbArtistProvider.RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -65,8 +65,8 @@ namespace MediaBrowser.Providers.Plugins.AudioDb
|
|||||||
|
|
||||||
var path = GetArtistInfoPath(_config.ApplicationPaths, id);
|
var path = GetArtistInfoPath(_config.ApplicationPaths, id);
|
||||||
|
|
||||||
var jsonString = await File.ReadAllTextAsync(path, cancellationToken).ConfigureAwait(false);
|
await using FileStream jsonStream = File.OpenRead(path);
|
||||||
var obj = JsonSerializer.Deserialize<RootObject>(jsonString, JsonDefaults.GetOptions());
|
var obj = await JsonSerializer.DeserializeAsync<RootObject>(jsonStream, JsonDefaults.GetOptions(), cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
if (obj != null && obj.artists != null && obj.artists.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -299,7 +299,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||||||
var jsonOptions = JsonDefaults.GetOptions();
|
var jsonOptions = JsonDefaults.GetOptions();
|
||||||
var rootObject = await GetDeserializedOmdbResponse<RootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, jsonOptions, cancellationToken).ConfigureAwait(false);
|
var rootObject = await GetDeserializedOmdbResponse<RootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
await using FileStream jsonFileStream = File.Create(path);
|
await using FileStream jsonFileStream = File.OpenWrite(path);
|
||||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, jsonOptions, cancellationToken).ConfigureAwait(false);
|
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@ -337,7 +337,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||||||
var jsonOptions = JsonDefaults.GetOptions();
|
var jsonOptions = JsonDefaults.GetOptions();
|
||||||
var rootObject = await GetDeserializedOmdbResponse<SeasonRootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, jsonOptions, cancellationToken).ConfigureAwait(false);
|
var rootObject = await GetDeserializedOmdbResponse<SeasonRootObject>(_httpClientFactory.CreateClient(NamedClient.Default), url, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||||
await using FileStream jsonFileStream = File.Create(path);
|
await using FileStream jsonFileStream = File.OpenWrite(path);
|
||||||
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, jsonOptions, cancellationToken).ConfigureAwait(false);
|
await JsonSerializer.SerializeAsync(jsonFileStream, rootObject, jsonOptions, cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
return path;
|
return path;
|
||||||
@ -349,7 +349,7 @@ namespace MediaBrowser.Providers.Plugins.Omdb
|
|||||||
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
var content = await response.Content.ReadAsStringAsync(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// OMDb is sending "N/A" for no empty number fields
|
// OMDb is sending "N/A" for no empty number fields
|
||||||
content = content.Replace("\"N/A\"", "\"0\"", StringComparison.InvariantCulture);
|
content = content.Replace("\"N/A\"", "\"\"", StringComparison.InvariantCulture);
|
||||||
return JsonSerializer.Deserialize<T>(content, jsonOptions);
|
return JsonSerializer.Deserialize<T>(content, jsonOptions);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user