diff --git a/MediaBrowser.Api/ItemUpdateService.cs b/MediaBrowser.Api/ItemUpdateService.cs index 79aaccfe80..b944a39b6a 100644 --- a/MediaBrowser.Api/ItemUpdateService.cs +++ b/MediaBrowser.Api/ItemUpdateService.cs @@ -70,26 +70,21 @@ namespace MediaBrowser.Api Cultures = _localizationManager.GetCultures().ToList() }; - var locationType = item.LocationType; - if (locationType == LocationType.FileSystem || - locationType == LocationType.Offline) + if (!item.IsVirtualItem && !(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName)) { - if (!(item is ICollectionFolder) && !(item is UserView) && !(item is AggregateFolder) && !(item is LiveTvChannel) && !(item is IItemByName)) + var inheritedContentType = _libraryManager.GetInheritedContentType(item); + var configuredContentType = _libraryManager.GetConfiguredContentType(item); + + if (string.IsNullOrWhiteSpace(inheritedContentType) || string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || !string.IsNullOrWhiteSpace(configuredContentType)) { - var inheritedContentType = _libraryManager.GetInheritedContentType(item); - var configuredContentType = _libraryManager.GetConfiguredContentType(item); + info.ContentTypeOptions = GetContentTypeOptions(true); + info.ContentType = configuredContentType; - if (string.IsNullOrWhiteSpace(inheritedContentType) || string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase) || !string.IsNullOrWhiteSpace(configuredContentType)) + if (string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) { - info.ContentTypeOptions = GetContentTypeOptions(true); - info.ContentType = configuredContentType; - - if (string.Equals(inheritedContentType, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) - { - info.ContentTypeOptions = info.ContentTypeOptions - .Where(i => string.IsNullOrWhiteSpace(i.Value) || string.Equals(i.Value, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) - .ToList(); - } + info.ContentTypeOptions = info.ContentTypeOptions + .Where(i => string.IsNullOrWhiteSpace(i.Value) || string.Equals(i.Value, CollectionType.TvShows, StringComparison.OrdinalIgnoreCase)) + .ToList(); } } } diff --git a/MediaBrowser.Providers/Manager/ImageSaver.cs b/MediaBrowser.Providers/Manager/ImageSaver.cs index 327c142078..465677efb6 100644 --- a/MediaBrowser.Providers/Manager/ImageSaver.cs +++ b/MediaBrowser.Providers/Manager/ImageSaver.cs @@ -278,7 +278,7 @@ namespace MediaBrowser.Providers.Manager /// IEnumerable{System.String}. private string[] GetSavePaths(IHasImages item, ImageType type, int? imageIndex, string mimeType, bool saveLocally) { - if (!saveLocally) + if (!saveLocally || (_config.Configuration.ImageSavingConvention == ImageSavingConvention.Legacy)) { return new[] { GetStandardSavePath(item, type, imageIndex, mimeType, saveLocally) }; } diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 883864156c..ffcf9f60fc 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -2791,6 +2791,31 @@ namespace MediaBrowser.Server.Implementations.Library } _fileSystem.CreateShortcut(lnk, path); + + RemoveContentTypeOverrides(path); + } + + private void RemoveContentTypeOverrides(string path) + { + var removeList = new List(); + + foreach (var contentType in ConfigurationManager.Configuration.ContentTypes) + { + if (string.Equals(path, contentType.Name, StringComparison.OrdinalIgnoreCase) + || _fileSystem.ContainsSubPath(path, contentType.Name)) + { + removeList.Add(contentType); + } + } + + if (removeList.Count > 0) + { + ConfigurationManager.Configuration.ContentTypes = ConfigurationManager.Configuration.ContentTypes + .Except(removeList) + .ToArray(); + + ConfigurationManager.SaveConfiguration(); + } } public void RemoveMediaPath(string virtualFolderName, string mediaPath) diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs index 2d2d18524a..8f56554f10 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EmbyTV.cs @@ -979,67 +979,57 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV var recordPath = GetRecordingPath(timer, info); var recordingStatus = RecordingStatus.New; + var isResourceOpen = false; + SemaphoreSlim semaphore = null; try { var result = await GetChannelStreamInternal(timer.ChannelId, null, CancellationToken.None).ConfigureAwait(false); + isResourceOpen = true; + semaphore = result.Item3; var mediaStreamInfo = result.Item1; - var isResourceOpen = true; - // Unfortunately due to the semaphore we have to have a nested try/finally - try - { - // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg - //await Task.Delay(3000, cancellationToken).ConfigureAwait(false); - - var recorder = await GetRecorder().ConfigureAwait(false); + // HDHR doesn't seem to release the tuner right away after first probing with ffmpeg + //await Task.Delay(3000, cancellationToken).ConfigureAwait(false); - recordPath = recorder.GetOutputPath(mediaStreamInfo, recordPath); - recordPath = EnsureFileUnique(recordPath, timer.Id); + var recorder = await GetRecorder().ConfigureAwait(false); - _libraryMonitor.ReportFileSystemChangeBeginning(recordPath); - _fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath)); - activeRecordingInfo.Path = recordPath; + recordPath = recorder.GetOutputPath(mediaStreamInfo, recordPath); + recordPath = EnsureFileUnique(recordPath, timer.Id); - var duration = recordingEndDate - DateTime.UtcNow; + _libraryMonitor.ReportFileSystemChangeBeginning(recordPath); + _fileSystem.CreateDirectory(Path.GetDirectoryName(recordPath)); + activeRecordingInfo.Path = recordPath; - _logger.Info("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture)); + var duration = recordingEndDate - DateTime.UtcNow; - _logger.Info("Writing file to path: " + recordPath); - _logger.Info("Opening recording stream from tuner provider"); + _logger.Info("Beginning recording. Will record for {0} minutes.", duration.TotalMinutes.ToString(CultureInfo.InvariantCulture)); - Action onStarted = () => - { - timer.Status = RecordingStatus.InProgress; - _timerProvider.AddOrUpdate(timer, false); - - result.Item3.Release(); - isResourceOpen = false; - }; + _logger.Info("Writing file to path: " + recordPath); + _logger.Info("Opening recording stream from tuner provider"); - var pathWithDuration = result.Item2.ApplyDuration(mediaStreamInfo.Path, duration); + Action onStarted = () => + { + timer.Status = RecordingStatus.InProgress; + _timerProvider.AddOrUpdate(timer, false); - // If it supports supplying duration via url - if (!string.Equals(pathWithDuration, mediaStreamInfo.Path, StringComparison.OrdinalIgnoreCase)) - { - mediaStreamInfo.Path = pathWithDuration; - mediaStreamInfo.RunTimeTicks = duration.Ticks; - } + result.Item3.Release(); + isResourceOpen = false; + }; - await recorder.Record(mediaStreamInfo, recordPath, duration, onStarted, cancellationToken).ConfigureAwait(false); + var pathWithDuration = result.Item2.ApplyDuration(mediaStreamInfo.Path, duration); - recordingStatus = RecordingStatus.Completed; - _logger.Info("Recording completed: {0}", recordPath); - } - finally + // If it supports supplying duration via url + if (!string.Equals(pathWithDuration, mediaStreamInfo.Path, StringComparison.OrdinalIgnoreCase)) { - if (isResourceOpen) - { - result.Item3.Release(); - } - - _libraryMonitor.ReportFileSystemChangeComplete(recordPath, true); + mediaStreamInfo.Path = pathWithDuration; + mediaStreamInfo.RunTimeTicks = duration.Ticks; } + + await recorder.Record(mediaStreamInfo, recordPath, duration, onStarted, cancellationToken).ConfigureAwait(false); + + recordingStatus = RecordingStatus.Completed; + _logger.Info("Recording completed: {0}", recordPath); } catch (OperationCanceledException) { @@ -1053,6 +1043,13 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } finally { + if (isResourceOpen && semaphore != null) + { + semaphore.Release(); + } + + _libraryMonitor.ReportFileSystemChangeComplete(recordPath, true); + ActiveRecordingInfo removed; _activeRecordings.TryRemove(timer.Id, out removed); } @@ -1060,10 +1057,9 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV if (recordingStatus == RecordingStatus.Completed) { timer.Status = RecordingStatus.Completed; - _timerProvider.AddOrUpdate(timer, false); + _timerProvider.Delete(timer); OnSuccessfulRecording(info.IsSeries, recordPath); - _timerProvider.Delete(timer); } else if (DateTime.UtcNow < timer.EndDate) { diff --git a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs index cad300fac3..21879f6f46 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/EmbyTV/EncodedRecorder.cs @@ -62,7 +62,14 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV } finally { - File.Delete(tempfile); + try + { + File.Delete(tempfile); + } + catch (Exception ex) + { + _logger.ErrorException("Error deleting recording temp file", ex); + } } } diff --git a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs index 14e4e1093a..4d24431e69 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/Listings/XmlTvListingsProvider.cs @@ -11,6 +11,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; using Emby.XmlTv.Classes; +using Emby.XmlTv.Entities; using MediaBrowser.Common.Extensions; using MediaBrowser.Common.Net; using MediaBrowser.Controller.Configuration; @@ -109,12 +110,12 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings return results.Select(p => new ProgramInfo() { ChannelId = p.ChannelId, - EndDate = p.EndDate, + EndDate = GetDate(p.EndDate), EpisodeNumber = p.Episode == null ? null : p.Episode.Episode, EpisodeTitle = p.Episode == null ? null : p.Episode.Title, Genres = p.Categories, Id = String.Format("{0}_{1:O}", p.ChannelId, p.StartDate), // Construct an id from the channel and start date, - StartDate = p.StartDate, + StartDate = GetDate(p.StartDate), Name = p.Title, Overview = p.Description, ShortOverview = p.Description, @@ -135,6 +136,15 @@ namespace MediaBrowser.Server.Implementations.LiveTv.Listings }); } + private DateTime GetDate(DateTime date) + { + if (date.Kind != DateTimeKind.Utc) + { + date = DateTime.SpecifyKind(date, DateTimeKind.Utc); + } + return date; + } + public async Task AddMetadata(ListingsProviderInfo info, List channels, CancellationToken cancellationToken) { // Add the channel image url diff --git a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs index 95ed2aac1a..8d361e6a06 100644 --- a/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs +++ b/MediaBrowser.Server.Implementations/LiveTv/LiveTvManager.cs @@ -656,7 +656,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv item.Audio = info.Audio; item.ChannelId = channel.Id.ToString("N"); item.CommunityRating = item.CommunityRating ?? info.CommunityRating; - item.EndDate = info.EndDate; + item.EpisodeTitle = info.EpisodeTitle; item.ExternalId = info.Id; item.Genres = info.Genres; @@ -673,7 +673,19 @@ namespace MediaBrowser.Server.Implementations.LiveTv item.OfficialRating = item.OfficialRating ?? info.OfficialRating; item.Overview = item.Overview ?? info.Overview; item.RunTimeTicks = (info.EndDate - info.StartDate).Ticks; + + if (item.StartDate != info.StartDate) + { + forceUpdate = true; + } item.StartDate = info.StartDate; + + if (item.EndDate != info.EndDate) + { + forceUpdate = true; + } + item.EndDate = info.EndDate; + item.HomePageUrl = info.HomePageUrl; item.ProductionYear = info.ProductionYear; diff --git a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs index f109b34d63..9338a87067 100644 --- a/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs +++ b/MediaBrowser.Server.Implementations/Persistence/SqliteItemRepository.cs @@ -160,8 +160,6 @@ namespace MediaBrowser.Server.Implementations.Persistence "create table if not exists UserDataKeys (ItemId GUID, UserDataKey TEXT Priority INT, PRIMARY KEY (ItemId, UserDataKey))", "create table if not exists ItemValues (ItemId GUID, Type INT, Value TEXT, CleanValue TEXT)", - //"create index if not exists idx_ItemValues on ItemValues(ItemId)", - "create index if not exists idx_ItemValues2 on ItemValues(ItemId,Type)", "create table if not exists ProviderIds (ItemId GUID, Name TEXT, Value TEXT, PRIMARY KEY (ItemId, Name))", // covering index @@ -321,6 +319,7 @@ namespace MediaBrowser.Server.Implementations.Persistence // items by name "create index if not exists idx_ItemValues6 on ItemValues(ItemId,Type,CleanValue)", + "create index if not exists idx_ItemValues7 on ItemValues(Type,CleanValue,ItemId)", // covering index "create index if not exists idx_UserDataKeys3 on UserDataKeys(ItemId,Priority,UserDataKey)" @@ -1776,9 +1775,9 @@ namespace MediaBrowser.Server.Implementations.Persistence return string.Empty; } - private string GetFromText() + private string GetFromText(string alias = "A") { - return " from TypedBaseItems A"; + return " from TypedBaseItems " + alias; } public List GetItemList(InternalItemsQuery query) @@ -3661,19 +3660,14 @@ namespace MediaBrowser.Server.Implementations.Persistence var typesToCount = query.IncludeItemTypes.ToList(); - if (typesToCount.Count == 0) - { - //typesToCount.Add("Item"); - } - - foreach (var type in typesToCount) + if (typesToCount.Count > 0) { - var itemCountColumnQuery = "Select Count(CleanValue) from ItemValues where ItemValues.CleanValue=CleanName AND Type=@ItemValueType AND ItemId in ("; - itemCountColumnQuery += "select guid" + GetFromText(); + var itemCountColumnQuery = "select group_concat(type, '|')" + GetFromText("B"); var typeSubQuery = new InternalItemsQuery(query.User) { ExcludeItemTypes = query.ExcludeItemTypes, + IncludeItemTypes = query.IncludeItemTypes, MediaTypes = query.MediaTypes, AncestorIds = query.AncestorIds, ExcludeItemIds = query.ExcludeItemIds, @@ -3682,15 +3676,9 @@ namespace MediaBrowser.Server.Implementations.Persistence ParentId = query.ParentId, IsPlayed = query.IsPlayed }; - if (string.Equals(type, "Item", StringComparison.OrdinalIgnoreCase)) - { - typeSubQuery.IncludeItemTypes = query.IncludeItemTypes; - } - else - { - typeSubQuery.IncludeItemTypes = new[] { type }; - } - var whereClauses = GetWhereClauses(typeSubQuery, cmd, type); + var whereClauses = GetWhereClauses(typeSubQuery, cmd, "itemTypes"); + + whereClauses.Add("guid in (select ItemId from ItemValues where ItemValues.CleanValue=A.CleanName AND Type=@ItemValueType)"); var typeWhereText = whereClauses.Count == 0 ? string.Empty : @@ -3698,11 +3686,9 @@ namespace MediaBrowser.Server.Implementations.Persistence itemCountColumnQuery += typeWhereText; - itemCountColumnQuery += ")"; + //itemCountColumnQuery += ")"; - var columnName = type + "Count"; - - itemCountColumns.Add(new Tuple(columnName, "(" + itemCountColumnQuery + ") as " + columnName)); + itemCountColumns.Add(new Tuple("itemTypes", "(" + itemCountColumnQuery + ") as itemTypes")); } var columns = _retriveItemColumns.ToList(); @@ -3731,7 +3717,15 @@ namespace MediaBrowser.Server.Implementations.Persistence " where " + string.Join(" AND ", innerWhereClauses.ToArray()); var whereText = " where Type=@SelectType"; - whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; + + if (typesToCount.Count == 0) + { + whereText += " And CleanName In (Select CleanValue from ItemValues where Type=@ItemValueType AND ItemId in (select guid from TypedBaseItems" + innerWhereText + "))"; + } + else + { + whereText += " And itemTypes not null"; + } var outerQuery = new InternalItemsQuery(query.User) { @@ -3812,6 +3806,8 @@ namespace MediaBrowser.Server.Implementations.Persistence ? (CommandBehavior.SequentialAccess | CommandBehavior.SingleResult) : CommandBehavior.SequentialAccess; + //Logger.Debug("GetItemValues: " + cmd.CommandText); + using (var reader = cmd.ExecuteReader(commandBehavior)) { LogQueryTime("GetItemValues", cmd, now); @@ -3830,7 +3826,7 @@ namespace MediaBrowser.Server.Implementations.Persistence var item = GetItem(reader); if (item != null) { - var countStartColumn = columns.Count - typesToCount.Count; + var countStartColumn = columns.Count - 1; list.Add(new Tuple(item, GetItemCounts(reader, countStartColumn, typesToCount))); } @@ -3861,35 +3857,54 @@ namespace MediaBrowser.Server.Implementations.Persistence { var counts = new ItemCounts(); - for (var i = 0; i < typesToCount.Count; i++) + if (typesToCount.Count == 0) + { + return counts; + } + + var typeString = reader.IsDBNull(countStartColumn) ? null : reader.GetString(countStartColumn); + + if (string.IsNullOrWhiteSpace(typeString)) { - var value = reader.GetInt32(countStartColumn + i); + return counts; + } - var type = typesToCount[i]; - if (string.Equals(type, "Series", StringComparison.OrdinalIgnoreCase)) + var allTypes = typeString.Split(new[] {'|'}, StringSplitOptions.RemoveEmptyEntries) + .ToLookup(i => i).ToList(); + + foreach (var type in allTypes) + { + var value = type.ToList().Count; + var typeName = type.Key; + + if (string.Equals(typeName, typeof(Series).FullName, StringComparison.OrdinalIgnoreCase)) { counts.SeriesCount = value; } - else if (string.Equals(type, "Episode", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(typeName, typeof(Episode).FullName, StringComparison.OrdinalIgnoreCase)) { counts.EpisodeCount = value; } - else if (string.Equals(type, "Movie", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(typeName, typeof(Movie).FullName, StringComparison.OrdinalIgnoreCase)) { counts.MovieCount = value; } - else if (string.Equals(type, "MusicAlbum", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(typeName, typeof(MusicAlbum).FullName, StringComparison.OrdinalIgnoreCase)) { counts.AlbumCount = value; } - else if (string.Equals(type, "Audio", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(typeName, typeof(Audio).FullName, StringComparison.OrdinalIgnoreCase)) { counts.SongCount = value; } - else if (string.Equals(type, "Game", StringComparison.OrdinalIgnoreCase)) + else if (string.Equals(typeName, typeof(Game).FullName, StringComparison.OrdinalIgnoreCase)) { counts.GameCount = value; } + else if (string.Equals(typeName, typeof(Trailer).FullName, StringComparison.OrdinalIgnoreCase)) + { + counts.TrailerCount = value; + } counts.ItemCount += value; } diff --git a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj index 4eae9975a1..2c42c18149 100644 --- a/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj +++ b/MediaBrowser.WebDashboard/MediaBrowser.WebDashboard.csproj @@ -353,9 +353,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -830,9 +827,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest @@ -1155,9 +1149,6 @@ PreserveNewest - - PreserveNewest - PreserveNewest