public Model.MediaInfo.MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new Model.MediaInfo.MediaInfo { Path = path, Protocol = protocol }; FFProbeHelpers.NormalizeFFProbeResult(data); SetSize(data, info); var internalStreams = data.streams ?? new MediaStreamInfo[] { }; info.MediaStreams = internalStreams.Select(s => GetMediaStream(s, data.format)) .Where(i => i != null) .ToList(); if (data.format != null) { info.Container = data.format.format_name; if (!string.IsNullOrEmpty(data.format.bit_rate)) { info.Bitrate = int.Parse(data.format.bit_rate, _usCulture); } } if (isAudio) { SetAudioRuntimeTicks(data, info); if (data.format != null && data.format.tags != null) { SetAudioInfoFromTags(info, data.format.tags); } } else { if (data.format != null && !string.IsNullOrEmpty(data.format.duration)) { info.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration, _usCulture)).Ticks; } FetchWtvInfo(info, data); if (data.Chapters != null) { info.Chapters = data.Chapters.Select(GetChapterInfo).ToList(); } ExtractTimestamp(info); var videoStream = info.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); if (videoStream != null && videoType == VideoType.VideoFile) { UpdateFromMediaInfo(info, videoStream); } } return(info); }
public MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new MediaInfo { Path = path, Protocol = protocol }; FFProbeHelpers.NormalizeFFProbeResult(data); SetSize(data, info); var internalStreams = data.streams ?? new MediaStreamInfo[] { }; info.MediaStreams = internalStreams.Select(s => GetMediaStream(isAudio, s, data.format)) .Where(i => i != null) .ToList(); if (data.format != null) { info.Container = data.format.format_name; if (!string.IsNullOrEmpty(data.format.bit_rate)) { int value; if (int.TryParse(data.format.bit_rate, NumberStyles.Any, _usCulture, out value)) { info.Bitrate = value; } } } var tags = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); var tagStreamType = isAudio ? "audio" : "video"; if (data.streams != null) { var tagStream = data.streams.FirstOrDefault(i => string.Equals(i.codec_type, tagStreamType, StringComparison.OrdinalIgnoreCase)); if (tagStream != null && tagStream.tags != null) { foreach (var pair in tagStream.tags) { tags[pair.Key] = pair.Value; } } } if (data.format != null && data.format.tags != null) { foreach (var pair in data.format.tags) { tags[pair.Key] = pair.Value; } } FetchGenres(info, tags); var shortOverview = FFProbeHelpers.GetDictionaryValue(tags, "description"); var overview = FFProbeHelpers.GetDictionaryValue(tags, "synopsis"); if (string.IsNullOrWhiteSpace(overview)) { overview = shortOverview; shortOverview = null; } if (string.IsNullOrWhiteSpace(overview)) { overview = FFProbeHelpers.GetDictionaryValue(tags, "desc"); } if (!string.IsNullOrWhiteSpace(overview)) { info.Overview = overview; } if (!string.IsNullOrWhiteSpace(shortOverview)) { info.ShortOverview = shortOverview; } var title = FFProbeHelpers.GetDictionaryValue(tags, "title"); if (!string.IsNullOrWhiteSpace(title)) { info.Name = title; } info.ProductionYear = FFProbeHelpers.GetDictionaryNumericValue(tags, "date"); // Several different forms of retaildate info.PremiereDate = FFProbeHelpers.GetDictionaryDateTime(tags, "retaildate") ?? FFProbeHelpers.GetDictionaryDateTime(tags, "retail date") ?? FFProbeHelpers.GetDictionaryDateTime(tags, "retail_date") ?? FFProbeHelpers.GetDictionaryDateTime(tags, "date"); if (isAudio) { SetAudioRuntimeTicks(data, info); // tags are normally located under data.format, but we've seen some cases with ogg where they're part of the info stream // so let's create a combined list of both SetAudioInfoFromTags(info, tags); } else { FetchStudios(info, tags, "copyright"); var iTunEXTC = FFProbeHelpers.GetDictionaryValue(tags, "iTunEXTC"); if (!string.IsNullOrWhiteSpace(iTunEXTC)) { var parts = iTunEXTC.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries); // Example // mpaa|G|100|For crude humor if (parts.Length > 1) { info.OfficialRating = parts[1]; if (parts.Length > 3) { info.OfficialRatingDescription = parts[3]; } } } var itunesXml = FFProbeHelpers.GetDictionaryValue(tags, "iTunMOVI"); if (!string.IsNullOrWhiteSpace(itunesXml)) { FetchFromItunesInfo(itunesXml, info); } if (data.format != null && !string.IsNullOrEmpty(data.format.duration)) { info.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration, _usCulture)).Ticks; } FetchWtvInfo(info, data); if (data.Chapters != null) { info.Chapters = data.Chapters.Select(GetChapterInfo).ToList(); } ExtractTimestamp(info); } return(info); }
public Model.MediaInfo.MediaInfo GetMediaInfo(InternalMediaInfoResult data, VideoType videoType, bool isAudio, string path, MediaProtocol protocol) { var info = new Model.MediaInfo.MediaInfo { Path = path, Protocol = protocol }; FFProbeHelpers.NormalizeFFProbeResult(data); SetSize(data, info); var internalStreams = data.streams ?? new MediaStreamInfo[] { }; info.MediaStreams = internalStreams.Select(s => GetMediaStream(isAudio, s, data.format)) .Where(i => i != null) .ToList(); if (data.format != null) { info.Container = data.format.format_name; if (!string.IsNullOrEmpty(data.format.bit_rate)) { info.Bitrate = int.Parse(data.format.bit_rate, _usCulture); } } if (isAudio) { SetAudioRuntimeTicks(data, info); var tags = new Dictionary <string, string>(StringComparer.OrdinalIgnoreCase); // tags are normally located under data.format, but we've seen some cases with ogg where they're part of the audio stream // so let's create a combined list of both if (data.streams != null) { var audioStream = data.streams.FirstOrDefault(i => string.Equals(i.codec_type, "audio", StringComparison.OrdinalIgnoreCase)); if (audioStream != null && audioStream.tags != null) { foreach (var pair in audioStream.tags) { tags[pair.Key] = pair.Value; } } } if (data.format != null && data.format.tags != null) { foreach (var pair in data.format.tags) { tags[pair.Key] = pair.Value; } } SetAudioInfoFromTags(info, tags); } else { if (data.format != null && !string.IsNullOrEmpty(data.format.duration)) { info.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(data.format.duration, _usCulture)).Ticks; } FetchWtvInfo(info, data); if (data.Chapters != null) { info.Chapters = data.Chapters.Select(GetChapterInfo).ToList(); } ExtractTimestamp(info); var videoStream = info.MediaStreams.FirstOrDefault(i => i.Type == MediaStreamType.Video); if (videoStream != null && videoType == VideoType.VideoFile) { UpdateFromMediaInfo(info, videoStream); } } return(info); }