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); }
private void SetAudioInfoFromTags(Model.MediaInfo.MediaInfo audio, Dictionary <string, string> tags) { var title = FFProbeHelpers.GetDictionaryValue(tags, "title"); // Only set Name if title was found in the dictionary if (!string.IsNullOrEmpty(title)) { audio.Title = title; } var composer = FFProbeHelpers.GetDictionaryValue(tags, "composer"); if (!string.IsNullOrWhiteSpace(composer)) { foreach (var person in Split(composer, false)) { audio.People.Add(new BaseItemPerson { Name = person, Type = PersonType.Composer }); } } audio.Album = FFProbeHelpers.GetDictionaryValue(tags, "album"); var artists = FFProbeHelpers.GetDictionaryValue(tags, "artists"); if (!string.IsNullOrWhiteSpace(artists)) { audio.Artists = artists.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); } else { var artist = FFProbeHelpers.GetDictionaryValue(tags, "artist"); if (string.IsNullOrWhiteSpace(artist)) { audio.Artists.Clear(); } else { audio.Artists = SplitArtists(artist) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); } } var albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "albumartist"); if (string.IsNullOrWhiteSpace(albumArtist)) { albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "album artist"); } if (string.IsNullOrWhiteSpace(albumArtist)) { albumArtist = FFProbeHelpers.GetDictionaryValue(tags, "album_artist"); } if (string.IsNullOrWhiteSpace(albumArtist)) { audio.AlbumArtists = new List <string>(); } else { audio.AlbumArtists = SplitArtists(albumArtist) .Distinct(StringComparer.OrdinalIgnoreCase) .ToList(); } // Track number audio.IndexNumber = GetDictionaryDiscValue(tags, "track"); // Disc number audio.ParentIndexNumber = GetDictionaryDiscValue(tags, "disc"); audio.ProductionYear = FFProbeHelpers.GetDictionaryNumericValue(tags, "date"); // Several different forms of retaildate audio.PremiereDate = FFProbeHelpers.GetDictionaryDateTime(tags, "retaildate") ?? FFProbeHelpers.GetDictionaryDateTime(tags, "retail date") ?? FFProbeHelpers.GetDictionaryDateTime(tags, "retail_date") ?? FFProbeHelpers.GetDictionaryDateTime(tags, "date"); // If we don't have a ProductionYear try and get it from PremiereDate if (audio.PremiereDate.HasValue && !audio.ProductionYear.HasValue) { audio.ProductionYear = audio.PremiereDate.Value.ToLocalTime().Year; } FetchGenres(audio, tags); // There's several values in tags may or may not be present FetchStudios(audio, tags, "organization"); FetchStudios(audio, tags, "ensemble"); FetchStudios(audio, tags, "publisher"); // These support mulitple values, but for now we only store the first. audio.SetProviderId(MetadataProviders.MusicBrainzAlbumArtist, GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Album Artist Id"))); audio.SetProviderId(MetadataProviders.MusicBrainzArtist, GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Artist Id"))); audio.SetProviderId(MetadataProviders.MusicBrainzAlbum, GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Album Id"))); audio.SetProviderId(MetadataProviders.MusicBrainzReleaseGroup, GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Release Group Id"))); audio.SetProviderId(MetadataProviders.MusicBrainzTrack, GetMultipleMusicBrainzId(FFProbeHelpers.GetDictionaryValue(tags, "MusicBrainz Release Track Id"))); }