jellyfin-server/MediaBrowser.ServerApplication/FFMpeg/FFMpegDownloadInfo.cs

252 lines
9.3 KiB
C#
Raw Normal View History

2014-10-06 23:58:46 +00:00
using Mono.Unix.Native;
using System;
2014-05-07 02:28:19 +00:00
using System.IO;
using System.Text.RegularExpressions;
2014-01-05 03:50:29 +00:00
2013-10-13 03:39:22 +00:00
namespace MediaBrowser.ServerApplication.FFMpeg
{
public static class FFMpegDownloadInfo
{
2014-01-05 03:50:29 +00:00
// Windows builds: http://ffmpeg.zeranoe.com/builds/
// Linux builds: http://ffmpeg.gusari.org/static/
2014-03-05 02:59:00 +00:00
// OS X builds: http://ffmpegmac.net/
2014-07-09 00:46:11 +00:00
// OS X x64: http://www.evermeet.cx/ffmpeg/
2014-01-05 03:50:29 +00:00
public static string Version = getFfmpegValue("Version");
2014-01-05 03:50:29 +00:00
public static string FFMpegFilename = getFfmpegValue("FFMpegFilename");
public static string FFProbeFilename = getFfmpegValue("FFProbeFilename");
2014-01-05 03:50:29 +00:00
public static string ArchiveType = getFfmpegValue("ArchiveType");
2014-01-05 03:50:29 +00:00
private static string getFfmpegValue(string arg)
2014-01-05 03:50:29 +00:00
{
OperatingSystem os = Environment.OSVersion;
PlatformID pid = os.Platform;
switch (pid)
{
case PlatformID.Win32NT:
switch (arg)
{
case "Version":
2014-10-06 23:58:46 +00:00
return "20141005";
2014-01-05 03:50:29 +00:00
case "FFMpegFilename":
return "ffmpeg.exe";
case "FFProbeFilename":
return "ffprobe.exe";
case "ArchiveType":
return "7z";
}
break;
2014-01-05 03:50:29 +00:00
case PlatformID.Unix:
if (PlatformDetection.IsMac)
2014-01-05 03:50:29 +00:00
{
if (PlatformDetection.IsX86_64)
2014-08-28 01:36:59 +00:00
{
switch (arg)
{
case "Version":
return "20140827";
case "FFMpegFilename":
return "ffmpeg";
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
2014-09-28 16:50:33 +00:00
return "7z";
2014-08-28 01:36:59 +00:00
}
}
if (PlatformDetection.IsX86)
{
switch (arg)
{
case "Version":
return "20131121";
case "FFMpegFilename":
return "ffmpeg";
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
return "gz";
}
}
2014-01-05 03:50:29 +00:00
}
else if (PlatformDetection.IsLinux)
{
if (PlatformDetection.IsX86)
{
switch (arg)
{
case "Version":
2014-10-06 23:58:46 +00:00
return "20140716";
case "FFMpegFilename":
return "ffmpeg";
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
return "gz";
}
}
else if (PlatformDetection.IsX86_64)
{
// Linux on x86 or x86_64
switch (arg)
{
case "Version":
2014-10-06 23:58:46 +00:00
return "20140716";
case "FFMpegFilename":
return "ffmpeg";
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
return "gz";
}
}
}
break;
}
switch (arg)
{
case "Version":
return "path";
case "FFMpegFilename":
return "ffmpeg";
case "FFProbeFilename":
return "ffprobe";
case "ArchiveType":
return "";
default:
return string.Empty;
2014-01-05 03:50:29 +00:00
}
}
2013-10-13 03:39:22 +00:00
public static string[] GetDownloadUrls()
2014-01-05 03:50:29 +00:00
{
var pid = Environment.OSVersion.Platform;
2014-05-07 02:28:19 +00:00
2014-01-05 03:50:29 +00:00
switch (pid)
{
case PlatformID.Win32NT:
if (PlatformDetection.IsX86_64)
{
return new[]
{
2014-10-06 23:58:46 +00:00
"http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-20141005-git-e079d43-win64-static.7z",
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20141005-git-e079d43-win64-static.7z"
};
}
2014-01-05 03:50:29 +00:00
return new[]
{
2014-10-06 23:58:46 +00:00
"http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-20141005-git-e079d43-win32-static.7z",
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/windows/ffmpeg-20141005-git-e079d43-win32-static.7z"
2014-01-05 03:50:29 +00:00
};
2014-05-07 02:28:19 +00:00
case PlatformID.Unix:
2014-07-09 00:46:11 +00:00
if (PlatformDetection.IsMac && PlatformDetection.IsX86)
{
return new[]
{
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffmpeg-osx-20131121.gz"
};
}
if (PlatformDetection.IsMac && PlatformDetection.IsX86_64)
2014-01-05 03:50:29 +00:00
{
return new[]
{
2014-08-28 01:36:59 +00:00
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/osx/ffmpeg-x64-2.3.3.7z"
};
}
if (PlatformDetection.IsLinux)
{
if (PlatformDetection.IsX86)
{
return new[]
{
2014-05-07 02:28:19 +00:00
"http://ffmpeg.gusari.org/static/32bit/ffmpeg.static.32bit.latest.tar.gz",
2014-10-06 23:58:46 +00:00
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.32bit.2014-07-16.tar.gz"
};
}
if (PlatformDetection.IsX86_64)
{
return new[]
{
2014-05-07 02:28:19 +00:00
"http://ffmpeg.gusari.org/static/64bit/ffmpeg.static.64bit.latest.tar.gz",
2014-10-06 23:58:46 +00:00
"https://github.com/MediaBrowser/MediaBrowser.Resources/raw/master/ffmpeg/linux/ffmpeg.static.64bit.2014-07-16.tar.gz"
};
}
}
2014-07-09 00:46:11 +00:00
// No Unix version available
2014-05-07 02:28:19 +00:00
return new string[] { };
default:
throw new ApplicationException("No ffmpeg download available for " + pid);
2014-01-05 03:50:29 +00:00
}
}
}
public static class PlatformDetection
{
public readonly static bool IsWindows;
public readonly static bool IsMac;
public readonly static bool IsLinux;
public readonly static bool IsX86;
public readonly static bool IsX86_64;
public readonly static bool IsArm;
2014-05-07 02:28:19 +00:00
static PlatformDetection()
{
IsWindows = Path.DirectorySeparatorChar == '\\';
2014-09-16 03:33:30 +00:00
// Don't call uname on windows
if (!IsWindows)
{
2014-05-07 02:28:19 +00:00
var uname = GetUnixName();
2014-09-16 03:33:30 +00:00
var sysName = uname.sysname ?? string.Empty;
IsMac = string.Equals(sysName, "Darwin", StringComparison.OrdinalIgnoreCase);
IsLinux = string.Equals(sysName, "Linux", StringComparison.OrdinalIgnoreCase);
2014-05-07 02:28:19 +00:00
var archX86 = new Regex("(i|I)[3-6]86");
IsX86 = archX86.IsMatch(uname.machine);
IsX86_64 = !IsX86 && uname.machine == "x86_64";
IsArm = !IsX86 && !IsX86_64 && uname.machine.StartsWith("arm");
}
else
{
2014-05-07 02:28:19 +00:00
if (Environment.Is64BitOperatingSystem)
IsX86_64 = true;
else
IsX86 = true;
}
}
2014-05-07 02:28:19 +00:00
private static Uname GetUnixName()
{
var uname = new Uname();
2014-10-06 23:58:46 +00:00
Utsname utsname;
var callResult = Syscall.uname(out utsname);
if (callResult == 0)
{
uname.sysname = utsname.sysname;
uname.machine = utsname.machine;
}
2014-05-07 02:28:19 +00:00
return uname;
}
}
public class Uname
{
public string sysname = string.Empty;
public string machine = string.Empty;
2013-10-13 03:39:22 +00:00
}
2014-07-30 03:31:35 +00:00
}