Added some ffprobe error handling

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-08-25 11:30:37 -04:00
parent bbbe6164dc
commit 37dd0c8bdd
3 changed files with 59 additions and 42 deletions

View File

@@ -27,40 +27,40 @@ namespace MediaBrowser.Controller.Providers
protected override void Fetch(Video video, FFProbeResult data)
{
if (data == null)
if (data.format != null)
{
Logger.LogInfo("Null FFProbeResult for {0} {1}", video.Id, video.Name);
return;
}
if (!string.IsNullOrEmpty(data.format.duration))
{
video.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration)).Ticks;
}
if (!string.IsNullOrEmpty(data.format.bit_rate))
{
video.BitRate = int.Parse(data.format.bit_rate);
}
// For now, only read info about first video stream
// Files with multiple video streams are possible, but extremely rare
bool foundVideo = false;
foreach (MediaStream stream in data.streams)
{
if (stream.codec_type.Equals("video", StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrEmpty(data.format.duration))
{
if (!foundVideo)
{
FetchFromVideoStream(video, stream);
}
foundVideo = true;
video.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration)).Ticks;
}
else if (stream.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase))
if (!string.IsNullOrEmpty(data.format.bit_rate))
{
FetchFromAudioStream(video, stream);
video.BitRate = int.Parse(data.format.bit_rate);
}
}
if (data.streams != null)
{
// For now, only read info about first video stream
// Files with multiple video streams are possible, but extremely rare
bool foundVideo = false;
foreach (MediaStream stream in data.streams)
{
if (stream.codec_type.Equals("video", StringComparison.OrdinalIgnoreCase))
{
if (!foundVideo)
{
FetchFromVideoStream(video, stream);
}
foundVideo = true;
}
else if (stream.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase))
{
FetchFromAudioStream(video, stream);
}
}
}
}
@@ -111,6 +111,17 @@ namespace MediaBrowser.Controller.Providers
streams.Add(audio);
video.AudioStreams = streams;
}
private void FetchFromSubtitleStream(Video video, MediaStream stream)
{
SubtitleStream subtitle = new SubtitleStream();
subtitle.Language = GetDictionaryValue(stream.tags, "language");
List<SubtitleStream> streams = video.Subtitles ?? new List<SubtitleStream>();
streams.Add(subtitle);
video.Subtitles = streams;
}
/// <summary>
/// Determines if there's already enough info in the Video object to allow us to skip running ffprobe