From cf4adb84383d937db27c2052721417863908e2fd Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 18 May 2014 17:23:03 -0400 Subject: [PATCH] dlna fixes --- .../Playback/BaseStreamingService.cs | 20 +++---- MediaBrowser.Controller/Entities/BaseItem.cs | 7 +++ MediaBrowser.Model/Dlna/DeviceProfile.cs | 39 ------------- MediaBrowser.Model/Querying/ItemSortBy.cs | 1 + .../Channels/ChannelManager.cs | 5 +- ...MediaBrowser.Server.Implementations.csproj | 1 + .../Sorting/IsFavoriteOrLikeComparer.cs | 58 +++++++++++++++++++ 7 files changed, 80 insertions(+), 51 deletions(-) create mode 100644 MediaBrowser.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs diff --git a/MediaBrowser.Api/Playback/BaseStreamingService.cs b/MediaBrowser.Api/Playback/BaseStreamingService.cs index 8d07b10ce5..ef6c295500 100644 --- a/MediaBrowser.Api/Playback/BaseStreamingService.cs +++ b/MediaBrowser.Api/Playback/BaseStreamingService.cs @@ -1535,16 +1535,6 @@ namespace MediaBrowser.Api.Playback } } - var headers = new Dictionary(); - foreach (var key in Request.Headers.AllKeys) - { - headers[key] = Request.Headers[key]; - } - - state.DeviceProfile = string.IsNullOrWhiteSpace(state.Request.DeviceProfileId) ? - DlnaManager.GetProfile(headers) : - DlnaManager.GetProfile(state.Request.DeviceProfileId); - return state; } @@ -1669,6 +1659,16 @@ namespace MediaBrowser.Api.Playback private void ApplyDeviceProfileSettings(StreamState state) { + var headers = new Dictionary(); + foreach (var key in Request.Headers.AllKeys) + { + headers[key] = Request.Headers[key]; + } + + state.DeviceProfile = string.IsNullOrWhiteSpace(state.Request.DeviceProfileId) ? + DlnaManager.GetProfile(headers) : + DlnaManager.GetProfile(state.Request.DeviceProfileId); + var profile = state.DeviceProfile; if (profile == null) diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index 3a0b251eef..52c6e951ee 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -1501,6 +1501,13 @@ namespace MediaBrowser.Controller.Entities return userdata != null && userdata.Played; } + public bool IsFavoriteOrLiked(User user) + { + var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey()); + + return userdata != null && (userdata.IsFavorite || (userdata.Likes ?? false)); + } + public virtual bool IsUnplayed(User user) { var userdata = UserDataManager.GetUserData(user.Id, GetUserDataKey()); diff --git a/MediaBrowser.Model/Dlna/DeviceProfile.cs b/MediaBrowser.Model/Dlna/DeviceProfile.cs index 42ba5840cf..a3e217ef3a 100644 --- a/MediaBrowser.Model/Dlna/DeviceProfile.cs +++ b/MediaBrowser.Model/Dlna/DeviceProfile.cs @@ -318,44 +318,5 @@ namespace MediaBrowser.Model.Dlna } return null; } - - public ResponseProfile GetPhotoMediaProfile(string container, int? width, int? height) - { - container = (container ?? string.Empty).TrimStart('.'); - - foreach (var i in ResponseProfiles) - { - if (i.Type != DlnaProfileType.Photo) - { - continue; - } - - List containers = i.GetContainers().ToList(); - if (containers.Count > 0 && !containers.Contains(container, StringComparer.OrdinalIgnoreCase)) - { - continue; - } - - ConditionProcessor conditionProcessor = new ConditionProcessor(); - - var anyOff = false; - foreach (ProfileCondition c in i.Conditions) - { - if (!conditionProcessor.IsImageConditionSatisfied(c, width, height)) - { - anyOff = true; - break; - } - } - - if (anyOff) - { - continue; - } - - return i; - } - return null; - } } } diff --git a/MediaBrowser.Model/Querying/ItemSortBy.cs b/MediaBrowser.Model/Querying/ItemSortBy.cs index c91e0bafa8..14b80853ac 100644 --- a/MediaBrowser.Model/Querying/ItemSortBy.cs +++ b/MediaBrowser.Model/Querying/ItemSortBy.cs @@ -82,5 +82,6 @@ namespace MediaBrowser.Model.Querying public const string Studio = "Studio"; public const string Players = "Players"; public const string GameSystem = "GameSystem"; + public const string IsFavoriteOrLiked = "IsFavoriteOrLiked"; } } diff --git a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs index 538e6a0fdf..f1558e9dec 100644 --- a/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs +++ b/MediaBrowser.Server.Implementations/Channels/ChannelManager.cs @@ -162,8 +162,9 @@ namespace MediaBrowser.Server.Implementations.Channels var channelGuid = new Guid(item.ChannelId); var channel = _channelEntities.First(i => i.Id == channelGuid); + var internalChannel = _channels.First(i => string.Equals(i.Name, channel.OriginalChannelName, StringComparison.OrdinalIgnoreCase)); - var requiresCallback = channel as IRequiresMediaInfoCallback; + var requiresCallback = internalChannel as IRequiresMediaInfoCallback; if (requiresCallback != null) { @@ -403,7 +404,7 @@ namespace MediaBrowser.Server.Implementations.Channels private string GetIdToHash(string externalId) { // Increment this as needed to force new downloads - return externalId + "7"; + return externalId + "8"; } private async Task GetChannelItemEntity(ChannelItemInfo info, string internalChannnelId, CancellationToken cancellationToken) diff --git a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj index 2a1492c1f1..0bfaca1e4c 100644 --- a/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj +++ b/MediaBrowser.Server.Implementations/MediaBrowser.Server.Implementations.csproj @@ -227,6 +227,7 @@ + diff --git a/MediaBrowser.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs b/MediaBrowser.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs new file mode 100644 index 0000000000..658708dba5 --- /dev/null +++ b/MediaBrowser.Server.Implementations/Sorting/IsFavoriteOrLikeComparer.cs @@ -0,0 +1,58 @@ +using MediaBrowser.Controller.Entities; +using MediaBrowser.Controller.Library; +using MediaBrowser.Controller.Sorting; +using MediaBrowser.Model.Querying; + +namespace MediaBrowser.Server.Implementations.Sorting +{ + public class IsFavoriteOrLikeComparer : IUserBaseItemComparer + { + /// + /// Gets or sets the user. + /// + /// The user. + public User User { get; set; } + + /// + /// Compares the specified x. + /// + /// The x. + /// The y. + /// System.Int32. + public int Compare(BaseItem x, BaseItem y) + { + return GetValue(x).CompareTo(GetValue(y)); + } + + /// + /// Gets the date. + /// + /// The x. + /// DateTime. + private int GetValue(BaseItem x) + { + return x.IsFavoriteOrLiked(User) ? 0 : 1; + } + + /// + /// Gets the name. + /// + /// The name. + public string Name + { + get { return ItemSortBy.IsFavoriteOrLiked; } + } + + /// + /// Gets or sets the user data repository. + /// + /// The user data repository. + public IUserDataManager UserDataRepository { get; set; } + + /// + /// Gets or sets the user manager. + /// + /// The user manager. + public IUserManager UserManager { get; set; } + } +} \ No newline at end of file