The Free Software Media System - Server Backend & API
Added support for more Audio fields
LukePulverenti Luke Pulverenti luke pulverentifd2ead1aff7b
diff --git a/MediaBrowser.Api/ApiService.cs b/MediaBrowser.Api/ApiService.csindex 3878389df5..f6db269286 100644--- a/MediaBrowser.Api/ApiService.cs+++ b/MediaBrowser.Api/ApiService.cs@@ -40,6 +40,7 @@ namespace MediaBrowser.Apidto.IsNew = item.IsRecentlyAdded(user);dto.IndexNumber = item.IndexNumber;dto.IsFolder = item.IsFolder;+ dto.Language = item.Language;dto.LocalTrailerCount = item.LocalTrailers == null ? 0 : item.LocalTrailers.Count();dto.Name = item.Name;dto.OfficialRating = item.OfficialRating;@@ -58,6 +59,8 @@ namespace MediaBrowser.Apidto.ParentId = item.Parent.Id;}+ dto.ParentIndexNumber = item.ParentIndexNumber;+// If there is no logo, indicate what parent has one in case the UI wants to allow inheritanceif (!dto.HasLogo){diff --git a/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs b/MediaBrowser.Controller/FFMpeg/FFProbeResult.csindex 43167b521a..e7e7e5694f 100644--- a/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs+++ b/MediaBrowser.Controller/FFMpeg/FFProbeResult.cs@@ -1,4 +1,5 @@-using System.Collections.Generic;+using System;+using System.Collections.Generic;namespace MediaBrowser.Controller.FFMpeg{@@ -47,7 +48,7 @@ namespace MediaBrowser.Controller.FFMpeg//public string pix_fmt { get; set; }//public int level { get; set; }public Dictionary<string,string> tags { get; set; }- }+ }public class MediaFormat{diff --git a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs b/MediaBrowser.Controller/Providers/AudioInfoProvider.csindex 70adb688f1..79ee7f9f69 100644--- a/MediaBrowser.Controller/Providers/AudioInfoProvider.cs+++ b/MediaBrowser.Controller/Providers/AudioInfoProvider.cs@@ -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{@@ -27,30 +28,155 @@ namespace MediaBrowser.Controller.ProvidersFFProbeResult data = await FFProbe.Run(audio, outputPath);- MediaStream stream = data.streams.FirstOrDefault(s => s.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase));+ MediaStream stream = data.streams.First(s => s.codec_type.Equals("audio", StringComparison.OrdinalIgnoreCase));++ string bitrate = null;+ string duration = null;audio.Channels = stream.channels;- string bitrate = null;-if (!string.IsNullOrEmpty(stream.sample_rate)){audio.SampleRate = int.Parse(stream.sample_rate);-- bitrate = stream.bit_rate;}+ bitrate = stream.bit_rate;+ duration = stream.duration;+if (string.IsNullOrEmpty(bitrate)){bitrate = data.format.bit_rate;}+ if (string.IsNullOrEmpty(duration))+ {+ duration = data.format.duration;+ }+if (!string.IsNullOrEmpty(bitrate)){audio.BitRate = int.Parse(bitrate);}++ if (!string.IsNullOrEmpty(duration))+ {+ audio.RunTimeTicks = TimeSpan.FromSeconds(double.Parse(duration)).Ticks;+ }++ if (data.format.tags != null)+ {+ FetchDataFromTags(audio, data.format.tags);+ }}+ private void FetchDataFromTags(Audio audio, Dictionary<string, string> tags)+ {+ string title = GetDictionaryValue(tags, "title");++ if (!string.IsNullOrEmpty(title))+ {+ audio.Name = title;+ }++ audio.Album = GetDictionaryValue(tags, "album");+ audio.Composer = GetDictionaryValue(tags, "composer");+ audio.Artist = GetDictionaryValue(tags, "artist");+ audio.AlbumArtist = GetDictionaryValue(tags, "albumartist") ?? GetDictionaryValue(tags, "album artist") ?? GetDictionaryValue(tags, "album_artist");++ audio.IndexNumber = GetDictionaryNumericValue(tags, "track");+ audio.ParentIndexNumber = GetDictionaryDiscValue(tags);++ audio.Language = GetDictionaryValue(tags, "language");++ audio.ProductionYear = GetDictionaryNumericValue(tags, "date");++ audio.PremiereDate = GetDictionaryDateTime(tags, "retaildate") ?? GetDictionaryDateTime(tags, "retail date") ?? GetDictionaryDateTime(tags, "retail_date");++ MediaBrowser.Common.Logging.Logger.LogInfo(tags.Comparer.GetType().Name.ToString());+ }++ private int? GetDictionaryDiscValue(Dictionary<string, string> tags)+ {+ string[] keys = tags.Keys.ToArray();++ for (int i = 0; i < keys.Length; i++)+ {+ string currentKey = keys[i];++ if ("disc".Equals(currentKey, StringComparison.OrdinalIgnoreCase))+ {+ string disc = tags[currentKey];++ if (!string.IsNullOrEmpty(disc))+ {+ disc = disc.Split('/')[0];++ int num;++ if (int.TryParse(disc, out num))+ {+ return num;+ }+ }++ break;+ }+ }++ return null;+ }++ private string GetDictionaryValue(Dictionary<string, string> tags, string key)+ {+ string[] keys = tags.Keys.ToArray();++ for (int i = 0; i < keys.Length; i++)+ {+ string currentKey = keys[i];++ if (key.Equals(currentKey, StringComparison.OrdinalIgnoreCase))+ {+ return tags[currentKey];+ }+ }++ return null;+ }++ private int? GetDictionaryNumericValue(Dictionary<string, string> tags, string key)+ {+ string val = GetDictionaryValue(tags, key);++ if (!string.IsNullOrEmpty(val))+ {+ int i;++ if (int.TryParse(val, out i))+ {+ return i;+ }+ }++ return null;+ }++ private DateTime? GetDictionaryDateTime(Dictionary<string, string> tags, string key)+ {+ string val = GetDictionaryValue(tags, key);++ if (!string.IsNullOrEmpty(val))+ {+ DateTime i;++ if (DateTime.TryParse(val, out i))+ {+ return i;+ }+ }++ return null;+ }+private string GetOutputCachePath(BaseItem item){string outputDirectory = Path.Combine(Kernel.Instance.ApplicationPaths.FFProbeAudioCacheDirectory, item.Id.ToString().Substring(0, 1));diff --git a/MediaBrowser.Model/DTO/DTOBaseItem.cs b/MediaBrowser.Model/DTO/DTOBaseItem.csindex a469bf4eb2..9bc86a6b14 100644--- a/MediaBrowser.Model/DTO/DTOBaseItem.cs+++ b/MediaBrowser.Model/DTO/DTOBaseItem.cs@@ -32,6 +32,7 @@ namespace MediaBrowser.Model.DTOpublic int? ProductionYear { get; set; }public int? IndexNumber { get; set; }+ public int? ParentIndexNumber { get; set; }public string TrailerUrl { get; set; }@@ -43,6 +44,8 @@ namespace MediaBrowser.Model.DTOpublic bool HasThumb { get; set; }public bool HasPrimaryImage { get; set; }+ public string Language { get; set; }+public int BackdropCount { get; set; }public IEnumerable<DTOBaseItem> Children { get; set; }diff --git a/MediaBrowser.Model/Entities/Audio.cs b/MediaBrowser.Model/Entities/Audio.csindex fd202b6c3f..cc48a58a7f 100644--- a/MediaBrowser.Model/Entities/Audio.cs+++ b/MediaBrowser.Model/Entities/Audio.cs@@ -6,5 +6,10 @@ namespace MediaBrowser.Model.Entitiespublic int BitRate { get; set; }public int Channels { get; set; }public int SampleRate { get; set; }++ public string Artist { get; set; }+ public string Album { get; set; }+ public string AlbumArtist { get; set; }+ public string Composer { get; set; }}}diff --git a/MediaBrowser.Model/Entities/BaseItem.cs b/MediaBrowser.Model/Entities/BaseItem.csindex 69a5410b2b..249dee3ac8 100644--- a/MediaBrowser.Model/Entities/BaseItem.cs+++ b/MediaBrowser.Model/Entities/BaseItem.cs@@ -54,6 +54,7 @@ namespace MediaBrowser.Model.Entitiespublic string CustomRating { get; set; }+ public string Language { get; set; }public string Overview { get; set; }public IEnumerable<string> Taglines { get; set; }@@ -77,6 +78,11 @@ namespace MediaBrowser.Model.Entities/// </summary>public int? IndexNumber { get; set; }+ /// <summary>+ /// For an episode this could be the season number, or for a song this could be the disc number.+ /// </summary>+ public int? ParentIndexNumber { get; set; }+public IEnumerable<Video> LocalTrailers { get; set; }public string TrailerUrl { get; set; }diff --git a/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs b/MediaBrowser.TV/Metadata/EpisodeXmlParser.csindex ef8a6705fd..82d2d3c406 100644--- a/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs+++ b/MediaBrowser.TV/Metadata/EpisodeXmlParser.cs@@ -22,14 +22,27 @@ namespace MediaBrowser.TV.Metadata}break;}- case "EpisodeNumber":- string number = reader.ReadString();+ case "SeasonNumber":+ {+ string number = reader.ReadString();++ if (!string.IsNullOrWhiteSpace(number))+ {+ item.ParentIndexNumber = int.Parse(number);+ }+ break;+ }- if (!string.IsNullOrWhiteSpace(number))+ case "EpisodeNumber":{- item.IndexNumber = int.Parse(number);+ string number = reader.ReadString();++ if (!string.IsNullOrWhiteSpace(number))+ {+ item.IndexNumber = int.Parse(number);+ }+ break;}- break;case "EpisodeName":item.Name = reader.ReadString();