Added VideoInfo to DTOBaseItem

This commit is contained in:
LukePulverenti Luke Pulverenti luke pulverenti
2012-08-22 08:56:44 -04:00
parent fbf8cc833c
commit f2de85b5d9
10 changed files with 156 additions and 58 deletions

View File

@@ -33,7 +33,7 @@ namespace MediaBrowser.Controller.FFMpeg
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 avg_frame_rate { get; set; }
//public string time_base { get; set; }
//public string start_time { get; set; }
public string duration { get; set; }

View File

@@ -144,37 +144,30 @@ namespace MediaBrowser.Controller.Providers
private int? GetDictionaryDiscValue(Dictionary<string, string> tags)
{
string[] keys = tags.Keys.ToArray();
string disc = GetDictionaryValue(tags, "disc");
for (int i = 0; i < keys.Length; i++)
if (!string.IsNullOrEmpty(disc))
{
string currentKey = keys[i];
disc = disc.Split('/')[0];
if ("disc".Equals(currentKey, StringComparison.OrdinalIgnoreCase))
int num;
if (int.TryParse(disc, out num))
{
string disc = tags[currentKey];
if (!string.IsNullOrEmpty(disc))
{
disc = disc.Split('/')[0];
int num;
if (int.TryParse(disc, out num))
{
return num;
}
}
break;
return num;
}
}
return null;
}
private string GetDictionaryValue(Dictionary<string, string> tags, string key)
internal static string GetDictionaryValue(Dictionary<string, string> tags, string key)
{
if (tags == null)
{
return null;
}
string[] keys = tags.Keys.ToArray();
for (int i = 0; i < keys.Length; i++)

View File

@@ -6,6 +6,7 @@ using System.Threading.Tasks;
using MediaBrowser.Controller.Events;
using MediaBrowser.Controller.FFMpeg;
using MediaBrowser.Model.Entities;
using System.Collections.Generic;
namespace MediaBrowser.Controller.Providers
{
@@ -61,11 +62,25 @@ namespace MediaBrowser.Controller.Providers
video.BitRate = int.Parse(data.format.bit_rate);
}
MediaStream videoStream = data.streams.FirstOrDefault(s => s.codec_type.Equals("video", StringComparison.OrdinalIgnoreCase));
// For now, only read info about first video stream
// Files with multiple video streams are possible, but extremely rare
bool foundVideo = false;
if (videoStream != null)
foreach (MediaStream stream in data.streams)
{
FetchFromVideoStream(video, videoStream);
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);
}
}
}
@@ -75,6 +90,45 @@ namespace MediaBrowser.Controller.Providers
video.Width = stream.width;
video.Height = stream.height;
video.AspectRatio = stream.display_aspect_ratio;
if (!string.IsNullOrEmpty(stream.avg_frame_rate))
{
string[] parts = stream.avg_frame_rate.Split('/');
if (parts.Length == 2)
{
video.FrameRate = float.Parse(parts[0]) / float.Parse(parts[1]);
}
else
{
video.FrameRate = float.Parse(parts[0]);
}
}
}
private void FetchFromAudioStream(Video video, MediaStream stream)
{
AudioStream audio = new AudioStream();
audio.Codec = stream.codec_name;
if (!string.IsNullOrEmpty(stream.bit_rate))
{
audio.BitRate = int.Parse(stream.bit_rate);
}
audio.Channels = stream.channels;
if (!string.IsNullOrEmpty(stream.sample_rate))
{
audio.SampleRate = int.Parse(stream.sample_rate);
}
audio.Language = AudioInfoProvider.GetDictionaryValue(stream.tags, "language");
List<AudioStream> streams = (video.AudioStreams ?? new AudioStream[] { }).ToList();
streams.Add(audio);
video.AudioStreams = streams;
}
/// <summary>

View File

@@ -321,8 +321,15 @@ namespace MediaBrowser.Controller.Xml
break;
case "Subtitle":
FetchMediaInfoSubtitles(reader.ReadSubtree(), item);
break;
{
SubtitleStream stream = FetchMediaInfoSubtitles(reader.ReadSubtree());
List<SubtitleStream> streams = (item.Subtitles ?? new SubtitleStream[] { }).ToList();
streams.Add(stream);
item.Subtitles = streams;
break;
}
default:
reader.Skip();
@@ -348,10 +355,6 @@ namespace MediaBrowser.Controller.Xml
stream.IsDefault = reader.ReadElementContentAsString() == "True";
break;
case "Forced":
stream.IsForced = reader.ReadElementContentAsString() == "True";
break;
case "BitRate":
stream.BitRate = reader.ReadIntSafe();
break;
@@ -451,9 +454,9 @@ namespace MediaBrowser.Controller.Xml
}
}
private void FetchMediaInfoSubtitles(XmlReader reader, Video item)
private SubtitleStream FetchMediaInfoSubtitles(XmlReader reader)
{
List<string> list = (item.Subtitles ?? new string[] { }).ToList();
SubtitleStream stream = new SubtitleStream();
reader.MoveToContent();
@@ -464,15 +467,16 @@ namespace MediaBrowser.Controller.Xml
switch (reader.Name)
{
case "Language":
{
string genre = reader.ReadElementContentAsString();
stream.Language = reader.ReadElementContentAsString();
break;
if (!string.IsNullOrWhiteSpace(genre))
{
list.Add(genre);
}
break;
}
case "Default":
stream.IsDefault = reader.ReadElementContentAsString() == "True";
break;
case "Forced":
stream.IsForced = reader.ReadElementContentAsString() == "True";
break;
default:
reader.Skip();
@@ -481,7 +485,7 @@ namespace MediaBrowser.Controller.Xml
}
}
item.Subtitles = list;
return stream;
}
private void FetchFromTaglinesNode(XmlReader reader, T item)