aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-04 15:34:50 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-04 15:34:50 -0400
commitcb6170712d78f02c511e0d25a1c17f3982805e2c (patch)
treeed0784aa86725c8ab1031023b25107bfe65fc466
parentc45e152205d46669e7fa7e3cabf5956fc53e0448 (diff)
#74 - Subtitle font
-rw-r--r--MediaBrowser.Controller/IServerApplicationPaths.cs7
-rw-r--r--MediaBrowser.Controller/MediaBrowser.Controller.csproj2
-rw-r--r--MediaBrowser.Controller/MediaInfo/FFMpegManager.cs96
-rw-r--r--MediaBrowser.Controller/MediaInfo/fonts/fonts.conf9
-rw-r--r--MediaBrowser.Server.Implementations/ServerApplicationPaths.cs26
5 files changed, 105 insertions, 35 deletions
diff --git a/MediaBrowser.Controller/IServerApplicationPaths.cs b/MediaBrowser.Controller/IServerApplicationPaths.cs
index f88d7a5f6..aa6ff4d97 100644
--- a/MediaBrowser.Controller/IServerApplicationPaths.cs
+++ b/MediaBrowser.Controller/IServerApplicationPaths.cs
@@ -76,13 +76,6 @@ namespace MediaBrowser.Controller
/// <value>The FF MPEG stream cache path.</value>
string EncodedMediaCachePath { get; }
- /// <summary>
- /// Gets the folder path to tools
- /// </summary>
- /// <value>The media tools path.</value>
- string MediaToolsPath { get; }
-
- /// <summary>
/// Gets the downloaded images data path.
/// </summary>
/// <value>The downloaded images data path.</value>
diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
index 02f15b94a..1c03e11dd 100644
--- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj
+++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj
@@ -202,6 +202,8 @@
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MediaInfo\ffmpeg20130327.zip" />
+ <EmbeddedResource Include="MediaInfo\fonts\ARIALUNI.TTF" />
+ <EmbeddedResource Include="MediaInfo\fonts\fonts.conf" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
diff --git a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs
index d6fc8eb94..3a4f3cae7 100644
--- a/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs
+++ b/MediaBrowser.Controller/MediaInfo/FFMpegManager.cs
@@ -1,4 +1,5 @@
-using MediaBrowser.Common.IO;
+using System.Text;
+using MediaBrowser.Common.IO;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Model.Entities;
@@ -286,6 +287,32 @@ namespace MediaBrowser.Controller.MediaInfo
}
/// <summary>
+ /// The _media tools path
+ /// </summary>
+ private string _mediaToolsPath;
+ /// <summary>
+ /// Gets the folder path to tools
+ /// </summary>
+ /// <value>The media tools path.</value>
+ private string MediaToolsPath
+ {
+ get
+ {
+ if (_mediaToolsPath == null)
+ {
+ _mediaToolsPath = Path.Combine(_appPaths.ProgramDataPath, "ffmpeg");
+
+ if (!Directory.Exists(_mediaToolsPath))
+ {
+ Directory.CreateDirectory(_mediaToolsPath);
+ }
+ }
+
+ return _mediaToolsPath;
+ }
+ }
+
+ /// <summary>
/// Gets the versioned directory path.
/// </summary>
/// <returns>System.String.</returns>
@@ -300,7 +327,7 @@ namespace MediaBrowser.Controller.MediaInfo
var filename = resource.Substring(resource.IndexOf(prefix, StringComparison.OrdinalIgnoreCase) + prefix.Length);
- var versionedDirectoryPath = Path.Combine(_appPaths.MediaToolsPath, Path.GetFileNameWithoutExtension(filename));
+ var versionedDirectoryPath = Path.Combine(MediaToolsPath, Path.GetFileNameWithoutExtension(filename));
if (!Directory.Exists(versionedDirectoryPath))
{
@@ -324,6 +351,71 @@ namespace MediaBrowser.Controller.MediaInfo
{
_zipClient.ExtractAll(resourceStream, targetPath, false);
}
+
+ ExtractFonts(assembly, targetPath);
+ }
+
+ /// <summary>
+ /// Extracts the fonts.
+ /// </summary>
+ /// <param name="assembly">The assembly.</param>
+ /// <param name="targetPath">The target path.</param>
+ private async void ExtractFonts(Assembly assembly, string targetPath)
+ {
+ var fontsDirectory = Path.Combine(targetPath, "fonts");
+
+ if (!Directory.Exists(fontsDirectory))
+ {
+ Directory.CreateDirectory(fontsDirectory);
+ }
+
+ const string fontFilename = "ARIALUNI.TTF";
+
+ var fontFile = Path.Combine(fontsDirectory, fontFilename);
+
+ if (!File.Exists(fontFile))
+ {
+ using (var stream = assembly.GetManifestResourceStream("MediaBrowser.Controller.MediaInfo.fonts." + fontFilename))
+ {
+ using (var fileStream = new FileStream(fontFile, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
+ {
+ await stream.CopyToAsync(fileStream).ConfigureAwait(false);
+ }
+ }
+ }
+
+ await ExtractFontConfigFile(assembly, fontsDirectory).ConfigureAwait(false);
+ }
+
+ /// <summary>
+ /// Extracts the font config file.
+ /// </summary>
+ /// <param name="assembly">The assembly.</param>
+ /// <param name="fontsDirectory">The fonts directory.</param>
+ private async Task ExtractFontConfigFile(Assembly assembly, string fontsDirectory)
+ {
+ const string fontConfigFilename = "fonts.conf";
+ var fontConfigFile = Path.Combine(fontsDirectory, fontConfigFilename);
+
+ if (!File.Exists(fontConfigFile))
+ {
+ using (var stream = assembly.GetManifestResourceStream("MediaBrowser.Controller.MediaInfo.fonts." + fontConfigFilename))
+ {
+ using (var streamReader = new StreamReader(stream))
+ {
+ var contents = await streamReader.ReadToEndAsync().ConfigureAwait(false);
+
+ contents = contents.Replace("<dir></dir>", "<dir>" + fontsDirectory + "</dir>");
+
+ var bytes = Encoding.UTF8.GetBytes(contents);
+
+ using (var fileStream = new FileStream(fontConfigFile, FileMode.Create, FileAccess.Write, FileShare.Read, StreamDefaults.DefaultFileStreamBufferSize, FileOptions.Asynchronous))
+ {
+ await fileStream.WriteAsync(bytes, 0, bytes.Length);
+ }
+ }
+ }
+ }
}
/// <summary>
diff --git a/MediaBrowser.Controller/MediaInfo/fonts/fonts.conf b/MediaBrowser.Controller/MediaInfo/fonts/fonts.conf
new file mode 100644
index 000000000..648bdb7b2
--- /dev/null
+++ b/MediaBrowser.Controller/MediaInfo/fonts/fonts.conf
@@ -0,0 +1,9 @@
+<?xml version="1.0"?>
+<fontconfig>
+
+<dir></dir>
+ <alias>
+ <family>Arial</family>
+ <prefer>Arial Unicode MS</prefer>
+ </alias>
+</fontconfig> \ No newline at end of file
diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs
index 429c893ca..0863e592b 100644
--- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs
+++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs
@@ -321,32 +321,6 @@ namespace MediaBrowser.Server.Implementations
}
/// <summary>
- /// The _media tools path
- /// </summary>
- private string _mediaToolsPath;
- /// <summary>
- /// Gets the folder path to tools
- /// </summary>
- /// <value>The media tools path.</value>
- public string MediaToolsPath
- {
- get
- {
- if (_mediaToolsPath == null)
- {
- _mediaToolsPath = Path.Combine(ProgramDataPath, "MediaTools");
-
- if (!Directory.Exists(_mediaToolsPath))
- {
- Directory.CreateDirectory(_mediaToolsPath);
- }
- }
-
- return _mediaToolsPath;
- }
- }
-
- /// <summary>
/// The _images data path
/// </summary>
private string _downloadedImagesDataPath;