mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-09-06 11:34:57 +02:00
commit
eebec1b98b
13 changed files with 201 additions and 67 deletions
|
@ -1,9 +1,14 @@
|
|||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Globalization;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Net;
|
||||
using MediaBrowser.Controller.Session;
|
||||
using MediaBrowser.Model.Connect;
|
||||
using MediaBrowser.Model.Dto;
|
||||
using MediaBrowser.Model.Session;
|
||||
using ServiceStack;
|
||||
|
||||
namespace MediaBrowser.Api
|
||||
|
@ -13,6 +18,8 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
[ApiMember(Name = "DeviceId", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||
public string DeviceId { get; set; }
|
||||
[ApiMember(Name = "AppName", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||
public string AppName { get; set; }
|
||||
}
|
||||
|
||||
[Route("/Auth/Pin", "GET", Summary = "Gets pin status")]
|
||||
|
@ -35,7 +42,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
[Route("/Auth/Pin/Validate", "POST", Summary = "Validates a pin")]
|
||||
[Authenticated]
|
||||
public class ValidatePinRequest : IReturnVoid
|
||||
public class ValidatePinRequest : IReturn<SessionInfoDto>
|
||||
{
|
||||
[ApiMember(Name = "Pin", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "POST")]
|
||||
public string Pin { get; set; }
|
||||
|
@ -43,10 +50,27 @@ namespace MediaBrowser.Api
|
|||
|
||||
public class PinLoginService : BaseApiService
|
||||
{
|
||||
private readonly ConcurrentDictionary<string, MyPinStatus> _activeRequests = new ConcurrentDictionary<string, MyPinStatus>(StringComparer.OrdinalIgnoreCase);
|
||||
private static readonly ConcurrentDictionary<string, MyPinStatus> _activeRequests = new ConcurrentDictionary<string, MyPinStatus>(StringComparer.OrdinalIgnoreCase);
|
||||
private readonly ISessionManager _sessionManager;
|
||||
private readonly IUserManager _userManager;
|
||||
|
||||
public PinLoginService(ISessionManager sessionManager, IUserManager userManager)
|
||||
{
|
||||
_sessionManager = sessionManager;
|
||||
_userManager = userManager;
|
||||
}
|
||||
|
||||
public object Post(CreatePinRequest request)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(request.DeviceId))
|
||||
{
|
||||
throw new ArgumentNullException("DeviceId");
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(request.AppName))
|
||||
{
|
||||
throw new ArgumentNullException("AppName");
|
||||
}
|
||||
|
||||
var pin = GetNewPin();
|
||||
|
||||
var value = new MyPinStatus
|
||||
|
@ -55,7 +79,8 @@ namespace MediaBrowser.Api
|
|||
IsConfirmed = false,
|
||||
IsExpired = false,
|
||||
Pin = pin,
|
||||
DeviceId = request.DeviceId
|
||||
DeviceId = request.DeviceId,
|
||||
AppName = request.AppName
|
||||
};
|
||||
|
||||
_activeRequests.AddOrUpdate(pin, value, (k, v) => value);
|
||||
|
@ -75,6 +100,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
if (!_activeRequests.TryGetValue(request.Pin, out status))
|
||||
{
|
||||
Logger.Debug("Pin {0} not found.", request.Pin);
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
|
@ -88,12 +114,13 @@ namespace MediaBrowser.Api
|
|||
});
|
||||
}
|
||||
|
||||
public object Post(ExchangePinRequest request)
|
||||
public async Task<object> Post(ExchangePinRequest request)
|
||||
{
|
||||
MyPinStatus status;
|
||||
|
||||
if (!_activeRequests.TryGetValue(request.Pin, out status))
|
||||
{
|
||||
Logger.Debug("Pin {0} not found.", request.Pin);
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
|
@ -104,14 +131,24 @@ namespace MediaBrowser.Api
|
|||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
return ToOptimizedResult(new PinExchangeResult
|
||||
var auth = AuthorizationContext.GetAuthorizationInfo(Request);
|
||||
var user = _userManager.GetUserById(status.UserId);
|
||||
|
||||
var result = await _sessionManager.CreateNewSession(new AuthenticationRequest
|
||||
{
|
||||
// TODO: Add access token
|
||||
UserId = status.UserId
|
||||
});
|
||||
App = auth.Client,
|
||||
AppVersion = auth.Version,
|
||||
DeviceId = auth.DeviceId,
|
||||
DeviceName = auth.Device,
|
||||
RemoteEndPoint = Request.RemoteIp,
|
||||
Username = user.Name
|
||||
|
||||
}).ConfigureAwait(false);
|
||||
|
||||
return ToOptimizedResult(result);
|
||||
}
|
||||
|
||||
public void Post(ValidatePinRequest request)
|
||||
public object Post(ValidatePinRequest request)
|
||||
{
|
||||
MyPinStatus status;
|
||||
|
||||
|
@ -124,12 +161,18 @@ namespace MediaBrowser.Api
|
|||
|
||||
status.IsConfirmed = true;
|
||||
status.UserId = AuthorizationContext.GetAuthorizationInfo(Request).UserId;
|
||||
|
||||
return ToOptimizedResult(new ValidatePinResult
|
||||
{
|
||||
AppName = status.AppName
|
||||
});
|
||||
}
|
||||
|
||||
private void EnsureValid(string requestedDeviceId, MyPinStatus status)
|
||||
{
|
||||
if (!string.Equals(requestedDeviceId, status.DeviceId, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
Logger.Debug("Pin device Id's do not match. requestedDeviceId: {0}, status.DeviceId: {1}", requestedDeviceId, status.DeviceId);
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
|
||||
|
@ -145,6 +188,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
if (status.IsExpired)
|
||||
{
|
||||
Logger.Debug("Pin {0} is expired", status.Pin);
|
||||
throw new ResourceNotFoundException();
|
||||
}
|
||||
}
|
||||
|
@ -163,16 +207,7 @@ namespace MediaBrowser.Api
|
|||
|
||||
private string GetNewPinInternal()
|
||||
{
|
||||
var length = 5;
|
||||
var pin = string.Empty;
|
||||
|
||||
while (pin.Length < length)
|
||||
{
|
||||
var digit = new Random().Next(0, 9);
|
||||
pin += digit.ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
return pin;
|
||||
return new Random().Next(10000, 99999).ToString(CultureInfo.InvariantCulture);
|
||||
}
|
||||
|
||||
private bool IsPinActive(string pin)
|
||||
|
@ -181,15 +216,15 @@ namespace MediaBrowser.Api
|
|||
|
||||
if (!_activeRequests.TryGetValue(pin, out status))
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (status.IsExpired)
|
||||
{
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
public class MyPinStatus : PinStatusResult
|
||||
|
@ -197,6 +232,12 @@ namespace MediaBrowser.Api
|
|||
public DateTime CreationTimeUtc { get; set; }
|
||||
public string DeviceId { get; set; }
|
||||
public string UserId { get; set; }
|
||||
public string AppName { get; set; }
|
||||
}
|
||||
}
|
||||
|
||||
public class ValidatePinResult
|
||||
{
|
||||
public string AppName { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -415,23 +415,6 @@ namespace MediaBrowser.Api
|
|||
{
|
||||
var auth = AuthorizationContext.GetAuthorizationInfo(Request);
|
||||
|
||||
if (string.IsNullOrWhiteSpace(auth.Client))
|
||||
{
|
||||
auth.Client = "Unknown app";
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(auth.Device))
|
||||
{
|
||||
auth.Device = "Unknown device";
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(auth.Version))
|
||||
{
|
||||
auth.Version = "Unknown version";
|
||||
}
|
||||
if (string.IsNullOrWhiteSpace(auth.DeviceId))
|
||||
{
|
||||
auth.DeviceId = "Unknown device id";
|
||||
}
|
||||
|
||||
var result = await _sessionMananger.AuthenticateNewSession(new AuthenticationRequest
|
||||
{
|
||||
App = auth.Client,
|
||||
|
|
|
@ -3,7 +3,7 @@ using System.Collections.Generic;
|
|||
|
||||
namespace MediaBrowser.Controller.Entities
|
||||
{
|
||||
public interface IHasMediaSources : IHasId
|
||||
public interface IHasMediaSources : IHasUserData
|
||||
{
|
||||
/// <summary>
|
||||
/// Gets the media sources.
|
||||
|
|
|
@ -78,6 +78,16 @@ namespace MediaBrowser.Controller.Entities
|
|||
/// </summary>
|
||||
/// <value><c>true</c> if played; otherwise, <c>false</c>.</value>
|
||||
public bool Played { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the index of the audio stream.
|
||||
/// </summary>
|
||||
/// <value>The index of the audio stream.</value>
|
||||
public int? AudioStreamIndex { get; set; }
|
||||
/// <summary>
|
||||
/// Gets or sets the index of the subtitle stream.
|
||||
/// </summary>
|
||||
/// <value>The index of the subtitle stream.</value>
|
||||
public int? SubtitleStreamIndex { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// This is an interpreted property to indicate likes or dislikes
|
||||
|
|
|
@ -250,6 +250,13 @@ namespace MediaBrowser.Controller.Session
|
|||
/// <returns>Task{SessionInfo}.</returns>
|
||||
Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the new session.
|
||||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>Task<AuthenticationResult>.</returns>
|
||||
Task<AuthenticationResult> CreateNewSession(AuthenticationRequest request);
|
||||
|
||||
/// <summary>
|
||||
/// Reports the capabilities.
|
||||
/// </summary>
|
||||
|
|
|
@ -639,6 +639,8 @@ namespace MediaBrowser.Server.Implementations.Dto
|
|||
private IEnumerable<string> GetCacheTags(BaseItem item, ImageType type, int limit)
|
||||
{
|
||||
return item.GetImages(type)
|
||||
// Convert to a list now in case GetImageCacheTag is slow
|
||||
.ToList()
|
||||
.Select(p => GetImageCacheTag(item, p))
|
||||
.Where(i => i != null)
|
||||
.Take(limit)
|
||||
|
|
|
@ -348,6 +348,12 @@ namespace MediaBrowser.Server.Implementations.HttpServer
|
|||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
if (string.Equals(localPath, "/emby/pin", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
httpRes.RedirectToUrl("web/pin.html");
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(GlobalResponse))
|
||||
{
|
||||
httpRes.StatusCode = 503;
|
||||
|
|
|
@ -30,8 +30,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
|
||||
private IMediaSourceProvider[] _providers;
|
||||
private readonly ILogger _logger;
|
||||
private readonly IUserDataManager _userDataManager;
|
||||
|
||||
public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem)
|
||||
public MediaSourceManager(IItemRepository itemRepo, IUserManager userManager, ILibraryManager libraryManager, ILogger logger, IJsonSerializer jsonSerializer, IFileSystem fileSystem, IUserDataManager userDataManager)
|
||||
{
|
||||
_itemRepo = itemRepo;
|
||||
_userManager = userManager;
|
||||
|
@ -39,6 +40,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
_logger = logger;
|
||||
_jsonSerializer = jsonSerializer;
|
||||
_fileSystem = fileSystem;
|
||||
_userDataManager = userDataManager;
|
||||
}
|
||||
|
||||
public void AddParts(IEnumerable<IMediaSourceProvider> providers)
|
||||
|
@ -140,7 +142,7 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
{
|
||||
if (user != null)
|
||||
{
|
||||
SetUserProperties(source, user);
|
||||
SetUserProperties(hasMediaSources, source, user);
|
||||
}
|
||||
if (source.Protocol == MediaProtocol.File)
|
||||
{
|
||||
|
@ -257,25 +259,38 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
{
|
||||
foreach (var source in sources)
|
||||
{
|
||||
SetUserProperties(source, user);
|
||||
SetUserProperties(item, source, user);
|
||||
}
|
||||
}
|
||||
|
||||
return sources;
|
||||
}
|
||||
|
||||
private void SetUserProperties(MediaSourceInfo source, User user)
|
||||
private void SetUserProperties(IHasUserData item, MediaSourceInfo source, User user)
|
||||
{
|
||||
var preferredAudio = string.IsNullOrEmpty(user.Configuration.AudioLanguagePreference)
|
||||
? new string[] { }
|
||||
: new[] { user.Configuration.AudioLanguagePreference };
|
||||
var userData = item == null ? new UserItemData() : _userDataManager.GetUserData(user.Id, item.GetUserDataKey());
|
||||
|
||||
SetDefaultAudioStreamIndex(source, userData, user);
|
||||
SetDefaultSubtitleStreamIndex(source, userData, user);
|
||||
}
|
||||
|
||||
private void SetDefaultSubtitleStreamIndex(MediaSourceInfo source, UserItemData userData, User user)
|
||||
{
|
||||
if (userData.SubtitleStreamIndex.HasValue)
|
||||
{
|
||||
var index = userData.SubtitleStreamIndex.Value;
|
||||
// Make sure the saved index is still valid
|
||||
if (index == -1 || source.MediaStreams.Any(i => i.Type == MediaStreamType.Subtitle && i.Index == index))
|
||||
{
|
||||
source.DefaultSubtitleStreamIndex = index;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var preferredSubs = string.IsNullOrEmpty(user.Configuration.SubtitleLanguagePreference)
|
||||
? new List<string> { }
|
||||
: new List<string> { user.Configuration.SubtitleLanguagePreference };
|
||||
|
||||
source.DefaultAudioStreamIndex = MediaStreamSelector.GetDefaultAudioStreamIndex(source.MediaStreams, preferredAudio, user.Configuration.PlayDefaultAudioTrack);
|
||||
|
||||
var defaultAudioIndex = source.DefaultAudioStreamIndex;
|
||||
var audioLangage = defaultAudioIndex == null
|
||||
? null
|
||||
|
@ -290,6 +305,26 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
user.Configuration.SubtitleMode, audioLangage);
|
||||
}
|
||||
|
||||
private void SetDefaultAudioStreamIndex(MediaSourceInfo source, UserItemData userData, User user)
|
||||
{
|
||||
if (userData.AudioStreamIndex.HasValue)
|
||||
{
|
||||
var index = userData.AudioStreamIndex.Value;
|
||||
// Make sure the saved index is still valid
|
||||
if (source.MediaStreams.Any(i => i.Type == MediaStreamType.Audio && i.Index == index))
|
||||
{
|
||||
source.DefaultAudioStreamIndex = index;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
var preferredAudio = string.IsNullOrEmpty(user.Configuration.AudioLanguagePreference)
|
||||
? new string[] { }
|
||||
: new[] { user.Configuration.AudioLanguagePreference };
|
||||
|
||||
source.DefaultAudioStreamIndex = MediaStreamSelector.GetDefaultAudioStreamIndex(source.MediaStreams, preferredAudio, user.Configuration.PlayDefaultAudioTrack);
|
||||
}
|
||||
|
||||
private IEnumerable<MediaSourceInfo> SortMediaSources(IEnumerable<MediaSourceInfo> sources)
|
||||
{
|
||||
return sources.OrderBy(i =>
|
||||
|
@ -353,7 +388,10 @@ namespace MediaBrowser.Server.Implementations.Library
|
|||
if (!string.IsNullOrWhiteSpace(request.UserId))
|
||||
{
|
||||
var user = _userManager.GetUserById(request.UserId);
|
||||
SetUserProperties(clone, user);
|
||||
var item = string.IsNullOrWhiteSpace(request.ItemId)
|
||||
? null
|
||||
: _libraryManager.GetItemById(request.ItemId);
|
||||
SetUserProperties(item, clone, user);
|
||||
}
|
||||
|
||||
return new LiveStreamResponse
|
||||
|
|
|
@ -143,7 +143,7 @@ namespace MediaBrowser.Server.Implementations.LiveTv.EmbyTV
|
|||
{
|
||||
audioChannels = audioStream.Channels ?? audioChannels;
|
||||
}
|
||||
return "-codec:a:0 aac -strict experimental -ab 320000 -ac " + audioChannels.ToString(CultureInfo.InvariantCulture);
|
||||
return "-codec:a:0 aac -strict experimental -ab 320000";
|
||||
}
|
||||
|
||||
private bool EncodeVideo(MediaSourceInfo mediaSource)
|
||||
|
|
|
@ -56,6 +56,9 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
};
|
||||
|
||||
_connection.RunQueries(queries, Logger);
|
||||
|
||||
_connection.AddColumn(Logger, "userdata", "AudioStreamIndex", "int");
|
||||
_connection.AddColumn(Logger, "userdata", "SubtitleStreamIndex", "int");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -127,7 +130,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate)";
|
||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = key;
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
@ -137,6 +140,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userData.IsFavorite;
|
||||
cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userData.PlaybackPositionTicks;
|
||||
cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userData.LastPlayedDate;
|
||||
cmd.Parameters.Add(cmd, "@AudioStreamIndex", DbType.Int32).Value = userData.AudioStreamIndex;
|
||||
cmd.Parameters.Add(cmd, "@SubtitleStreamIndex", DbType.Int32).Value = userData.SubtitleStreamIndex;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
|
@ -199,7 +204,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
{
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate)";
|
||||
cmd.CommandText = "replace into userdata (key, userId, rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex) values (@key, @userId, @rating,@played,@playCount,@isFavorite,@playbackPositionTicks,@lastPlayedDate,@AudioStreamIndex,@SubtitleStreamIndex)";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = userItemData.Key;
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
@ -209,6 +214,8 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
cmd.Parameters.Add(cmd, "@isFavorite", DbType.Boolean).Value = userItemData.IsFavorite;
|
||||
cmd.Parameters.Add(cmd, "@playbackPositionTicks", DbType.Int64).Value = userItemData.PlaybackPositionTicks;
|
||||
cmd.Parameters.Add(cmd, "@lastPlayedDate", DbType.DateTime).Value = userItemData.LastPlayedDate;
|
||||
cmd.Parameters.Add(cmd, "@AudioStreamIndex", DbType.Int32).Value = userItemData.AudioStreamIndex;
|
||||
cmd.Parameters.Add(cmd, "@SubtitleStreamIndex", DbType.Int32).Value = userItemData.SubtitleStreamIndex;
|
||||
|
||||
cmd.Transaction = transaction;
|
||||
|
||||
|
@ -275,7 +282,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate from userdata where key = @key and userId=@userId";
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where key = @key and userId=@userId";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@key", DbType.String).Value = key;
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
@ -310,7 +317,7 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
|
||||
using (var cmd = _connection.CreateCommand())
|
||||
{
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate from userdata where userId=@userId";
|
||||
cmd.CommandText = "select key,userid,rating,played,playCount,isFavorite,playbackPositionTicks,lastPlayedDate,AudioStreamIndex,SubtitleStreamIndex from userdata where userId=@userId";
|
||||
|
||||
cmd.Parameters.Add(cmd, "@userId", DbType.Guid).Value = userId;
|
||||
|
||||
|
@ -350,6 +357,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
|||
userData.LastPlayedDate = reader.GetDateTime(7).ToUniversalTime();
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(8))
|
||||
{
|
||||
userData.AudioStreamIndex = reader.GetInt32(8);
|
||||
}
|
||||
|
||||
if (!reader.IsDBNull(9))
|
||||
{
|
||||
userData.SubtitleStreamIndex = reader.GetInt32(9);
|
||||
}
|
||||
|
||||
return userData;
|
||||
}
|
||||
|
||||
|
|
|
@ -680,7 +680,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
foreach (var user in users)
|
||||
{
|
||||
await OnPlaybackProgress(user.Id, key, libraryItem, info.PositionTicks).ConfigureAwait(false);
|
||||
await OnPlaybackProgress(user.Id, key, libraryItem, info).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -712,18 +712,28 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
StartIdleCheckTimer();
|
||||
}
|
||||
|
||||
private async Task OnPlaybackProgress(Guid userId, string userDataKey, BaseItem item, long? positionTicks)
|
||||
private async Task OnPlaybackProgress(Guid userId, string userDataKey, BaseItem item, PlaybackProgressInfo info)
|
||||
{
|
||||
var data = _userDataRepository.GetUserData(userId, userDataKey);
|
||||
|
||||
var positionTicks = info.PositionTicks;
|
||||
|
||||
if (positionTicks.HasValue)
|
||||
{
|
||||
_userDataRepository.UpdatePlayState(item, data, positionTicks.Value);
|
||||
|
||||
UpdatePlaybackSettings(info, data);
|
||||
|
||||
await _userDataRepository.SaveUserData(userId, item, data, UserDataSaveReason.PlaybackProgress, CancellationToken.None).ConfigureAwait(false);
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdatePlaybackSettings(PlaybackProgressInfo info, UserItemData data)
|
||||
{
|
||||
data.AudioStreamIndex = info.AudioStreamIndex;
|
||||
data.SubtitleStreamIndex = info.SubtitleStreamIndex;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Used to report that playback has ended for an item
|
||||
/// </summary>
|
||||
|
@ -1268,7 +1278,17 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
/// </summary>
|
||||
/// <param name="request">The request.</param>
|
||||
/// <returns>Task{SessionInfo}.</returns>
|
||||
public async Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request)
|
||||
public Task<AuthenticationResult> AuthenticateNewSession(AuthenticationRequest request)
|
||||
{
|
||||
return AuthenticateNewSessionInternal(request, true);
|
||||
}
|
||||
|
||||
public Task<AuthenticationResult> CreateNewSession(AuthenticationRequest request)
|
||||
{
|
||||
return AuthenticateNewSessionInternal(request, false);
|
||||
}
|
||||
|
||||
private async Task<AuthenticationResult> AuthenticateNewSessionInternal(AuthenticationRequest request, bool enforcePassword)
|
||||
{
|
||||
var user = _userManager.Users
|
||||
.FirstOrDefault(i => string.Equals(request.Username, i.Name, StringComparison.OrdinalIgnoreCase));
|
||||
|
@ -1281,6 +1301,8 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
}
|
||||
}
|
||||
|
||||
if (enforcePassword)
|
||||
{
|
||||
var result = await _userManager.AuthenticateUser(request.Username, request.PasswordSha1, request.PasswordMd5, request.RemoteEndPoint).ConfigureAwait(false);
|
||||
|
||||
if (!result)
|
||||
|
@ -1289,6 +1311,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
|
||||
throw new SecurityException("Invalid user or password entered.");
|
||||
}
|
||||
}
|
||||
|
||||
var token = await GetAuthorizationToken(user.Id.ToString("N"), request.DeviceId, request.App, request.AppVersion, request.DeviceName).ConfigureAwait(false);
|
||||
|
||||
|
@ -1311,6 +1334,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
private async Task<string> GetAuthorizationToken(string userId, string deviceId, string app, string appVersion, string deviceName)
|
||||
{
|
||||
var existing = _authRepo.Get(new AuthenticationInfoQuery
|
||||
|
|
|
@ -490,7 +490,7 @@ namespace MediaBrowser.Server.Startup.Common
|
|||
ChannelManager = new ChannelManager(UserManager, DtoService, LibraryManager, LogManager.GetLogger("ChannelManager"), ServerConfigurationManager, FileSystemManager, UserDataManager, JsonSerializer, LocalizationManager, HttpClient, ProviderManager);
|
||||
RegisterSingleInstance(ChannelManager);
|
||||
|
||||
MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager);
|
||||
MediaSourceManager = new MediaSourceManager(ItemRepository, UserManager, LibraryManager, LogManager.GetLogger("MediaSourceManager"), JsonSerializer, FileSystemManager, UserDataManager);
|
||||
RegisterSingleInstance(MediaSourceManager);
|
||||
|
||||
SessionManager = new SessionManager(UserDataManager, LogManager.GetLogger("SessionManager"), UserRepository, LibraryManager, UserManager, musicManager, DtoService, ImageProcessor, JsonSerializer, this, HttpClient, AuthenticationRepository, DeviceManager, MediaSourceManager);
|
||||
|
|
|
@ -275,6 +275,9 @@
|
|||
<Content Include="dashboard-ui\mysyncsettings.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\pin.html">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\robots.txt">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
@ -317,6 +320,9 @@
|
|||
<Content Include="dashboard-ui\scripts\autoorganizesmart.js">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\scripts\pin.js">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
<Content Include="dashboard-ui\scripts\searchmenu.js">
|
||||
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
|
||||
</Content>
|
||||
|
|
Loading…
Reference in a new issue