From fbf8cc833c441de8890998600be044296acfc783 Mon Sep 17 00:00:00 2001 From: LukePulverenti Luke Pulverenti luke pulverenti Date: Tue, 21 Aug 2012 22:50:59 -0400 Subject: a few more async optimizations --- MediaBrowser.Controller/FFMpeg/FFProbe.cs | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'MediaBrowser.Controller/FFMpeg') diff --git a/MediaBrowser.Controller/FFMpeg/FFProbe.cs b/MediaBrowser.Controller/FFMpeg/FFProbe.cs index f5364821c..1a0685a7a 100644 --- a/MediaBrowser.Controller/FFMpeg/FFProbe.cs +++ b/MediaBrowser.Controller/FFMpeg/FFProbe.cs @@ -18,10 +18,7 @@ namespace MediaBrowser.Controller.FFMpeg // Use try catch to avoid having to use File.Exists try { - using (FileStream stream = File.OpenRead(outputCachePath)) - { - return JsonSerializer.DeserializeFromStream(stream); - } + return GetCachedResult(outputCachePath); } catch (FileNotFoundException) { @@ -29,7 +26,12 @@ namespace MediaBrowser.Controller.FFMpeg await Run(item.Path, outputCachePath).ConfigureAwait(false); - using (FileStream stream = File.OpenRead(outputCachePath)) + return GetCachedResult(item.Path); + } + + public static FFProbeResult GetCachedResult(string path) + { + using (FileStream stream = File.OpenRead(path)) { return JsonSerializer.DeserializeFromStream(stream); } @@ -40,10 +42,7 @@ namespace MediaBrowser.Controller.FFMpeg // Use try catch to avoid having to use File.Exists try { - using (FileStream stream = File.OpenRead(outputCachePath)) - { - return JsonSerializer.DeserializeFromStream(stream); - } + return GetCachedResult(outputCachePath); } catch (FileNotFoundException) { @@ -51,10 +50,7 @@ namespace MediaBrowser.Controller.FFMpeg await Run(item.Path, outputCachePath).ConfigureAwait(false); - using (FileStream stream = File.OpenRead(outputCachePath)) - { - return JsonSerializer.DeserializeFromStream(stream); - } + return GetCachedResult(item.Path); } private async static Task Run(string input, string output) -- cgit v1.2.3