The Free Software Media System - Server Backend & API
perform downloads in parallel
Luke Pulverenti1dbce6bff23b
diff --git a/MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.cs b/MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.csindex ef33518cdb..75c47c10dd 100644--- a/MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.cs+++ b/MediaBrowser.ServerApplication/Implementations/FFMpegDownloader.cs@@ -7,6 +7,7 @@ using SharpCompress.Archive.SevenZip;using SharpCompress.Common;using SharpCompress.Reader;using System;+using System.Collections.Generic;using System.IO;using System.Linq;using System.Text;@@ -54,19 +55,16 @@ namespace MediaBrowser.ServerApplication.ImplementationsDirectory.CreateDirectory(versionedDirectoryPath);}+ var tasks = new List<Task>();+if (!File.Exists(info.ProbePath) || !File.Exists(info.Path)){- await DownloadFFMpeg(info).ConfigureAwait(false);+ tasks.Add(DownloadFFMpeg(info));}- try- {- await DownloadFonts(versionedDirectoryPath).ConfigureAwait(false);- }- catch (Exception ex)- {- _logger.ErrorException("Error getting ffmpeg font files", ex);- }+ tasks.Add(DownloadFonts(versionedDirectoryPath));++ await Task.WhenAll(tasks).ConfigureAwait(false);return info;}@@ -87,6 +85,8 @@ namespace MediaBrowser.ServerApplication.Implementations}}++ throw new ApplicationException("Unable to download required components. Please try again later.");}private Task<string> DownloadFFMpeg(FFMpegInfo info, string url)@@ -160,23 +160,36 @@ namespace MediaBrowser.ServerApplication.Implementations/// <param name="targetPath">The target path.</param>private async Task DownloadFonts(string targetPath){- var fontsDirectory = Path.Combine(targetPath, "fonts");-- if (!Directory.Exists(fontsDirectory))+ try{- Directory.CreateDirectory(fontsDirectory);- }+ var fontsDirectory = Path.Combine(targetPath, "fonts");- const string fontFilename = "ARIALUNI.TTF";+ if (!Directory.Exists(fontsDirectory))+ {+ Directory.CreateDirectory(fontsDirectory);+ }++ const string fontFilename = "ARIALUNI.TTF";- var fontFile = Path.Combine(fontsDirectory, fontFilename);+ var fontFile = Path.Combine(fontsDirectory, fontFilename);++ if (!File.Exists(fontFile))+ {+ await DownloadFontFile(fontsDirectory, fontFilename).ConfigureAwait(false);+ }- if (!File.Exists(fontFile))+ await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false);+ }+ catch (HttpException ex){- await DownloadFontFile(fontsDirectory, fontFilename).ConfigureAwait(false);+ // Don't let the server crash because of this+ _logger.ErrorException("Error downloading ffmpeg font files", ex);+ }+ catch (Exception ex)+ {+ // Don't let the server crash because of this+ _logger.ErrorException("Error writing ffmpeg font files", ex);}-- await WriteFontConfigFile(fontsDirectory).ConfigureAwait(false);}/// <summary>