added ffmpeg downloading for mono

This commit is contained in:
Luke Pulverenti 2013-10-12 23:39:22 -04:00
parent f8f17efd54
commit e98665a091
10 changed files with 148 additions and 62 deletions

View File

@ -1,5 +1,6 @@
using MediaBrowser.Model.IO; using MediaBrowser.Model.IO;
using SharpCompress.Archive.SevenZip; using SharpCompress.Archive.SevenZip;
using SharpCompress.Archive.Tar;
using SharpCompress.Common; using SharpCompress.Common;
using SharpCompress.Reader; using SharpCompress.Reader;
using System.IO; using System.IO;
@ -83,5 +84,44 @@ namespace MediaBrowser.Common.Implementations.Archiving
} }
} }
} }
/// <summary>
/// Extracts all from tar.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
public void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles)
{
using (var fileStream = File.OpenRead(sourceFile))
{
ExtractAllFromTar(fileStream, targetPath, overwriteExistingFiles);
}
}
/// <summary>
/// Extracts all from tar.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
public void ExtractAllFromTar(Stream source, string targetPath, bool overwriteExistingFiles)
{
using (var archive = TarArchive.Open(source))
{
using (var reader = archive.ExtractAllEntries())
{
var options = ExtractOptions.ExtractFullPath;
if (overwriteExistingFiles)
{
options = options | ExtractOptions.Overwrite;
}
reader.WriteAllToDirectory(targetPath, options);
}
}
}
} }
} }

View File

@ -38,5 +38,21 @@ namespace MediaBrowser.Model.IO
/// <param name="targetPath">The target path.</param> /// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param> /// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles); void ExtractAllFrom7z(Stream source, string targetPath, bool overwriteExistingFiles);
/// <summary>
/// Extracts all from tar.
/// </summary>
/// <param name="sourceFile">The source file.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
void ExtractAllFromTar(string sourceFile, string targetPath, bool overwriteExistingFiles);
/// <summary>
/// Extracts all from tar.
/// </summary>
/// <param name="source">The source.</param>
/// <param name="targetPath">The target path.</param>
/// <param name="overwriteExistingFiles">if set to <c>true</c> [overwrite existing files].</param>
void ExtractAllFromTar(Stream source, string targetPath, bool overwriteExistingFiles);
} }
} }

View File

@ -1,14 +1,31 @@
<Properties> <Properties>
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" /> <MonoDevelop.Ide.Workspace ActiveConfiguration="Debug|x86" />
<MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\Program.cs"> <MonoDevelop.Ide.Workbench ActiveDocument="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloadInfo.cs">
<Files> <Files>
<File FileName="MediaBrowser.Server.Implementations\HttpServer\HttpServer.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Implementations\HttpServer\HttpServer.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloader.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Networking\NetworkManager.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Mono\Networking\NetworkManager.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.ServerApplication\ApplicationHost.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="1" Column="1" /> <File FileName="MediaBrowser.Server.Mono\Native\NativeApp.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\Program.cs" Line="193" Column="25" /> <File FileName="MediaBrowser.Server.Mono\Program.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.ServerApplication\FFMpeg\FFMpegDownloader.cs" Line="1" Column="1" />
<File FileName="MediaBrowser.Server.Mono\FFMpeg\FFMpegDownloadInfo.cs" Line="21" Column="1" />
</Files> </Files>
<Pads>
<Pad Id="ProjectPad">
<State expanded="True">
<Node name="MediaBrowser.Model" expanded="True" selected="True" />
<Node name="MediaBrowser.Server.Mono" expanded="True">
<Node name="FFMpeg" expanded="True" />
</Node>
</State>
</Pad>
<Pad Id="ClassPad">
<State expanded="True" selected="True" />
</Pad>
<Pad Id="MonoDevelop.Debugger.WatchPad">
<State />
</Pad>
</Pads>
</MonoDevelop.Ide.Workbench> </MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints> <MonoDevelop.Ide.DebuggingService.Breakpoints>
<BreakpointStore> <BreakpointStore>

View File

@ -88,7 +88,7 @@ namespace MediaBrowser.Server.Implementations.EntryPoints
} }
} }
private async Task SendNotifications(List<KeyValuePair<Guid, List<string>>> changes, CancellationToken cancellationToken) private async Task SendNotifications(IEnumerable<KeyValuePair<Guid, List<string>>> changes, CancellationToken cancellationToken)
{ {
foreach (var pair in changes) foreach (var pair in changes)
{ {

View File

@ -0,0 +1,20 @@

namespace MediaBrowser.ServerApplication.FFMpeg
{
public static class FFMpegDownloadInfo
{
public static string Version = "ffmpeg20130904";
public static string[] FfMpegUrls = new[]
{
"http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.2013-09-04.tar.gz",
"https://www.dropbox.com/s/y7f4nk96rxmbb30/ffmpeg.static.32bit.2013-09-04.tar.gz?dl=1"
};
public static string FFMpegFilename = "ffmpeg";
public static string FFProbeFilename = "ffprobe";
public static string ArchiveType = "gz";
}
}

View File

@ -1,36 +0,0 @@
using MediaBrowser.Common.Configuration;
using MediaBrowser.Common.IO;
using MediaBrowser.Common.Net;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.Logging;
using MediaBrowser.Model.Net;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.ServerApplication.FFMpeg
{
public class FFMpegDownloader
{
private readonly IHttpClient _httpClient;
private readonly IApplicationPaths _appPaths;
private readonly ILogger _logger;
private readonly IZipClient _zipClient;
public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient)
{
_logger = logger;
_appPaths = appPaths;
_httpClient = httpClient;
_zipClient = zipClient;
}
public Task<FFMpegInfo> GetFFMpegInfo()
{
return Task.FromResult (new FFMpegInfo());
}
}
}

View File

@ -74,7 +74,6 @@
</Compile> </Compile>
<Compile Include="Native\Autorun.cs" /> <Compile Include="Native\Autorun.cs" />
<Compile Include="Native\ServerAuthorization.cs" /> <Compile Include="Native\ServerAuthorization.cs" />
<Compile Include="FFMpeg\FFMpegDownloader.cs" />
<Compile Include="..\MediaBrowser.ServerApplication\FFMpeg\FFMpegInfo.cs"> <Compile Include="..\MediaBrowser.ServerApplication\FFMpeg\FFMpegInfo.cs">
<Link>FFMpeg\FFMpegInfo.cs</Link> <Link>FFMpeg\FFMpegInfo.cs</Link>
</Compile> </Compile>
@ -85,6 +84,10 @@
<Compile Include="Native\NativeApp.cs" /> <Compile Include="Native\NativeApp.cs" />
<Compile Include="Native\HttpClientFactory.cs" /> <Compile Include="Native\HttpClientFactory.cs" />
<Compile Include="Networking\NetworkManager.cs" /> <Compile Include="Networking\NetworkManager.cs" />
<Compile Include="..\MediaBrowser.ServerApplication\FFMpeg\FFMpegDownloader.cs">
<Link>FFMpeg\FFMpegDownloader.cs</Link>
</Compile>
<Compile Include="FFMpeg\FFMpegDownloadInfo.cs" />
</ItemGroup> </ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup> <ItemGroup>

View File

@ -0,0 +1,21 @@

namespace MediaBrowser.ServerApplication.FFMpeg
{
public static class FFMpegDownloadInfo
{
public static string Version = "ffmpeg20130904.1";
public static string[] FfMpegUrls = new[]
{
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20130904-git-f974289-win32-static.7z",
"http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20130904-git-f974289-win32-static.7z",
"https://www.dropbox.com/s/a81cb2ob23fwcfs/ffmpeg-20130904-git-f974289-win32-static.7z?dl=1"
};
public static string FFMpegFilename = "ffmpeg.exe";
public static string FFProbeFilename = "ffprobe.exe";
public static string ArchiveType = "7z";
}
}

View File

@ -21,21 +21,11 @@ namespace MediaBrowser.ServerApplication.FFMpeg
private readonly ILogger _logger; private readonly ILogger _logger;
private readonly IZipClient _zipClient; private readonly IZipClient _zipClient;
private const string Version = "ffmpeg20130904.1";
private readonly string[] _fontUrls = new[] private readonly string[] _fontUrls = new[]
{ {
"https://www.dropbox.com/s/pj847twf7riq0j7/ARIALUNI.7z?dl=1" "https://www.dropbox.com/s/pj847twf7riq0j7/ARIALUNI.7z?dl=1"
}; };
private readonly string[] _ffMpegUrls = new[]
{
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20130904-git-f974289-win32-static.7z",
"http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20130904-git-f974289-win32-static.7z",
"https://www.dropbox.com/s/a81cb2ob23fwcfs/ffmpeg-20130904-git-f974289-win32-static.7z?dl=1"
};
public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient) public FFMpegDownloader(ILogger logger, IApplicationPaths appPaths, IHttpClient httpClient, IZipClient zipClient)
{ {
_logger = logger; _logger = logger;
@ -46,13 +36,13 @@ namespace MediaBrowser.ServerApplication.FFMpeg
public async Task<FFMpegInfo> GetFFMpegInfo() public async Task<FFMpegInfo> GetFFMpegInfo()
{ {
var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), Version); var versionedDirectoryPath = Path.Combine(GetMediaToolsPath(true), FFMpegDownloadInfo.Version);
var info = new FFMpegInfo var info = new FFMpegInfo
{ {
ProbePath = Path.Combine(versionedDirectoryPath, "ffprobe.exe"), ProbePath = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFProbeFilename),
Path = Path.Combine(versionedDirectoryPath, "ffmpeg.exe"), Path = Path.Combine(versionedDirectoryPath, FFMpegDownloadInfo.FFMpegFilename),
Version = Version Version = FFMpegDownloadInfo.Version
}; };
Directory.CreateDirectory(versionedDirectoryPath); Directory.CreateDirectory(versionedDirectoryPath);
@ -73,7 +63,7 @@ namespace MediaBrowser.ServerApplication.FFMpeg
private async Task DownloadFFMpeg(FFMpegInfo info) private async Task DownloadFFMpeg(FFMpegInfo info)
{ {
foreach (var url in _ffMpegUrls) foreach (var url in FFMpegDownloadInfo.FfMpegUrls)
{ {
try try
{ {
@ -115,11 +105,18 @@ namespace MediaBrowser.ServerApplication.FFMpeg
try try
{ {
Extract7zArchive(tempFile, tempFolder); ExtractArchive(tempFile, tempFolder);
var files = Directory.EnumerateFiles(tempFolder, "*.exe", SearchOption.AllDirectories).ToList(); var files = Directory.EnumerateFiles(tempFolder, "*", SearchOption.AllDirectories).ToList();
foreach (var file in files.Where(i => i.IndexOf("ffprobe.exe", StringComparison.OrdinalIgnoreCase) != -1 || i.IndexOf("ffmpeg.exe", StringComparison.OrdinalIgnoreCase) != -1)) foreach (var file in files.Where(i =>
{
var filename = Path.GetFileName(i);
return
string.Equals(filename, FFMpegDownloadInfo.FFProbeFilename, StringComparison.OrdinalIgnoreCase) ||
string.Equals(filename, FFMpegDownloadInfo.FFMpegFilename, StringComparison.OrdinalIgnoreCase);
}))
{ {
File.Copy(file, Path.Combine(targetFolder, Path.GetFileName(file)), true); File.Copy(file, Path.Combine(targetFolder, Path.GetFileName(file)), true);
} }
@ -130,10 +127,17 @@ namespace MediaBrowser.ServerApplication.FFMpeg
} }
} }
private void Extract7zArchive(string archivePath, string targetPath) private void ExtractArchive(string archivePath, string targetPath)
{
if (string.Equals(FFMpegDownloadInfo.ArchiveType, "7z", StringComparison.OrdinalIgnoreCase))
{ {
_zipClient.ExtractAllFrom7z(archivePath, targetPath, true); _zipClient.ExtractAllFrom7z(archivePath, targetPath, true);
} }
else if (string.Equals(FFMpegDownloadInfo.ArchiveType, "gz", StringComparison.OrdinalIgnoreCase))
{
_zipClient.ExtractAllFromTar(archivePath, targetPath, true);
}
}
private void DeleteFile(string path) private void DeleteFile(string path)
{ {
@ -235,7 +239,7 @@ namespace MediaBrowser.ServerApplication.FFMpeg
return; return;
} }
Extract7zArchive(tempFile, fontsDirectory); ExtractArchive(tempFile, fontsDirectory);
try try
{ {

View File

@ -186,6 +186,7 @@
<SubType>Component</SubType> <SubType>Component</SubType>
</Compile> </Compile>
<Compile Include="EntryPoints\StartupWizard.cs" /> <Compile Include="EntryPoints\StartupWizard.cs" />
<Compile Include="FFMpeg\FFMpegDownloadInfo.cs" />
<Compile Include="FFMpeg\FFMpegInfo.cs" /> <Compile Include="FFMpeg\FFMpegInfo.cs" />
<Compile Include="Native\Assemblies.cs" /> <Compile Include="Native\Assemblies.cs" />
<Compile Include="Native\HttpClientFactory.cs" /> <Compile Include="Native\HttpClientFactory.cs" />