From f2abd8ba39eefd5397eb3f0e327efbca8d8ecd0f Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 1 Jun 2015 10:49:23 -0400 Subject: update live tv database --- .../Persistence/SqliteItemRepository.cs | 332 ++++++++++++++++++++- 1 file changed, 322 insertions(+), 10 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs') diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index c5a9db87b..19aca1cf9 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -1,12 +1,15 @@ using MediaBrowser.Common.Configuration; using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.LiveTv; using MediaBrowser.Controller.Persistence; using MediaBrowser.Model.Entities; using MediaBrowser.Model.Logging; +using MediaBrowser.Model.Querying; using MediaBrowser.Model.Serialization; using System; using System.Collections.Generic; using System.Data; +using System.Globalization; using System.IO; using System.Linq; using System.Threading; @@ -126,6 +129,12 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.RunQueries(queries, _logger); + _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME"); + _connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME"); + _connection.AddColumn(_logger, "TypedBaseItems", "ChannelId", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT"); + _connection.AddColumn(_logger, "TypedBaseItems", "IsSports", "BIT"); + PrepareStatements(); _mediaStreamsRepository.Initialize(); @@ -143,10 +152,15 @@ namespace MediaBrowser.Server.Implementations.Persistence private void PrepareStatements() { _saveItemCommand = _connection.CreateCommand(); - _saveItemCommand.CommandText = "replace into TypedBaseItems (guid, type, data) values (@1, @2, @3)"; + _saveItemCommand.CommandText = "replace into TypedBaseItems (guid, type, data, StartDate, EndDate, ChannelId, IsMovie, IsSports) values (@1, @2, @3, @4, @5, @6, @7, @8)"; _saveItemCommand.Parameters.Add(_saveItemCommand, "@1"); _saveItemCommand.Parameters.Add(_saveItemCommand, "@2"); _saveItemCommand.Parameters.Add(_saveItemCommand, "@3"); + _saveItemCommand.Parameters.Add(_saveItemCommand, "@4"); + _saveItemCommand.Parameters.Add(_saveItemCommand, "@5"); + _saveItemCommand.Parameters.Add(_saveItemCommand, "@6"); + _saveItemCommand.Parameters.Add(_saveItemCommand, "@7"); + _saveItemCommand.Parameters.Add(_saveItemCommand, "@8"); _deleteChildrenCommand = _connection.CreateCommand(); _deleteChildrenCommand.CommandText = "delete from ChildrenIds where ParentId=@ParentId"; @@ -155,7 +169,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _deleteItemCommand = _connection.CreateCommand(); _deleteItemCommand.CommandText = "delete from TypedBaseItems where guid=@Id"; _deleteItemCommand.Parameters.Add(_deleteItemCommand, "@Id"); - + _saveChildrenCommand = _connection.CreateCommand(); _saveChildrenCommand.CommandText = "replace into ChildrenIds (ParentId, ItemId) values (@ParentId, @ItemId)"; _saveChildrenCommand.Parameters.Add(_saveChildrenCommand, "@ParentId"); @@ -200,7 +214,7 @@ namespace MediaBrowser.Server.Implementations.Persistence cancellationToken.ThrowIfCancellationRequested(); CheckDisposed(); - + await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -217,6 +231,31 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(1).Value = item.GetType().FullName; _saveItemCommand.GetParameter(2).Value = _jsonSerializer.SerializeToBytes(item); + var hasStartDate = item as IHasStartDate; + if (hasStartDate != null) + { + _saveItemCommand.GetParameter(3).Value = hasStartDate.StartDate; + } + else + { + _saveItemCommand.GetParameter(3).Value = null; + } + + _saveItemCommand.GetParameter(4).Value = item.EndDate; + _saveItemCommand.GetParameter(5).Value = item.ChannelId; + + var hasProgramAttributes = item as IHasProgramAttributes; + if (hasProgramAttributes != null) + { + _saveItemCommand.GetParameter(6).Value = hasProgramAttributes.IsMovie; + _saveItemCommand.GetParameter(7).Value = hasProgramAttributes.IsSports; + } + else + { + _saveItemCommand.GetParameter(6).Value = null; + _saveItemCommand.GetParameter(7).Value = null; + } + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); @@ -254,7 +293,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _writeLock.Release(); } } - + /// /// Internal retrieve from items or users table /// @@ -270,7 +309,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } CheckDisposed(); - + using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "select type,data from TypedBaseItems where guid = @guid"; @@ -467,7 +506,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } CheckDisposed(); - + using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "select ItemId from ChildrenIds where ParentId = @ParentId"; @@ -492,7 +531,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } CheckDisposed(); - + using (var cmd = _connection.CreateCommand()) { cmd.CommandText = "select type,data from TypedBaseItems where guid in (select ItemId from ChildrenIds where ParentId = @ParentId)"; @@ -544,6 +583,279 @@ namespace MediaBrowser.Server.Implementations.Persistence } } + public QueryResult GetItems(InternalItemsQuery query) + { + if (query == null) + { + throw new ArgumentNullException("query"); + } + + CheckDisposed(); + + using (var cmd = _connection.CreateCommand()) + { + cmd.CommandText = "select type,data from TypedBaseItems"; + + var whereClauses = GetWhereClauses(query, cmd, false); + + var whereTextWithoutPaging = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + whereClauses = GetWhereClauses(query, cmd, true); + + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + cmd.CommandText += whereText; + + if (query.Limit.HasValue) + { + cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); + } + + cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging; + + var list = new List(); + var count = 0; + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) + { + while (reader.Read()) + { + list.Add(GetItem(reader)); + } + + if (reader.NextResult() && reader.Read()) + { + count = reader.GetInt32(0); + } + } + + return new QueryResult() + { + Items = list.ToArray(), + TotalRecordCount = count + }; + } + } + + public List GetItemIdsList(InternalItemsQuery query) + { + if (query == null) + { + throw new ArgumentNullException("query"); + } + + CheckDisposed(); + + using (var cmd = _connection.CreateCommand()) + { + cmd.CommandText = "select guid from TypedBaseItems"; + + var whereClauses = GetWhereClauses(query, cmd, false); + + whereClauses = GetWhereClauses(query, cmd, true); + + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + cmd.CommandText += whereText; + + if (query.Limit.HasValue) + { + cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); + } + + var list = new List(); + + _logger.Debug(cmd.CommandText); + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) + { + while (reader.Read()) + { + list.Add(reader.GetGuid(0)); + } + } + + return list; + } + } + + public QueryResult GetItemIds(InternalItemsQuery query) + { + if (query == null) + { + throw new ArgumentNullException("query"); + } + + CheckDisposed(); + + using (var cmd = _connection.CreateCommand()) + { + cmd.CommandText = "select guid from TypedBaseItems"; + + var whereClauses = GetWhereClauses(query, cmd, false); + + var whereTextWithoutPaging = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + whereClauses = GetWhereClauses(query, cmd, true); + + var whereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + cmd.CommandText += whereText; + + if (query.Limit.HasValue) + { + cmd.CommandText += " LIMIT " + query.Limit.Value.ToString(CultureInfo.InvariantCulture); + } + + cmd.CommandText += "; select count (guid) from TypedBaseItems" + whereTextWithoutPaging; + + var list = new List(); + var count = 0; + + _logger.Debug(cmd.CommandText); + + using (var reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess)) + { + while (reader.Read()) + { + list.Add(reader.GetGuid(0)); + } + + if (reader.NextResult() && reader.Read()) + { + count = reader.GetInt32(0); + } + } + + return new QueryResult() + { + Items = list.ToArray(), + TotalRecordCount = count + }; + } + } + + private List GetWhereClauses(InternalItemsQuery query, IDbCommand cmd, bool addPaging) + { + var whereClauses = new List(); + + if (query.IsMovie.HasValue) + { + whereClauses.Add("IsMovie=@IsMovie"); + cmd.Parameters.Add(cmd, "@IsMovie", DbType.Boolean).Value = query.IsMovie; + } + if (query.IsSports.HasValue) + { + whereClauses.Add("IsSports=@IsSports"); + cmd.Parameters.Add(cmd, "@IsSports", DbType.Boolean).Value = query.IsSports; + } + if (query.IncludeItemTypes.Length == 1) + { + whereClauses.Add("type=@type"); + cmd.Parameters.Add(cmd, "@type", DbType.String).Value = MapIncludeItemType(query.IncludeItemTypes[0]); + } + if (query.IncludeItemTypes.Length > 1) + { + var inClause = string.Join(",", query.IncludeItemTypes.Select(i => "'" + MapIncludeItemType(i) + "'").ToArray()); + whereClauses.Add(string.Format("type in ({0})", inClause)); + } + if (query.ChannelIds.Length == 1) + { + whereClauses.Add("ChannelId=@ChannelId"); + cmd.Parameters.Add(cmd, "@ChannelId", DbType.String).Value = query.ChannelIds[0]; + } + if (query.ChannelIds.Length > 1) + { + var inClause = string.Join(",", query.ChannelIds.Select(i => "'" + i + "'").ToArray()); + whereClauses.Add(string.Format("ChannelId in ({0})", inClause)); + } + + if (query.MinEndDate.HasValue) + { + whereClauses.Add("EndDate>=@MinEndDate"); + cmd.Parameters.Add(cmd, "@MinEndDate", DbType.Date).Value = query.MinEndDate.Value; + } + + if (query.MaxEndDate.HasValue) + { + whereClauses.Add("EndDate<=@MaxEndDate"); + cmd.Parameters.Add(cmd, "@MaxEndDate", DbType.Date).Value = query.MaxEndDate.Value; + } + + if (query.MinStartDate.HasValue) + { + whereClauses.Add("StartDate>=@MinStartDate"); + cmd.Parameters.Add(cmd, "@MinStartDate", DbType.Date).Value = query.MinStartDate.Value; + } + + if (query.MaxStartDate.HasValue) + { + whereClauses.Add("StartDate<=@MaxStartDate"); + cmd.Parameters.Add(cmd, "@MaxStartDate", DbType.Date).Value = query.MaxStartDate.Value; + } + + if (query.IsAiring.HasValue) + { + if (query.IsAiring.Value) + { + whereClauses.Add("StartDate<=@MaxStartDate"); + cmd.Parameters.Add(cmd, "@MaxStartDate", DbType.Date).Value = DateTime.UtcNow; + + whereClauses.Add("EndDate>=@MinEndDate"); + cmd.Parameters.Add(cmd, "@MinEndDate", DbType.Date).Value = DateTime.UtcNow; + } + else + { + whereClauses.Add("(StartDate>@IsAiringDate OR EndDate < @IsAiringDate)"); + cmd.Parameters.Add(cmd, "@IsAiringDate", DbType.Date).Value = DateTime.UtcNow; + } + } + + if (addPaging) + { + if (query.StartIndex.HasValue && query.StartIndex.Value > 0) + { + var pagingWhereText = whereClauses.Count == 0 ? + string.Empty : + " where " + string.Join(" AND ", whereClauses.ToArray()); + + whereClauses.Add(string.Format("Id NOT IN (SELECT Id FROM TypedBaseItems {0} ORDER BY DateCreated DESC LIMIT {1})", + pagingWhereText, + query.StartIndex.Value.ToString(CultureInfo.InvariantCulture))); + } + } + + return whereClauses; + } + + // Not crazy about having this all the way down here, but at least it's in one place + readonly Dictionary _types = new Dictionary(StringComparer.OrdinalIgnoreCase) + { + {typeof(LiveTvProgram).Name, typeof(LiveTvProgram).FullName}, + {typeof(LiveTvChannel).Name, typeof(LiveTvChannel).FullName} + }; + + private string MapIncludeItemType(string value) + { + string result; + if (_types.TryGetValue(value, out result)) + { + return result; + } + + return value; + } + public IEnumerable GetItemIdsOfType(Type type) { if (type == null) @@ -577,7 +889,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } CheckDisposed(); - + await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; @@ -595,7 +907,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _deleteItemCommand.GetParameter(0).Value = id; _deleteItemCommand.Transaction = transaction; _deleteItemCommand.ExecuteNonQuery(); - + transaction.Commit(); } catch (OperationCanceledException) @@ -642,7 +954,7 @@ namespace MediaBrowser.Server.Implementations.Persistence } CheckDisposed(); - + await _writeLock.WaitAsync(cancellationToken).ConfigureAwait(false); IDbTransaction transaction = null; -- cgit v1.2.3 From 418bb8787869b13eca2da0095e94be6b22f2f10d Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 1 Jun 2015 13:07:55 -0400 Subject: update recording database --- MediaBrowser.Controller/Entities/IHasId.cs | 9 + MediaBrowser.Controller/Entities/IHasImages.cs | 9 +- .../Entities/IHasMediaSources.cs | 9 +- .../Entities/IHasProgramAttributes.cs | 12 +- MediaBrowser.Controller/Entities/IHasUserData.cs | 9 +- MediaBrowser.Controller/LiveTv/ILiveTvItem.cs | 5 +- MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs | 20 +- .../LiveTv/LiveTvAudioRecording.cs | 23 +++ .../LiveTv/LiveTvVideoRecording.cs | 23 +++ .../MediaBrowser.Controller.csproj | 1 + .../LiveTv/LiveTvDtoService.cs | 2 +- .../LiveTv/LiveTvManager.cs | 207 +++++++++++++-------- .../LiveTv/RecordingImageProvider.cs | 14 +- .../Persistence/SqliteItemRepository.cs | 28 +-- .../Session/SessionManager.cs | 10 +- Nuget/MediaBrowser.Common.Internal.nuspec | 4 +- Nuget/MediaBrowser.Common.nuspec | 2 +- Nuget/MediaBrowser.Model.Signed.nuspec | 2 +- Nuget/MediaBrowser.Server.Core.nuspec | 4 +- 19 files changed, 259 insertions(+), 134 deletions(-) create mode 100644 MediaBrowser.Controller/Entities/IHasId.cs (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs') diff --git a/MediaBrowser.Controller/Entities/IHasId.cs b/MediaBrowser.Controller/Entities/IHasId.cs new file mode 100644 index 000000000..9698adf7a --- /dev/null +++ b/MediaBrowser.Controller/Entities/IHasId.cs @@ -0,0 +1,9 @@ +using System; + +namespace MediaBrowser.Controller.Entities +{ + public interface IHasId + { + Guid Id { get; } + } +} diff --git a/MediaBrowser.Controller/Entities/IHasImages.cs b/MediaBrowser.Controller/Entities/IHasImages.cs index 1871d7b68..ffb351c94 100644 --- a/MediaBrowser.Controller/Entities/IHasImages.cs +++ b/MediaBrowser.Controller/Entities/IHasImages.cs @@ -1,13 +1,12 @@ using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Entities; -using System; using System.Collections.Generic; using System.IO; using System.Threading.Tasks; namespace MediaBrowser.Controller.Entities { - public interface IHasImages : IHasProviderIds + public interface IHasImages : IHasProviderIds, IHasId { /// /// Gets the name. @@ -27,12 +26,6 @@ namespace MediaBrowser.Controller.Entities /// The file name without extension. string FileNameWithoutExtension { get; } - /// - /// Gets the identifier. - /// - /// The identifier. - Guid Id { get; } - /// /// Gets the type of the location. /// diff --git a/MediaBrowser.Controller/Entities/IHasMediaSources.cs b/MediaBrowser.Controller/Entities/IHasMediaSources.cs index 17a147806..85ce3c781 100644 --- a/MediaBrowser.Controller/Entities/IHasMediaSources.cs +++ b/MediaBrowser.Controller/Entities/IHasMediaSources.cs @@ -1,17 +1,10 @@ using MediaBrowser.Model.Dto; -using System; using System.Collections.Generic; namespace MediaBrowser.Controller.Entities { - public interface IHasMediaSources + public interface IHasMediaSources : IHasId { - /// - /// Gets the identifier. - /// - /// The identifier. - Guid Id { get; } - /// /// Gets the media sources. /// diff --git a/MediaBrowser.Controller/Entities/IHasProgramAttributes.cs b/MediaBrowser.Controller/Entities/IHasProgramAttributes.cs index 1878d8d2c..391c8f7a7 100644 --- a/MediaBrowser.Controller/Entities/IHasProgramAttributes.cs +++ b/MediaBrowser.Controller/Entities/IHasProgramAttributes.cs @@ -1,9 +1,19 @@ - +using MediaBrowser.Model.LiveTv; +using System; + namespace MediaBrowser.Controller.Entities { public interface IHasProgramAttributes { bool IsMovie { get; set; } bool IsSports { get; set; } + bool IsNews { get; set; } + bool IsKids { get; set; } + bool IsRepeat { get; set; } + bool? IsHD { get; set; } + bool IsLive { get; set; } + bool IsPremiere { get; set; } + ProgramAudio? Audio { get; set; } + DateTime? OriginalAirDate { get; set; } } } diff --git a/MediaBrowser.Controller/Entities/IHasUserData.cs b/MediaBrowser.Controller/Entities/IHasUserData.cs index d576d90c4..34a820853 100644 --- a/MediaBrowser.Controller/Entities/IHasUserData.cs +++ b/MediaBrowser.Controller/Entities/IHasUserData.cs @@ -1,19 +1,12 @@ using MediaBrowser.Model.Dto; -using System; namespace MediaBrowser.Controller.Entities { /// /// Interface IHasUserData /// - public interface IHasUserData + public interface IHasUserData : IHasId { - /// - /// Gets or sets the identifier. - /// - /// The identifier. - Guid Id { get; set; } - /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs b/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs index 6c277a2e1..313675fb7 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvItem.cs @@ -1,10 +1,9 @@ -using System; +using MediaBrowser.Controller.Entities; namespace MediaBrowser.Controller.LiveTv { - public interface ILiveTvItem + public interface ILiveTvItem : IHasId { - Guid Id { get; } string ServiceName { get; set; } } } diff --git a/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs b/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs index 93e1e576a..1dd267c93 100644 --- a/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs +++ b/MediaBrowser.Controller/LiveTv/ILiveTvRecording.cs @@ -2,19 +2,21 @@ using MediaBrowser.Controller.Library; using MediaBrowser.Controller.Providers; using MediaBrowser.Model.Library; +using MediaBrowser.Model.LiveTv; +using System; using System.Threading; using System.Threading.Tasks; namespace MediaBrowser.Controller.LiveTv { - public interface ILiveTvRecording : IHasImages, IHasMediaSources, IHasUserData, ILiveTvItem + public interface ILiveTvRecording : IHasImages, IHasMediaSources, IHasUserData, ILiveTvItem, IHasStartDate, IHasProgramAttributes { + string ChannelId { get; } + string ProgramId { get; set; } string MediaType { get; } string Container { get; } - RecordingInfo RecordingInfo { get; set; } - long? RunTimeTicks { get; set; } string GetClientTypeName(); @@ -28,5 +30,17 @@ namespace MediaBrowser.Controller.LiveTv bool CanDelete(); bool CanDelete(User user); + + string ProviderImagePath { get; set; } + + string ProviderImageUrl { get; set; } + + string ExternalId { get; set; } + string EpisodeTitle { get; set; } + bool IsSeries { get; set; } + string SeriesTimerId { get; set; } + RecordingStatus Status { get; set; } + DateTime? EndDate { get; set; } + ChannelType ChannelType { get; set; } } } diff --git a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs index 0dc296d5a..20bde7483 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs @@ -3,7 +3,9 @@ using MediaBrowser.Controller.Entities.Audio; using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Users; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; @@ -12,6 +14,27 @@ namespace MediaBrowser.Controller.LiveTv { public class LiveTvAudioRecording : Audio, ILiveTvRecording { + public string ExternalId { get; set; } + public string ProviderImagePath { get; set; } + public string ProviderImageUrl { get; set; } + public string EpisodeTitle { get; set; } + public bool IsSeries { get; set; } + public string SeriesTimerId { get; set; } + public DateTime StartDate { get; set; } + public RecordingStatus Status { get; set; } + public bool IsSports { get; set; } + public bool IsNews { get; set; } + public bool IsKids { get; set; } + public bool IsRepeat { get; set; } + public bool IsMovie { get; set; } + public bool? IsHD { get; set; } + public bool IsLive { get; set; } + public bool IsPremiere { get; set; } + public ChannelType ChannelType { get; set; } + public string ProgramId { get; set; } + public ProgramAudio? Audio { get; set; } + public DateTime? OriginalAirDate { get; set; } + /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs index 3669f9440..a9028989f 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs @@ -2,7 +2,9 @@ using MediaBrowser.Model.Configuration; using MediaBrowser.Model.Dto; using MediaBrowser.Model.Entities; +using MediaBrowser.Model.LiveTv; using MediaBrowser.Model.Users; +using System; using System.Collections.Generic; using System.Linq; using System.Runtime.Serialization; @@ -11,6 +13,27 @@ namespace MediaBrowser.Controller.LiveTv { public class LiveTvVideoRecording : Video, ILiveTvRecording { + public string ExternalId { get; set; } + public string ProviderImagePath { get; set; } + public string ProviderImageUrl { get; set; } + public string EpisodeTitle { get; set; } + public bool IsSeries { get; set; } + public string SeriesTimerId { get; set; } + public DateTime StartDate { get; set; } + public RecordingStatus Status { get; set; } + public bool IsSports { get; set; } + public bool IsNews { get; set; } + public bool IsKids { get; set; } + public bool IsRepeat { get; set; } + public bool IsMovie { get; set; } + public bool? IsHD { get; set; } + public bool IsLive { get; set; } + public bool IsPremiere { get; set; } + public ChannelType ChannelType { get; set; } + public string ProgramId { get; set; } + public ProgramAudio? Audio { get; set; } + public DateTime? OriginalAirDate { get; set; } + /// /// Gets the user data key. /// diff --git a/MediaBrowser.Controller/MediaBrowser.Controller.csproj b/MediaBrowser.Controller/MediaBrowser.Controller.csproj index e1a18164e..216f1cf81 100644 --- a/MediaBrowser.Controller/MediaBrowser.Controller.csproj +++ b/MediaBrowser.Controller/MediaBrowser.Controller.csproj @@ -142,6 +142,7 @@ + diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs index f24fe0019..72fea2c79 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvDtoService.cs @@ -290,7 +290,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv public Guid GetInternalRecordingId(string serviceName, string externalId) { - var name = serviceName + externalId + InternalVersionNumber; + var name = serviceName + externalId + InternalVersionNumber + "0"; return name.ToLower().GetMBId(typeof(ILiveTvRecording)); } diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 47e862b9f..e6dc268d5 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -53,6 +53,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv private readonly ConcurrentDictionary _openStreams = new ConcurrentDictionary(); + private readonly SemaphoreSlim _refreshRecordingsLock = new SemaphoreSlim(1, 1); + public LiveTvManager(IApplicationHost appHost, IServerConfigurationManager config, ILogger logger, IItemRepository itemRepo, IImageProcessor imageProcessor, IUserDataManager userDataManager, IDtoService dtoService, IUserManager userManager, ILibraryManager libraryManager, ITaskManager taskManager, ILocalizationManager localization, IJsonSerializer jsonSerializer, IProviderManager providerManager) { _config = config; @@ -359,8 +361,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv isVideo = !string.Equals(recording.MediaType, MediaType.Audio, StringComparison.OrdinalIgnoreCase); var service = GetService(recording); - _logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.RecordingInfo.Id); - info = await service.GetRecordingStream(recording.RecordingInfo.Id, null, cancellationToken).ConfigureAwait(false); + _logger.Info("Opening recording stream from {0}, external recording Id: {1}", service.Name, recording.ExternalId); + info = await service.GetRecordingStream(recording.ExternalId, null, cancellationToken).ConfigureAwait(false); info.RequiresClosing = true; if (info.RequiresClosing) @@ -618,7 +620,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return item; } - private async Task GetRecording(RecordingInfo info, string serviceName, CancellationToken cancellationToken) + private async Task CreateRecordingRecord(RecordingInfo info, string serviceName, CancellationToken cancellationToken) { var isNew = false; @@ -653,14 +655,36 @@ namespace MediaBrowser.Server.Implementations.LiveTv isNew = true; } + item.ChannelId = _tvDtoService.GetInternalChannelId(serviceName, info.ChannelId).ToString("N"); item.CommunityRating = info.CommunityRating; item.OfficialRating = info.OfficialRating; item.Overview = info.Overview; item.EndDate = info.EndDate; + item.Genres = info.Genres; var recording = (ILiveTvRecording)item; - recording.RecordingInfo = info; + recording.ProgramId = _tvDtoService.GetInternalProgramId(serviceName, info.ProgramId).ToString("N"); + recording.Audio = info.Audio; + recording.ChannelType = info.ChannelType; + recording.EndDate = info.EndDate; + recording.EpisodeTitle = info.EpisodeTitle; + recording.ProviderImagePath = info.ImagePath; + recording.ProviderImageUrl = info.ImageUrl; + recording.IsHD = info.IsHD; + recording.IsKids = info.IsKids; + recording.IsLive = info.IsLive; + recording.IsMovie = info.IsMovie; + recording.IsNews = info.IsNews; + recording.IsPremiere = info.IsPremiere; + recording.IsRepeat = info.IsRepeat; + recording.IsSeries = info.IsSeries; + recording.IsSports = info.IsSports; + recording.OriginalAirDate = info.OriginalAirDate; + recording.SeriesTimerId = info.SeriesTimerId; + recording.StartDate = info.StartDate; + recording.Status = info.Status; + recording.ServiceName = serviceName; var originalPath = item.Path; @@ -676,15 +700,18 @@ namespace MediaBrowser.Server.Implementations.LiveTv var pathChanged = !string.Equals(originalPath, item.Path); - await item.RefreshMetadata(new MetadataRefreshOptions + if (isNew) { - ForceSave = isNew || pathChanged - - }, cancellationToken); + await _libraryManager.CreateItem(item, cancellationToken).ConfigureAwait(false); + } + else if (pathChanged) + { + await _libraryManager.UpdateItem(item, ItemUpdateType.MetadataImport, cancellationToken).ConfigureAwait(false); + } - _libraryManager.RegisterItem(item); + _providerManager.QueueRefresh(item.Id, new MetadataRefreshOptions()); - return recording; + return item.Id; } public async Task GetProgram(string id, CancellationToken cancellationToken, User user = null) @@ -1006,8 +1033,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv progress.Report(100 * percent); } - await CleanDatabaseInternal(newChannelIdList, typeof(LiveTvChannel).Name, progress, cancellationToken).ConfigureAwait(false); - await CleanDatabaseInternal(newProgramIdList, typeof(LiveTvProgram).Name, progress, cancellationToken).ConfigureAwait(false); + await CleanDatabaseInternal(newChannelIdList, new[] { typeof(LiveTvChannel).Name }, progress, cancellationToken).ConfigureAwait(false); + await CleanDatabaseInternal(newProgramIdList, new[] { typeof(LiveTvProgram).Name }, progress, cancellationToken).ConfigureAwait(false); // Load these now which will prefetch metadata var dtoOptions = new DtoOptions(); @@ -1017,7 +1044,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv progress.Report(100); } - private async Task,List>> RefreshChannelsInternal(ILiveTvService service, IProgress progress, CancellationToken cancellationToken) + private async Task, List>> RefreshChannelsInternal(ILiveTvService service, IProgress progress, CancellationToken cancellationToken) { progress.Report(10); @@ -1103,14 +1130,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv } progress.Report(100); - return new Tuple,List>(channels, programs); + return new Tuple, List>(channels, programs); } - private async Task CleanDatabaseInternal(List currentIdList, string typeName, IProgress progress, CancellationToken cancellationToken) + private async Task CleanDatabaseInternal(List currentIdList, string[] validTypes, IProgress progress, CancellationToken cancellationToken) { var list = _itemRepo.GetItemIds(new InternalItemsQuery { - IncludeItemTypes = new[] { typeName } + IncludeItemTypes = validTypes }).Items.ToList(); @@ -1163,64 +1190,103 @@ namespace MediaBrowser.Server.Implementations.LiveTv return channels.Select(i => new Tuple(service.Name, i)); } - public async Task> GetInternalRecordings(RecordingQuery query, CancellationToken cancellationToken) + private DateTime _lastRecordingRefreshTime; + private async Task RefreshRecordings(CancellationToken cancellationToken) { - var tasks = _services.Select(async i => + const int cacheMinutes = 5; + + if ((DateTime.UtcNow - _lastRecordingRefreshTime).TotalMinutes < cacheMinutes) { - try + return; + } + + await _refreshRecordingsLock.WaitAsync(cancellationToken).ConfigureAwait(false); + + try + { + if ((DateTime.UtcNow - _lastRecordingRefreshTime).TotalMinutes < cacheMinutes) { - var recs = await i.GetRecordingsAsync(cancellationToken).ConfigureAwait(false); - return recs.Select(r => new Tuple(r, i)); + return; } - catch (Exception ex) + + var tasks = _services.Select(async i => { - _logger.ErrorException("Error getting recordings", ex); - return new List>(); - } - }); - var results = await Task.WhenAll(tasks).ConfigureAwait(false); - var recordings = results.SelectMany(i => i.ToList()); + try + { + var recs = await i.GetRecordingsAsync(cancellationToken).ConfigureAwait(false); + return recs.Select(r => new Tuple(r, i)); + } + catch (Exception ex) + { + _logger.ErrorException("Error getting recordings", ex); + return new List>(); + } + }); - var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); + var results = await Task.WhenAll(tasks).ConfigureAwait(false); + + var recordingTasks = results.SelectMany(i => i.ToList()).Select(i => CreateRecordingRecord(i.Item1, i.Item2.Name, cancellationToken)); + + var idList = await Task.WhenAll(recordingTasks).ConfigureAwait(false); + + CleanDatabaseInternal(idList.ToList(), new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name }, new Progress(), cancellationToken).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.UtcNow; + } + finally + { + _refreshRecordingsLock.Release(); + } + } + + public async Task> GetInternalRecordings(RecordingQuery query, CancellationToken cancellationToken) + { + var user = string.IsNullOrEmpty(query.UserId) ? null : _userManager.GetUserById(query.UserId); if (user != null && !IsLiveTvEnabled(user)) { - recordings = new List>(); + return new QueryResult(); } - if (!string.IsNullOrEmpty(query.ChannelId)) + await RefreshRecordings(cancellationToken).ConfigureAwait(false); + + var internalQuery = new InternalItemsQuery { - var guid = new Guid(query.ChannelId); + IncludeItemTypes = new[] { typeof(LiveTvVideoRecording).Name, typeof(LiveTvAudioRecording).Name } + }; - recordings = recordings - .Where(i => _tvDtoService.GetInternalChannelId(i.Item2.Name, i.Item1.ChannelId) == guid); + if (!string.IsNullOrEmpty(query.ChannelId)) + { + internalQuery.ChannelIds = new[] { query.ChannelId }; } + var queryResult = _libraryManager.GetItems(internalQuery); + IEnumerable recordings = queryResult.Items.Cast(); + if (!string.IsNullOrEmpty(query.Id)) { var guid = new Guid(query.Id); recordings = recordings - .Where(i => _tvDtoService.GetInternalRecordingId(i.Item2.Name, i.Item1.Id) == guid); + .Where(i => i.Id == guid); } if (!string.IsNullOrEmpty(query.GroupId)) { var guid = new Guid(query.GroupId); - recordings = recordings.Where(i => GetRecordingGroupIds(i.Item1).Contains(guid)); + recordings = recordings.Where(i => GetRecordingGroupIds(i).Contains(guid)); } if (query.IsInProgress.HasValue) { var val = query.IsInProgress.Value; - recordings = recordings.Where(i => (i.Item1.Status == RecordingStatus.InProgress) == val); + recordings = recordings.Where(i => (i.Status == RecordingStatus.InProgress) == val); } if (query.Status.HasValue) { var val = query.Status.Value; - recordings = recordings.Where(i => (i.Item1.Status == val)); + recordings = recordings.Where(i => (i.Status == val)); } if (!string.IsNullOrEmpty(query.SeriesTimerId)) @@ -1228,21 +1294,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv var guid = new Guid(query.SeriesTimerId); recordings = recordings - .Where(i => _tvDtoService.GetInternalSeriesTimerId(i.Item2.Name, i.Item1.SeriesTimerId) == guid); + .Where(i => _tvDtoService.GetInternalSeriesTimerId(i.ServiceName, i.SeriesTimerId) == guid); } - recordings = recordings.OrderByDescending(i => i.Item1.StartDate); - - IEnumerable entities = await GetEntities(recordings, cancellationToken).ConfigureAwait(false); - if (user != null) { var currentUser = user; - entities = entities.Where(i => i.IsParentalAllowed(currentUser)); + recordings = recordings.Where(i => i.IsParentalAllowed(currentUser)); } - var entityList = entities.ToList(); - entities = entityList; + recordings = recordings.OrderByDescending(i => i.StartDate); + + var entityList = recordings.ToList(); + IEnumerable entities = entityList; if (query.StartIndex.HasValue) { @@ -1270,7 +1334,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv dto.Id = _tvDtoService.GetInternalProgramId(service.Name, program.ExternalId).ToString("N"); - dto.ChannelId = channel.Id.ToString("N"); + dto.ChannelId = item.ChannelId; dto.StartDate = program.StartDate; dto.IsRepeat = program.IsRepeat; @@ -1303,16 +1367,16 @@ namespace MediaBrowser.Server.Implementations.LiveTv var recording = (ILiveTvRecording)item; var service = GetService(recording); - var channel = string.IsNullOrEmpty(recording.RecordingInfo.ChannelId) ? null : GetInternalChannel(_tvDtoService.GetInternalChannelId(service.Name, recording.RecordingInfo.ChannelId)); + var channel = string.IsNullOrWhiteSpace(recording.ChannelId) ? null : GetInternalChannel(recording.ChannelId); - var info = recording.RecordingInfo; + var info = recording; - dto.Id = _tvDtoService.GetInternalRecordingId(service.Name, info.Id).ToString("N"); + dto.Id = item.Id.ToString("N"); dto.SeriesTimerId = string.IsNullOrEmpty(info.SeriesTimerId) ? null : _tvDtoService.GetInternalSeriesTimerId(service.Name, info.SeriesTimerId).ToString("N"); - dto.ChannelId = _tvDtoService.GetInternalChannelId(service.Name, info.ChannelId).ToString("N"); + dto.ChannelId = item.ChannelId; dto.StartDate = info.StartDate; dto.RecordingStatus = info.Status; @@ -1344,11 +1408,11 @@ namespace MediaBrowser.Server.Implementations.LiveTv dto.MediaStreams = dto.MediaSources.SelectMany(i => i.MediaStreams).ToList(); } - if (info.Status == RecordingStatus.InProgress) + if (info.Status == RecordingStatus.InProgress && info.EndDate.HasValue) { var now = DateTime.UtcNow.Ticks; var start = info.StartDate.Ticks; - var end = info.EndDate.Ticks; + var end = info.EndDate.Value.Ticks; var pct = now - start; pct /= end; @@ -1356,10 +1420,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv dto.CompletionPercentage = pct; } - if (!string.IsNullOrEmpty(info.ProgramId)) - { - dto.ProgramId = _tvDtoService.GetInternalProgramId(service.Name, info.ProgramId).ToString("N"); - } + dto.ProgramId = info.ProgramId; if (channel != null) { @@ -1394,13 +1455,6 @@ namespace MediaBrowser.Server.Implementations.LiveTv }; } - private Task GetEntities(IEnumerable> recordings, CancellationToken cancellationToken) - { - var tasks = recordings.Select(i => GetRecording(i.Item1, i.Item2.Name, cancellationToken)); - - return Task.WhenAll(tasks); - } - public async Task> GetTimers(TimerQuery query, CancellationToken cancellationToken) { var tasks = _services.Select(async i => @@ -1468,7 +1522,8 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(recording.ServiceName); - await service.DeleteRecordingAsync(recording.RecordingInfo.Id, CancellationToken.None).ConfigureAwait(false); + await service.DeleteRecordingAsync(recording.ExternalId, CancellationToken.None).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } public async Task CancelTimer(string id) @@ -1483,6 +1538,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(timer.ServiceName); await service.CancelTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } public async Task CancelSeriesTimer(string id) @@ -1497,6 +1553,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(timer.ServiceName); await service.CancelSeriesTimerAsync(timer.ExternalId, CancellationToken.None).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } public async Task GetRecording(string id, DtoOptions options, CancellationToken cancellationToken, User user = null) @@ -1705,6 +1762,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv info.Priority = defaultValues.Priority; await service.CreateTimerAsync(info, cancellationToken).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } public async Task CreateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) @@ -1718,6 +1776,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv info.Priority = defaultValues.Priority; await service.CreateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } public async Task UpdateTimer(TimerInfoDto timer, CancellationToken cancellationToken) @@ -1727,6 +1786,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(timer.ServiceName); await service.UpdateTimerAsync(info, cancellationToken).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } public async Task UpdateSeriesTimer(SeriesTimerInfoDto timer, CancellationToken cancellationToken) @@ -1736,9 +1796,10 @@ namespace MediaBrowser.Server.Implementations.LiveTv var service = GetService(timer.ServiceName); await service.UpdateSeriesTimerAsync(info, cancellationToken).ConfigureAwait(false); + _lastRecordingRefreshTime = DateTime.MinValue; } - private IEnumerable GetRecordingGroupNames(RecordingInfo recording) + private IEnumerable GetRecordingGroupNames(ILiveTvRecording recording) { var list = new List(); @@ -1775,7 +1836,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv return list; } - private List GetRecordingGroupIds(RecordingInfo recording) + private List GetRecordingGroupIds(ILiveTvRecording recording) { return GetRecordingGroupNames(recording).Select(i => i.ToLower() .GetMD5()) @@ -1795,7 +1856,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv var groups = new List(); var series = recordings - .Where(i => i.RecordingInfo.IsSeries) + .Where(i => i.IsSeries) .ToLookup(i => i.Name, StringComparer.OrdinalIgnoreCase) .ToList(); @@ -1808,31 +1869,31 @@ namespace MediaBrowser.Server.Implementations.LiveTv groups.Add(new BaseItemDto { Name = "Kids", - RecordingCount = recordings.Count(i => i.RecordingInfo.IsKids) + RecordingCount = recordings.Count(i => i.IsKids) }); groups.Add(new BaseItemDto { Name = "Movies", - RecordingCount = recordings.Count(i => i.RecordingInfo.IsMovie) + RecordingCount = recordings.Count(i => i.IsMovie) }); groups.Add(new BaseItemDto { Name = "News", - RecordingCount = recordings.Count(i => i.RecordingInfo.IsNews) + RecordingCount = recordings.Count(i => i.IsNews) }); groups.Add(new BaseItemDto { Name = "Sports", - RecordingCount = recordings.Count(i => i.RecordingInfo.IsSports) + RecordingCount = recordings.Count(i => i.IsSports) }); groups.Add(new BaseItemDto { Name = "Others", - RecordingCount = recordings.Count(i => !i.RecordingInfo.IsSports && !i.RecordingInfo.IsNews && !i.RecordingInfo.IsMovie && !i.RecordingInfo.IsKids && !i.RecordingInfo.IsSeries) + RecordingCount = recordings.Count(i => !i.IsSports && !i.IsNews && !i.IsMovie && !i.IsKids && !i.IsSeries) }); groups = groups diff --git a/MediaBrowser.Server.Implementations/LiveTv/RecordingImageProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/RecordingImageProvider.cs index 710247da7..adf1e7516 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/RecordingImageProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/RecordingImageProvider.cs @@ -36,17 +36,17 @@ namespace MediaBrowser.Server.Implementations.LiveTv var imageResponse = new DynamicImageResponse(); - if (!string.IsNullOrEmpty(liveTvItem.RecordingInfo.ImagePath)) + if (!string.IsNullOrEmpty(liveTvItem.ProviderImagePath)) { - imageResponse.Path = liveTvItem.RecordingInfo.ImagePath; + imageResponse.Path = liveTvItem.ProviderImagePath; imageResponse.HasImage = true; } - else if (!string.IsNullOrEmpty(liveTvItem.RecordingInfo.ImageUrl)) + else if (!string.IsNullOrEmpty(liveTvItem.ProviderImageUrl)) { var options = new HttpRequestOptions { CancellationToken = cancellationToken, - Url = liveTvItem.RecordingInfo.ImageUrl + Url = liveTvItem.ProviderImageUrl }; var response = await _httpClient.GetResponse(options).ConfigureAwait(false); @@ -62,7 +62,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv _logger.Error("Provider did not return an image content type."); } } - else if (liveTvItem.RecordingInfo.HasImage ?? true) + else { var service = _liveTvManager.Services.FirstOrDefault(i => string.Equals(i.Name, liveTvItem.ServiceName, StringComparison.OrdinalIgnoreCase)); @@ -70,7 +70,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv { try { - var response = await service.GetRecordingImageAsync(liveTvItem.RecordingInfo.Id, cancellationToken).ConfigureAwait(false); + var response = await service.GetRecordingImageAsync(liveTvItem.ExternalId, cancellationToken).ConfigureAwait(false); if (response != null) { @@ -109,7 +109,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv if (liveTvItem != null) { - return !liveTvItem.HasImage(ImageType.Primary) && (liveTvItem.RecordingInfo.HasImage ?? true); + return !liveTvItem.HasImage(ImageType.Primary) && (!string.IsNullOrWhiteSpace(liveTvItem.ProviderImagePath) || !string.IsNullOrWhiteSpace(liveTvItem.ProviderImageUrl)); } return false; } diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 19aca1cf9..8b93c36a5 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -759,14 +759,17 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add("IsSports=@IsSports"); cmd.Parameters.Add(cmd, "@IsSports", DbType.Boolean).Value = query.IsSports; } - if (query.IncludeItemTypes.Length == 1) + + var includeTypes = query.IncludeItemTypes.SelectMany(MapIncludeItemTypes).ToArray(); + + if (includeTypes.Length == 1) { whereClauses.Add("type=@type"); - cmd.Parameters.Add(cmd, "@type", DbType.String).Value = MapIncludeItemType(query.IncludeItemTypes[0]); + cmd.Parameters.Add(cmd, "@type", DbType.String).Value = includeTypes[0]; } - if (query.IncludeItemTypes.Length > 1) + if (includeTypes.Length > 1) { - var inClause = string.Join(",", query.IncludeItemTypes.Select(i => "'" + MapIncludeItemType(i) + "'").ToArray()); + var inClause = string.Join(",", includeTypes.Select(i => "'" + i + "'").ToArray()); whereClauses.Add(string.Format("type in ({0})", inClause)); } if (query.ChannelIds.Length == 1) @@ -818,7 +821,7 @@ namespace MediaBrowser.Server.Implementations.Persistence { whereClauses.Add("(StartDate>@IsAiringDate OR EndDate < @IsAiringDate)"); cmd.Parameters.Add(cmd, "@IsAiringDate", DbType.Date).Value = DateTime.UtcNow; - } + } } if (addPaging) @@ -839,21 +842,24 @@ namespace MediaBrowser.Server.Implementations.Persistence } // Not crazy about having this all the way down here, but at least it's in one place - readonly Dictionary _types = new Dictionary(StringComparer.OrdinalIgnoreCase) + readonly Dictionary _types = new Dictionary(StringComparer.OrdinalIgnoreCase) { - {typeof(LiveTvProgram).Name, typeof(LiveTvProgram).FullName}, - {typeof(LiveTvChannel).Name, typeof(LiveTvChannel).FullName} + {typeof(LiveTvProgram).Name, new []{typeof(LiveTvProgram).FullName}}, + {typeof(LiveTvChannel).Name, new []{typeof(LiveTvChannel).FullName}}, + {typeof(LiveTvVideoRecording).Name, new []{typeof(LiveTvVideoRecording).FullName}}, + {typeof(LiveTvAudioRecording).Name, new []{typeof(LiveTvAudioRecording).FullName}}, + {"Recording", new []{typeof(LiveTvAudioRecording).FullName, typeof(LiveTvVideoRecording).FullName}} }; - private string MapIncludeItemType(string value) + private IEnumerable MapIncludeItemTypes(string value) { - string result; + string[] result; if (_types.TryGetValue(value, out result)) { return result; } - return value; + return new[] { value }; } public IEnumerable GetItemIdsOfType(Type type) diff --git a/MediaBrowser.Server.Implementations/Session/SessionManager.cs b/MediaBrowser.Server.Implementations/Session/SessionManager.cs index 1baaa952a..f657d5403 100644 --- a/MediaBrowser.Server.Implementations/Session/SessionManager.cs +++ b/MediaBrowser.Server.Implementations/Session/SessionManager.cs @@ -1528,16 +1528,16 @@ namespace MediaBrowser.Server.Implementations.Session } var recording = item as ILiveTvRecording; - if (recording != null && recording.RecordingInfo != null) + if (recording != null) { - if (recording.RecordingInfo.IsSeries) + if (recording.IsSeries) { - info.Name = recording.RecordingInfo.EpisodeTitle; - info.SeriesName = recording.RecordingInfo.Name; + info.Name = recording.EpisodeTitle; + info.SeriesName = recording.Name; if (string.IsNullOrWhiteSpace(info.Name)) { - info.Name = recording.RecordingInfo.Name; + info.Name = recording.Name; } } } diff --git a/Nuget/MediaBrowser.Common.Internal.nuspec b/Nuget/MediaBrowser.Common.Internal.nuspec index f2d46de3e..57c619976 100644 --- a/Nuget/MediaBrowser.Common.Internal.nuspec +++ b/Nuget/MediaBrowser.Common.Internal.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common.Internal - 3.0.622 + 3.0.624 MediaBrowser.Common.Internal Luke ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains common components shared by Emby Theater and Emby Server. Not intended for plugin developer consumption. Copyright © Emby 2013 - + diff --git a/Nuget/MediaBrowser.Common.nuspec b/Nuget/MediaBrowser.Common.nuspec index ab7d095f3..dcd913774 100644 --- a/Nuget/MediaBrowser.Common.nuspec +++ b/Nuget/MediaBrowser.Common.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Common - 3.0.622 + 3.0.624 MediaBrowser.Common Emby Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Model.Signed.nuspec b/Nuget/MediaBrowser.Model.Signed.nuspec index 67385bc3d..10cee8dc2 100644 --- a/Nuget/MediaBrowser.Model.Signed.nuspec +++ b/Nuget/MediaBrowser.Model.Signed.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Model.Signed - 3.0.622 + 3.0.624 MediaBrowser.Model - Signed Edition Emby Team ebr,Luke,scottisafool diff --git a/Nuget/MediaBrowser.Server.Core.nuspec b/Nuget/MediaBrowser.Server.Core.nuspec index e91b97464..d171dab17 100644 --- a/Nuget/MediaBrowser.Server.Core.nuspec +++ b/Nuget/MediaBrowser.Server.Core.nuspec @@ -2,7 +2,7 @@ MediaBrowser.Server.Core - 3.0.622 + 3.0.624 Media Browser.Server.Core Emby Team ebr,Luke,scottisafool @@ -12,7 +12,7 @@ Contains core components required to build plugins for Emby Server. Copyright © Emby 2013 - + -- cgit v1.2.3 From 08dbe39f9979ec94eeff1256acc21d798b1e6ad8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Mon, 1 Jun 2015 13:49:11 -0400 Subject: add IsKids column --- MediaBrowser.Controller/Entities/InternalItemsQuery.cs | 3 ++- .../Persistence/SqliteItemRepository.cs | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 4 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs') diff --git a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs index 245c11169..faa9bc875 100644 --- a/MediaBrowser.Controller/Entities/InternalItemsQuery.cs +++ b/MediaBrowser.Controller/Entities/InternalItemsQuery.cs @@ -81,7 +81,8 @@ namespace MediaBrowser.Controller.Entities public bool? IsMovie { get; set; } public bool? IsSports { get; set; } - + public bool? IsKids { get; set; } + public string[] ChannelIds { get; set; } public InternalItemsQuery() diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 8b93c36a5..09786e08c 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -134,6 +134,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(_logger, "TypedBaseItems", "ChannelId", "Text"); _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT"); _connection.AddColumn(_logger, "TypedBaseItems", "IsSports", "BIT"); + _connection.AddColumn(_logger, "TypedBaseItems", "IsKids", "BIT"); PrepareStatements(); @@ -152,7 +153,7 @@ namespace MediaBrowser.Server.Implementations.Persistence private void PrepareStatements() { _saveItemCommand = _connection.CreateCommand(); - _saveItemCommand.CommandText = "replace into TypedBaseItems (guid, type, data, StartDate, EndDate, ChannelId, IsMovie, IsSports) values (@1, @2, @3, @4, @5, @6, @7, @8)"; + _saveItemCommand.CommandText = "replace into TypedBaseItems (guid, type, data, StartDate, EndDate, ChannelId, IsKids, IsMovie, IsSports) values (@1, @2, @3, @4, @5, @6, @7, @8, @9)"; _saveItemCommand.Parameters.Add(_saveItemCommand, "@1"); _saveItemCommand.Parameters.Add(_saveItemCommand, "@2"); _saveItemCommand.Parameters.Add(_saveItemCommand, "@3"); @@ -161,6 +162,7 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.Parameters.Add(_saveItemCommand, "@6"); _saveItemCommand.Parameters.Add(_saveItemCommand, "@7"); _saveItemCommand.Parameters.Add(_saveItemCommand, "@8"); + _saveItemCommand.Parameters.Add(_saveItemCommand, "@9"); _deleteChildrenCommand = _connection.CreateCommand(); _deleteChildrenCommand.CommandText = "delete from ChildrenIds where ParentId=@ParentId"; @@ -247,13 +249,15 @@ namespace MediaBrowser.Server.Implementations.Persistence var hasProgramAttributes = item as IHasProgramAttributes; if (hasProgramAttributes != null) { - _saveItemCommand.GetParameter(6).Value = hasProgramAttributes.IsMovie; - _saveItemCommand.GetParameter(7).Value = hasProgramAttributes.IsSports; + _saveItemCommand.GetParameter(6).Value = hasProgramAttributes.IsKids; + _saveItemCommand.GetParameter(7).Value = hasProgramAttributes.IsMovie; + _saveItemCommand.GetParameter(8).Value = hasProgramAttributes.IsSports; } else { _saveItemCommand.GetParameter(6).Value = null; _saveItemCommand.GetParameter(7).Value = null; + _saveItemCommand.GetParameter(8).Value = null; } _saveItemCommand.Transaction = transaction; @@ -754,6 +758,11 @@ namespace MediaBrowser.Server.Implementations.Persistence whereClauses.Add("IsMovie=@IsMovie"); cmd.Parameters.Add(cmd, "@IsMovie", DbType.Boolean).Value = query.IsMovie; } + if (query.IsKids.HasValue) + { + whereClauses.Add("IsKids=@IsKids"); + cmd.Parameters.Add(cmd, "@IsKids", DbType.Boolean).Value = query.IsKids; + } if (query.IsSports.HasValue) { whereClauses.Add("IsSports=@IsSports"); -- cgit v1.2.3 From 92ce7c0fa84055dd90d33fe2fa5c1b78274047a8 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Tue, 2 Jun 2015 23:16:15 -0400 Subject: fix tv recording retrieval --- .../LiveTv/LiveTvAudioRecording.cs | 8 ++- .../LiveTv/LiveTvVideoRecording.cs | 8 ++- .../Persistence/SqliteItemRepository.cs | 62 ++++++++++++++-------- 3 files changed, 45 insertions(+), 33 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs') diff --git a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs index 20bde7483..3da12cd80 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvAudioRecording.cs @@ -43,16 +43,14 @@ namespace MediaBrowser.Controller.LiveTv { var name = GetClientTypeName(); - if (!string.IsNullOrEmpty(RecordingInfo.ProgramId)) + if (!string.IsNullOrEmpty(ProgramId)) { - return name + "-" + RecordingInfo.ProgramId; + return name + "-" + ProgramId; } - return name + "-" + RecordingInfo.Name + (RecordingInfo.EpisodeTitle ?? string.Empty); + return name + "-" + Name + (EpisodeTitle ?? string.Empty); } - public RecordingInfo RecordingInfo { get; set; } - public string ServiceName { get; set; } /// diff --git a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs index a9028989f..179c33d09 100644 --- a/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs +++ b/MediaBrowser.Controller/LiveTv/LiveTvVideoRecording.cs @@ -42,16 +42,14 @@ namespace MediaBrowser.Controller.LiveTv { var name = GetClientTypeName(); - if (!string.IsNullOrEmpty(RecordingInfo.ProgramId)) + if (!string.IsNullOrEmpty(ProgramId)) { - return name + "-" + RecordingInfo.ProgramId; + return name + "-" + ProgramId; } - return name + "-" + RecordingInfo.Name + (RecordingInfo.EpisodeTitle ?? string.Empty); + return name + "-" + Name + (EpisodeTitle ?? string.Empty); } - public RecordingInfo RecordingInfo { get; set; } - public string ServiceName { get; set; } [IgnoreDataMember] diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 09786e08c..9a013e2e7 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -135,6 +135,8 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT"); _connection.AddColumn(_logger, "TypedBaseItems", "IsSports", "BIT"); _connection.AddColumn(_logger, "TypedBaseItems", "IsKids", "BIT"); + _connection.AddColumn(_logger, "TypedBaseItems", "CommunityRating", "Float"); + _connection.AddColumn(_logger, "TypedBaseItems", "CustomRating", "Text"); PrepareStatements(); @@ -152,17 +154,26 @@ namespace MediaBrowser.Server.Implementations.Persistence /// private void PrepareStatements() { + var saveColumns = new List + { + "guid", + "type", + "data", + "StartDate", + "EndDate", + "ChannelId", + "IsKids", + "IsMovie", + "IsSports", + "CommunityRating", + "CustomRating" + }; _saveItemCommand = _connection.CreateCommand(); - _saveItemCommand.CommandText = "replace into TypedBaseItems (guid, type, data, StartDate, EndDate, ChannelId, IsKids, IsMovie, IsSports) values (@1, @2, @3, @4, @5, @6, @7, @8, @9)"; - _saveItemCommand.Parameters.Add(_saveItemCommand, "@1"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@2"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@3"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@4"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@5"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@6"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@7"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@8"); - _saveItemCommand.Parameters.Add(_saveItemCommand, "@9"); + _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11)"; + for (var i = 1; i <= saveColumns.Count; i++) + { + _saveItemCommand.Parameters.Add(_saveItemCommand, "@" + i.ToString(CultureInfo.InvariantCulture)); + } _deleteChildrenCommand = _connection.CreateCommand(); _deleteChildrenCommand.CommandText = "delete from ChildrenIds where ParentId=@ParentId"; @@ -229,37 +240,42 @@ namespace MediaBrowser.Server.Implementations.Persistence { cancellationToken.ThrowIfCancellationRequested(); - _saveItemCommand.GetParameter(0).Value = item.Id; - _saveItemCommand.GetParameter(1).Value = item.GetType().FullName; - _saveItemCommand.GetParameter(2).Value = _jsonSerializer.SerializeToBytes(item); + var index = 0; + + _saveItemCommand.GetParameter(index++).Value = item.Id; + _saveItemCommand.GetParameter(index++).Value = item.GetType().FullName; + _saveItemCommand.GetParameter(index++).Value = _jsonSerializer.SerializeToBytes(item); var hasStartDate = item as IHasStartDate; if (hasStartDate != null) { - _saveItemCommand.GetParameter(3).Value = hasStartDate.StartDate; + _saveItemCommand.GetParameter(index++).Value = hasStartDate.StartDate; } else { - _saveItemCommand.GetParameter(3).Value = null; + _saveItemCommand.GetParameter(index++).Value = null; } - _saveItemCommand.GetParameter(4).Value = item.EndDate; - _saveItemCommand.GetParameter(5).Value = item.ChannelId; + _saveItemCommand.GetParameter(index++).Value = item.EndDate; + _saveItemCommand.GetParameter(index++).Value = item.ChannelId; var hasProgramAttributes = item as IHasProgramAttributes; if (hasProgramAttributes != null) { - _saveItemCommand.GetParameter(6).Value = hasProgramAttributes.IsKids; - _saveItemCommand.GetParameter(7).Value = hasProgramAttributes.IsMovie; - _saveItemCommand.GetParameter(8).Value = hasProgramAttributes.IsSports; + _saveItemCommand.GetParameter(index++).Value = hasProgramAttributes.IsKids; + _saveItemCommand.GetParameter(index++).Value = hasProgramAttributes.IsMovie; + _saveItemCommand.GetParameter(index++).Value = hasProgramAttributes.IsSports; } else { - _saveItemCommand.GetParameter(6).Value = null; - _saveItemCommand.GetParameter(7).Value = null; - _saveItemCommand.GetParameter(8).Value = null; + _saveItemCommand.GetParameter(index++).Value = null; + _saveItemCommand.GetParameter(index++).Value = null; + _saveItemCommand.GetParameter(index++).Value = null; } + _saveItemCommand.GetParameter(index++).Value = item.CommunityRating; + _saveItemCommand.GetParameter(index++).Value = item.CustomRating; + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); -- cgit v1.2.3 From 00aa3b0de09a97c5eba2f46acf7a78c998d79f2b Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 5 Jun 2015 01:32:14 -0400 Subject: update connect --- MediaBrowser.Api/Playback/TranscodingThrottler.cs | 13 +++---------- .../HttpClientManager/HttpClientManager.cs | 17 ++++++++++++++--- .../Persistence/SqliteItemRepository.cs | 18 ++++++++++++++++-- .../MediaBrowser.WebDashboard.csproj | 3 +++ 4 files changed, 36 insertions(+), 15 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs') diff --git a/MediaBrowser.Api/Playback/TranscodingThrottler.cs b/MediaBrowser.Api/Playback/TranscodingThrottler.cs index f94d5d837..fec3dda86 100644 --- a/MediaBrowser.Api/Playback/TranscodingThrottler.cs +++ b/MediaBrowser.Api/Playback/TranscodingThrottler.cs @@ -42,14 +42,7 @@ namespace MediaBrowser.Api.Playback var options = GetOptions(); - var threshold = options.ThrottleThresholdInSeconds; - - if (!options.EnableThrottling) - { - threshold *= 2; - } - - if (IsThrottleAllowed(_job, threshold)) + if (options.EnableThrottling && IsThrottleAllowed(_job, options.ThrottleThresholdInSeconds)) { PauseTranscoding(); } @@ -63,7 +56,7 @@ namespace MediaBrowser.Api.Playback { if (!_isPaused) { - //_logger.Debug("Sending pause command to ffmpeg"); + _logger.Debug("Sending pause command to ffmpeg"); try { @@ -81,7 +74,7 @@ namespace MediaBrowser.Api.Playback { if (_isPaused) { - //_logger.Debug("Sending unpause command to ffmpeg"); + _logger.Debug("Sending unpause command to ffmpeg"); try { diff --git a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs index 94c91c55a..b3a7f70bd 100644 --- a/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/MediaBrowser.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -723,9 +723,20 @@ namespace MediaBrowser.Common.Implementations.HttpClientManager /// System.String. private string GetHostFromUrl(string url) { - var start = url.IndexOf("://", StringComparison.OrdinalIgnoreCase) + 3; - var len = url.IndexOf('/', start) - start; - return url.Substring(start, len); + var index = url.IndexOf("://", StringComparison.OrdinalIgnoreCase); + + if (index != -1) + { + url = url.Substring(index + 3); + var host = url.Split(new[] { '/' }, StringSplitOptions.RemoveEmptyEntries).FirstOrDefault(); + + if (!string.IsNullOrWhiteSpace(host)) + { + return host; + } + } + + return url; } /// diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 9a013e2e7..5e992d9db 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -137,6 +137,10 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.AddColumn(_logger, "TypedBaseItems", "IsKids", "BIT"); _connection.AddColumn(_logger, "TypedBaseItems", "CommunityRating", "Float"); _connection.AddColumn(_logger, "TypedBaseItems", "CustomRating", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "IndexNumber", "INT"); + _connection.AddColumn(_logger, "TypedBaseItems", "IsLocked", "BIT"); + _connection.AddColumn(_logger, "TypedBaseItems", "Name", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "OfficialRating", "Text"); PrepareStatements(); @@ -166,10 +170,14 @@ namespace MediaBrowser.Server.Implementations.Persistence "IsMovie", "IsSports", "CommunityRating", - "CustomRating" + "CustomRating", + "IndexNumber", + "IsLocked", + "Name", + "OfficialRating" }; _saveItemCommand = _connection.CreateCommand(); - _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11)"; + _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15)"; for (var i = 1; i <= saveColumns.Count; i++) { _saveItemCommand.Parameters.Add(_saveItemCommand, "@" + i.ToString(CultureInfo.InvariantCulture)); @@ -276,6 +284,12 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.CommunityRating; _saveItemCommand.GetParameter(index++).Value = item.CustomRating; + _saveItemCommand.GetParameter(index++).Value = item.IndexNumber; + _saveItemCommand.GetParameter(index++).Value = item.IsLocked; + + _saveItemCommand.GetParameter(index++).Value = item.Name; + _saveItemCommand.GetParameter(index++).Value = item.OfficialRating; + _saveItemCommand.Transaction = transaction; _saveItemCommand.ExecuteNonQuery(); diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 48cd3f234..92a3f5c16 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -126,6 +126,9 @@ PreserveNewest + + PreserveNewest + PreserveNewest -- cgit v1.2.3 From 716b82ecc58f91870fed15bc8fb47ad342585b91 Mon Sep 17 00:00:00 2001 From: Luke Date: Sun, 7 Jun 2015 15:24:56 -0400 Subject: save paths into db --- .../Persistence/SqliteItemRepository.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs') diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index 5e992d9db..2f01af79b 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -129,7 +129,8 @@ namespace MediaBrowser.Server.Implementations.Persistence _connection.RunQueries(queries, _logger); - _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME"); + _connection.AddColumn(_logger, "TypedBaseItems", "Path", "Text"); + _connection.AddColumn(_logger, "TypedBaseItems", "StartDate", "DATETIME"); _connection.AddColumn(_logger, "TypedBaseItems", "EndDate", "DATETIME"); _connection.AddColumn(_logger, "TypedBaseItems", "ChannelId", "Text"); _connection.AddColumn(_logger, "TypedBaseItems", "IsMovie", "BIT"); @@ -163,6 +164,7 @@ namespace MediaBrowser.Server.Implementations.Persistence "guid", "type", "data", + "Path", "StartDate", "EndDate", "ChannelId", @@ -177,7 +179,7 @@ namespace MediaBrowser.Server.Implementations.Persistence "OfficialRating" }; _saveItemCommand = _connection.CreateCommand(); - _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15)"; + _saveItemCommand.CommandText = "replace into TypedBaseItems (" + string.Join(",", saveColumns.ToArray()) + ") values (@1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14, @15, @16)"; for (var i = 1; i <= saveColumns.Count; i++) { _saveItemCommand.Parameters.Add(_saveItemCommand, "@" + i.ToString(CultureInfo.InvariantCulture)); @@ -254,7 +256,9 @@ namespace MediaBrowser.Server.Implementations.Persistence _saveItemCommand.GetParameter(index++).Value = item.GetType().FullName; _saveItemCommand.GetParameter(index++).Value = _jsonSerializer.SerializeToBytes(item); - var hasStartDate = item as IHasStartDate; + _saveItemCommand.GetParameter(index++).Value = item.Path; + + var hasStartDate = item as IHasStartDate; if (hasStartDate != null) { _saveItemCommand.GetParameter(index++).Value = hasStartDate.StartDate; -- cgit v1.2.3