Added initial implementation of the metadata provider network, along with the first few providers

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-08-19 11:58:35 -04:00
parent 803ce0968e
commit d794eecec4
18 changed files with 492 additions and 284 deletions

View File

@@ -1,13 +1,41 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Threading.Tasks;
using MediaBrowser.Common.Logging;
using MediaBrowser.Common.Serialization;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Controller.FFMpeg
{
/// <summary>
/// Runs FFProbe against a media file and returns metadata.
/// </summary>
public static class FFProbe
{
public static FFProbeResult Run(string path)
public async static Task<FFProbeResult> Run(Audio item, string outputCachePath)
{
// Use try catch to avoid having to use File.Exists
try
{
using (FileStream stream = File.OpenRead(outputCachePath))
{
return JsonSerializer.DeserializeFromStream<FFProbeResult>(stream);
}
}
catch (FileNotFoundException)
{
}
await Run(item.Path, outputCachePath);
using (FileStream stream = File.OpenRead(outputCachePath))
{
return JsonSerializer.DeserializeFromStream<FFProbeResult>(stream);
}
}
private async static Task Run(string input, string output)
{
ProcessStartInfo startInfo = new ProcessStartInfo();
@@ -21,13 +49,15 @@ namespace MediaBrowser.Controller.FFMpeg
startInfo.FileName = Kernel.Instance.ApplicationPaths.FFProbePath;
startInfo.WorkingDirectory = Kernel.Instance.ApplicationPaths.FFMpegDirectory;
startInfo.Arguments = string.Format("\"{0}\" -v quiet -print_format json -show_streams -show_format", path);
startInfo.Arguments = string.Format("\"{0}\" -v quiet -print_format json -show_streams -show_format", input);
Logger.LogInfo(startInfo.FileName + " " + startInfo.Arguments);
//Logger.LogInfo(startInfo.FileName + " " + startInfo.Arguments);
Process process = new Process();
process.StartInfo = startInfo;
FileStream stream = new FileStream(output, FileMode.Create);
try
{
process.Start();
@@ -36,18 +66,23 @@ namespace MediaBrowser.Controller.FFMpeg
// If we ever decide to disable the ffmpeg log then you must uncomment the below line.
process.BeginErrorReadLine();
FFProbeResult result = JsonSerializer.DeserializeFromStream<FFProbeResult>(process.StandardOutput.BaseStream);
await process.StandardOutput.BaseStream.CopyToAsync(stream);
process.WaitForExit();
Logger.LogInfo("FFMpeg exited with code " + process.ExitCode);
stream.Dispose();
return result;
if (process.ExitCode != 0)
{
Logger.LogInfo("FFProbe exited with code {0} for {1}", process.ExitCode, input);
}
}
catch (Exception ex)
{
Logger.LogException(ex);
stream.Dispose();
// Hate having to do this
try
{
@@ -56,8 +91,7 @@ namespace MediaBrowser.Controller.FFMpeg
catch
{
}
return null;
File.Delete(output);
}
finally
{

View File

@@ -13,6 +13,11 @@ namespace MediaBrowser.Controller.FFMpeg
public MediaFormat format { get; set; }
}
/// <summary>
/// Represents a stream within the output
/// A number of properties are commented out to improve deserialization performance
/// Enable them as needed.
/// </summary>
public class MediaStream
{
public int index { get; set; }
@@ -20,28 +25,28 @@ namespace MediaBrowser.Controller.FFMpeg
public string codec_name { get; set; }
public string codec_long_name { get; set; }
public string codec_type { get; set; }
public string codec_time_base { get; set; }
public string codec_tag { get; set; }
public string codec_tag_string { get; set; }
public string sample_fmt { get; set; }
//public string codec_time_base { get; set; }
//public string codec_tag { get; set; }
//public string codec_tag_string { get; set; }
//public string sample_fmt { get; set; }
public string sample_rate { get; set; }
public int channels { get; set; }
public int bits_per_sample { get; set; }
public string r_frame_rate { get; set; }
public string avg_frame_rate { get; set; }
public string time_base { get; set; }
public string start_time { get; set; }
//public int bits_per_sample { get; set; }
//public string r_frame_rate { get; set; }
//public string avg_frame_rate { get; set; }
//public string time_base { get; set; }
//public string start_time { get; set; }
public string duration { get; set; }
public string bit_rate { get; set; }
public int width { get; set; }
public int height { get; set; }
public int has_b_frames { get; set; }
public string sample_aspect_ratio { get; set; }
public string display_aspect_ratio { get; set; }
public string pix_fmt { get; set; }
public int level { get; set; }
public MediaTags tags { get; set; }
//public int has_b_frames { get; set; }
//public string sample_aspect_ratio { get; set; }
//public string display_aspect_ratio { get; set; }
//public string pix_fmt { get; set; }
//public int level { get; set; }
public Dictionary<string,string> tags { get; set; }
}
public class MediaFormat
@@ -54,23 +59,6 @@ namespace MediaBrowser.Controller.FFMpeg
public string duration { get; set; }
public string size { get; set; }
public string bit_rate { get; set; }
public MediaTags tags { get; set; }
}
public class MediaTags
{
public string title { get; set; }
public string comment { get; set; }
public string artist { get; set; }
public string album { get; set; }
public string album_artist { get; set; }
public string composer { get; set; }
public string copyright { get; set; }
public string publisher { get; set; }
public string track { get; set; }
public string disc { get; set; }
public string genre { get; set; }
public string date { get; set; }
public string language { get; set; }
public Dictionary<string, string> tags { get; set; }
}
}