From b91dcdbff43559e4cbaa4148d56f6b7295256b7a Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 31 Oct 2016 01:51:43 -0400 Subject: update audio queries --- .../Channels/ChannelManager.cs | 41 +++++++++- .../Persistence/SqliteItemRepository.cs | 90 +++++++++++++++++++++- 2 files changed, 127 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Server.Implementations') diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index ffb9c96e7..300973ce1 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 ffae9a6f0..5fcd38f87 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; -- cgit v1.2.3