From b91dcdbff43559e4cbaa4148d56f6b7295256b7a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 31 Oct 2016 01:51:43 -0400 Subject: [PATCH] update audio queries --- .../Serialization/XmlSerializer.cs | 11 +- .../project.fragment.lock.json | 17 +- Emby.Dlna/project.fragment.lock.json | 28 ++- MediaBrowser.Api/StartupWizardService.cs | 1 + .../Entities/Audio/Audio.cs | 12 - MediaBrowser.Controller/Entities/BaseItem.cs | 15 +- MediaBrowser.Controller/Entities/Video.cs | 12 - .../Configuration/ServerConfiguration.cs | 1 + .../Channels/ChannelManager.cs | 41 +++- .../Persistence/SqliteItemRepository.cs | 90 +++++++- .../ApplicationHost.cs | 215 +++--------------- Mono.Nat/project.fragment.lock.json | 17 +- 12 files changed, 226 insertions(+), 234 deletions(-) diff --git a/Emby.Common.Implementations/Serialization/XmlSerializer.cs b/Emby.Common.Implementations/Serialization/XmlSerializer.cs index ca162e8683..aea63a57e2 100644 --- a/Emby.Common.Implementations/Serialization/XmlSerializer.cs +++ b/Emby.Common.Implementations/Serialization/XmlSerializer.cs @@ -51,7 +51,6 @@ namespace Emby.Common.Implementations.Serialization /// The writer. private void SerializeToWriter(object obj, XmlWriter writer) { - //writer.Formatting = Formatting.Indented; var netSerializer = GetSerializer(obj.GetType()); netSerializer.Serialize(writer, obj); } @@ -78,10 +77,18 @@ namespace Emby.Common.Implementations.Serialization /// The stream. public void SerializeToStream(object obj, Stream stream) { - using (var writer = XmlWriter.Create(stream)) +#if NET46 + using (var writer = new XmlTextWriter(stream, null)) { + writer.Formatting = System.Xml.Formatting.Indented; SerializeToWriter(obj, writer); } +#else + using (var writer = XmlWriter.Create(stream)) + { + SerializeToWriter(obj, writer); + } +#endif } /// diff --git a/Emby.Common.Implementations/project.fragment.lock.json b/Emby.Common.Implementations/project.fragment.lock.json index 0d8df5a0e2..6a89a6320c 100644 --- a/Emby.Common.Implementations/project.fragment.lock.json +++ b/Emby.Common.Implementations/project.fragment.lock.json @@ -5,23 +5,30 @@ "type": "project", "framework": ".NETPortable,Version=v4.5,Profile=Profile7", "compile": { - "bin/Release/MediaBrowser.Common.dll": {} + "bin/Debug/MediaBrowser.Common.dll": {} }, "runtime": { - "bin/Release/MediaBrowser.Common.dll": {} + "bin/Debug/MediaBrowser.Common.dll": {} + }, + "contentFiles": { + "bin/Debug/MediaBrowser.Common.pdb": { + "buildAction": "None", + "codeLanguage": "any", + "copyToOutput": true + } } }, "MediaBrowser.Model/1.0.0": { "type": "project", "framework": ".NETPortable,Version=v4.5,Profile=Profile7", "compile": { - "bin/Release/MediaBrowser.Model.dll": {} + "bin/Debug/MediaBrowser.Model.dll": {} }, "runtime": { - "bin/Release/MediaBrowser.Model.dll": {} + "bin/Debug/MediaBrowser.Model.dll": {} }, "contentFiles": { - "bin/Release/MediaBrowser.Model.pdb": { + "bin/Debug/MediaBrowser.Model.pdb": { "buildAction": "None", "codeLanguage": "any", "copyToOutput": true diff --git a/Emby.Dlna/project.fragment.lock.json b/Emby.Dlna/project.fragment.lock.json index df837d207b..09e853c1cb 100644 --- a/Emby.Dlna/project.fragment.lock.json +++ b/Emby.Dlna/project.fragment.lock.json @@ -5,33 +5,47 @@ "type": "project", "framework": ".NETPortable,Version=v4.5,Profile=Profile7", "compile": { - "bin/Release/MediaBrowser.Common.dll": {} + "bin/Debug/MediaBrowser.Common.dll": {} }, "runtime": { - "bin/Release/MediaBrowser.Common.dll": {} + "bin/Debug/MediaBrowser.Common.dll": {} + }, + "contentFiles": { + "bin/Debug/MediaBrowser.Common.pdb": { + "buildAction": "None", + "codeLanguage": "any", + "copyToOutput": true + } } }, "MediaBrowser.Controller/1.0.0": { "type": "project", "framework": ".NETPortable,Version=v4.5,Profile=Profile7", "compile": { - "bin/Release/MediaBrowser.Controller.dll": {} + "bin/Debug/MediaBrowser.Controller.dll": {} }, "runtime": { - "bin/Release/MediaBrowser.Controller.dll": {} + "bin/Debug/MediaBrowser.Controller.dll": {} + }, + "contentFiles": { + "bin/Debug/MediaBrowser.Controller.pdb": { + "buildAction": "None", + "codeLanguage": "any", + "copyToOutput": true + } } }, "MediaBrowser.Model/1.0.0": { "type": "project", "framework": ".NETPortable,Version=v4.5,Profile=Profile7", "compile": { - "bin/Release/MediaBrowser.Model.dll": {} + "bin/Debug/MediaBrowser.Model.dll": {} }, "runtime": { - "bin/Release/MediaBrowser.Model.dll": {} + "bin/Debug/MediaBrowser.Model.dll": {} }, "contentFiles": { - "bin/Release/MediaBrowser.Model.pdb": { + "bin/Debug/MediaBrowser.Model.pdb": { "buildAction": "None", "codeLanguage": "any", "copyToOutput": true diff --git a/MediaBrowser.Api/StartupWizardService.cs b/MediaBrowser.Api/StartupWizardService.cs index ddeac4d5d3..49fdcece18 100644 --- a/MediaBrowser.Api/StartupWizardService.cs +++ b/MediaBrowser.Api/StartupWizardService.cs @@ -119,6 +119,7 @@ namespace MediaBrowser.Api config.EnableSimpleArtistDetection = true; config.SkipDeserializationForBasicTypes = true; config.SkipDeserializationForPrograms = true; + config.SkipDeserializationForAudio = true; } public void Post(UpdateStartupConfiguration request) diff --git a/MediaBrowser.Controller/Entities/Audio/Audio.cs b/MediaBrowser.Controller/Entities/Audio/Audio.cs index cd44616081..539cc5f221 100644 --- a/MediaBrowser.Controller/Entities/Audio/Audio.cs +++ b/MediaBrowser.Controller/Entities/Audio/Audio.cs @@ -26,9 +26,6 @@ namespace MediaBrowser.Controller.Entities.Audio { public List ChannelMediaSources { get; set; } - public int? TotalBitrate { get; set; } - public ExtraType? ExtraType { get; set; } - /// /// Gets or sets the artist. /// @@ -37,15 +34,6 @@ namespace MediaBrowser.Controller.Entities.Audio public List AlbumArtists { get; set; } - [IgnoreDataMember] - public override bool IsThemeMedia - { - get - { - return ExtraType.HasValue && ExtraType.Value == Model.Entities.ExtraType.ThemeSong; - } - } - [IgnoreDataMember] public override bool EnableRefreshOnDateModifiedChange { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 8211d89d2d..433fdbe16d 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -203,12 +203,15 @@ namespace MediaBrowser.Controller.Entities get { return PremiereDate.HasValue && PremiereDate.Value.ToLocalTime().Date >= DateTime.Now.Date; } } + public int? TotalBitrate { get; set; } + public ExtraType? ExtraType { get; set; } + [IgnoreDataMember] - public virtual bool IsThemeMedia + public bool IsThemeMedia { get { - return false; + return ExtraType.HasValue && (ExtraType.Value == Model.Entities.ExtraType.ThemeSong || ExtraType.Value == Model.Entities.ExtraType.ThemeVideo); } } @@ -1045,7 +1048,7 @@ namespace MediaBrowser.Controller.Entities audio = dbItem; } - audio.ExtraType = ExtraType.ThemeSong; + audio.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeSong; return audio; @@ -1075,7 +1078,7 @@ namespace MediaBrowser.Controller.Entities item = dbItem; } - item.ExtraType = ExtraType.ThemeVideo; + item.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo; return item; @@ -1225,7 +1228,7 @@ namespace MediaBrowser.Controller.Entities if (!i.IsThemeMedia) { - i.ExtraType = ExtraType.ThemeVideo; + i.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeVideo; subOptions.ForceSave = true; } @@ -1255,7 +1258,7 @@ namespace MediaBrowser.Controller.Entities if (!i.IsThemeMedia) { - i.ExtraType = ExtraType.ThemeSong; + i.ExtraType = MediaBrowser.Model.Entities.ExtraType.ThemeSong; subOptions.ForceSave = true; } diff --git a/MediaBrowser.Controller/Entities/Video.cs b/MediaBrowser.Controller/Entities/Video.cs index 6b8c894c8d..2dd134334f 100644 --- a/MediaBrowser.Controller/Entities/Video.cs +++ b/MediaBrowser.Controller/Entities/Video.cs @@ -35,15 +35,6 @@ namespace MediaBrowser.Controller.Entities public List LinkedAlternateVersions { get; set; } public List ChannelMediaSources { get; set; } - [IgnoreDataMember] - public override bool IsThemeMedia - { - get - { - return ExtraType.HasValue && ExtraType.Value == Model.Entities.ExtraType.ThemeVideo; - } - } - [IgnoreDataMember] public override bool SupportsPlayedStatus { @@ -87,9 +78,6 @@ namespace MediaBrowser.Controller.Entities get { return true; } } - public int? TotalBitrate { get; set; } - public ExtraType? ExtraType { get; set; } - /// /// Gets or sets the timestamp. /// diff --git a/MediaBrowser.Model/Configuration/ServerConfiguration.cs b/MediaBrowser.Model/Configuration/ServerConfiguration.cs index a1e5637a49..b1e52dc7b6 100644 --- a/MediaBrowser.Model/Configuration/ServerConfiguration.cs +++ b/MediaBrowser.Model/Configuration/ServerConfiguration.cs @@ -170,6 +170,7 @@ namespace MediaBrowser.Model.Configuration public bool EnableAutomaticRestart { get; set; } public bool SkipDeserializationForBasicTypes { get; set; } public bool SkipDeserializationForPrograms { get; set; } + public bool SkipDeserializationForAudio { get; set; } public PathSubstitution[] PathSubstitutions { get; set; } diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index ffb9c96e7a..300973ce10 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -252,6 +252,42 @@ namespace MediaBrowser.Server.Implementations.Channels return item; } + private List GetSavedMediaSources(BaseItem item) + { + var path = Path.Combine(item.GetInternalMetadataPath(), "channelmediasources.json"); + + try + { + return _jsonSerializer.DeserializeFromFile>(path) ?? new List(); + } + catch + { + return new List(); + } + } + + private void SaveMediaSources(BaseItem item, List mediaSources) + { + var path = Path.Combine(item.GetInternalMetadataPath(), "channelmediasources.json"); + + if (mediaSources == null || mediaSources.Count == 0) + { + try + { + _fileSystem.DeleteFile(path); + } + catch + { + + } + return; + } + + _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + + _jsonSerializer.SerializeToFile(mediaSources, path); + } + public async Task> GetStaticMediaSources(BaseItem item, bool includeCachedVersions, CancellationToken cancellationToken) { IEnumerable results = new List(); @@ -263,7 +299,7 @@ namespace MediaBrowser.Server.Implementations.Channels var audio = item as Audio; if (audio != null) { - results = audio.ChannelMediaSources ?? new List(); + results = audio.ChannelMediaSources ?? GetSavedMediaSources(audio); } var sources = SortMediaInfoResults(results) @@ -1385,7 +1421,6 @@ namespace MediaBrowser.Server.Implementations.Channels if (channelAudioItem != null) { channelAudioItem.ExtraType = info.ExtraType; - channelAudioItem.ChannelMediaSources = info.MediaSources; var mediaSource = info.MediaSources.FirstOrDefault(); item.Path = mediaSource == null ? null : mediaSource.Path; @@ -1426,6 +1461,8 @@ namespace MediaBrowser.Server.Implementations.Channels await item.UpdateToRepository(ItemUpdateType.None, cancellationToken).ConfigureAwait(false); } + SaveMediaSources(item, info.MediaSources); + return item; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index ffae9a6f08..5fcd38f87d 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -285,6 +285,10 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(Logger, "TypedBaseItems", "ProductionLocations", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "ThemeSongIds", "Text"); _connection.AddColumn(Logger, "TypedBaseItems", "ThemeVideoIds", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "TotalBitrate", "INT"); + _connection.AddColumn(Logger, "TypedBaseItems", "ExtraType", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "Artists", "Text"); + _connection.AddColumn(Logger, "TypedBaseItems", "AlbumArtists", "Text"); _connection.AddColumn(Logger, "ItemValues", "CleanValue", "Text"); @@ -435,7 +439,11 @@ namespace MediaBrowser.Server.Implementations.Persistence "Images", "ProductionLocations", "ThemeSongIds", - "ThemeVideoIds" + "ThemeVideoIds", + "TotalBitrate", + "ExtraType", + "Artists", + "AlbumArtists" }; private readonly string[] _mediaStreamSaveColumns = @@ -566,7 +574,11 @@ namespace MediaBrowser.Server.Implementations.Persistence "Images", "ProductionLocations", "ThemeSongIds", - "ThemeVideoIds" + "ThemeVideoIds", + "TotalBitrate", + "ExtraType", + "Artists", + "AlbumArtists" }; _saveItemCommand = _connection.CreateCommand(); _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values ("; @@ -1046,6 +1058,35 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = null; } + _saveItemCommand.GetParameter(index++).Value = item.TotalBitrate; + _saveItemCommand.GetParameter(index++).Value = item.ExtraType; + + var hasArtists = item as IHasArtist; + if (hasArtists != null) + { + if (hasArtists.Artists.Count > 0) + { + _saveItemCommand.GetParameter(index++).Value = string.Join("|", hasArtists.Artists.ToArray()); + } + else + { + _saveItemCommand.GetParameter(index++).Value = null; + } + } + + var hasAlbumArtists = item as IHasAlbumArtist; + if (hasAlbumArtists != null) + { + if (hasAlbumArtists.AlbumArtists.Count > 0) + { + _saveItemCommand.GetParameter(index++).Value = string.Join("|", hasAlbumArtists.AlbumArtists.ToArray()); + } + else + { + _saveItemCommand.GetParameter(index++).Value = null; + } + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -1305,6 +1346,25 @@ namespace MediaBrowser.Server.Implementations.Persistence return false; } } + if (_config.Configuration.SkipDeserializationForAudio) + { + if (type == typeof(Audio)) + { + return false; + } + if (type == typeof(LiveTvAudioRecording)) + { + return false; + } + if (type == typeof(AudioPodcast)) + { + return false; + } + if (type == typeof(MusicAlbum)) + { + return false; + } + } return true; } @@ -1884,6 +1944,32 @@ namespace MediaBrowser.Server.Implementations.Persistence index++; } + if (!reader.IsDBNull(index)) + { + item.TotalBitrate = reader.GetInt32(index); + } + index++; + + if (!reader.IsDBNull(index)) + { + item.ExtraType = (ExtraType)Enum.Parse(typeof(ExtraType), reader.GetString(index), true); + } + index++; + + var hasArtists = item as IHasArtist; + if (hasArtists != null && !reader.IsDBNull(index)) + { + hasArtists.Artists = reader.GetString(index).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).ToList(); + } + index++; + + var hasAlbumArtists = item as IHasAlbumArtist; + if (hasAlbumArtists != null && !reader.IsDBNull(index)) + { + hasAlbumArtists.AlbumArtists = reader.GetString(index).Split('|').Where(i => !string.IsNullOrWhiteSpace(i)).ToList(); + } + index++; + if (string.IsNullOrWhiteSpace(item.Tagline)) { var movie = item as Movie; diff --git a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs index ad9b3960fd..7ff50df63d 100644 --- a/MediaBrowser.Server.Startup.Common/ApplicationHost.cs +++ b/MediaBrowser.Server.Startup.Common/ApplicationHost.cs @@ -434,187 +434,40 @@ namespace MediaBrowser.Server.Startup.Common var result = new JsonSerializer(FileSystemManager, LogManager.GetLogger("JsonSerializer")); - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ShortOverview" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "Taglines" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "Keywords" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ShortOverview" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ShortOverview" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "PlaceOfBirth" }; - - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ProviderIds" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ProviderIds" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ProviderIds" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ProviderIds" }; - ServiceStack.Text.JsConfig.ExcludePropertyNames = new[] { "ProviderIds" }; - ServiceStack.Text.JsConfig