mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-22 01:54:42 +01:00
fixes #555 - Have clients report seek and queuing capabilities
This commit is contained in:
@@ -237,7 +237,9 @@ namespace MediaBrowser.Server.Implementations.Dto
|
||||
NowViewingItemId = session.NowViewingItemId,
|
||||
NowViewingItemName = session.NowViewingItemName,
|
||||
NowViewingItemType = session.NowViewingItemType,
|
||||
ApplicationVersion = session.ApplicationVersion
|
||||
ApplicationVersion = session.ApplicationVersion,
|
||||
CanSeek = session.CanSeek,
|
||||
QueueableMediaTypes = session.QueueableMediaTypes
|
||||
};
|
||||
|
||||
if (session.NowPlayingItem != null)
|
||||
|
||||
@@ -829,10 +829,6 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
/// <returns>Task.</returns>
|
||||
public async Task ValidatePeople(CancellationToken cancellationToken, IProgress<double> progress)
|
||||
{
|
||||
const int maxTasks = 3;
|
||||
|
||||
var tasks = new List<Task>();
|
||||
|
||||
var people = RootFolder.RecursiveChildren
|
||||
.SelectMany(c => c.People)
|
||||
.DistinctBy(p => p.Name, StringComparer.OrdinalIgnoreCase)
|
||||
@@ -842,47 +838,27 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
|
||||
foreach (var person in people)
|
||||
{
|
||||
if (tasks.Count > maxTasks)
|
||||
{
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
tasks.Clear();
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
// Safe cancellation point, when there are no pending tasks
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
try
|
||||
{
|
||||
var item = GetPerson(person.Name);
|
||||
|
||||
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
_logger.ErrorException("Error validating IBN entry {0}", ex, person.Name);
|
||||
}
|
||||
|
||||
// Avoid accessing the foreach variable within the closure
|
||||
var currentPerson = person;
|
||||
// Update progress
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= people.Count;
|
||||
|
||||
tasks.Add(Task.Run(async () =>
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
|
||||
try
|
||||
{
|
||||
var item = GetPerson(currentPerson.Name);
|
||||
|
||||
await item.RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
_logger.ErrorException("Error validating IBN entry {0}", ex, currentPerson.Name);
|
||||
}
|
||||
|
||||
// Update progress
|
||||
lock (progress)
|
||||
{
|
||||
numComplete++;
|
||||
double percent = numComplete;
|
||||
percent /= people.Count;
|
||||
|
||||
progress.Report(100 * percent);
|
||||
}
|
||||
}));
|
||||
progress.Report(100 * percent);
|
||||
}
|
||||
|
||||
await Task.WhenAll(tasks).ConfigureAwait(false);
|
||||
|
||||
progress.Report(100);
|
||||
|
||||
_logger.Info("People validation complete");
|
||||
@@ -956,7 +932,9 @@ namespace MediaBrowser.Server.Implementations.Library
|
||||
public Task ValidateMediaLibrary(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
// Just run the scheduled task so that the user can see it
|
||||
return Task.Run(() => _taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>());
|
||||
_taskManager.CancelIfRunningAndQueue<RefreshMediaLibraryTask>();
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -41,7 +41,9 @@ namespace MediaBrowser.Server.Implementations.Library.Validators
|
||||
/// <returns>Task.</returns>
|
||||
public Task Run(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() => RunInternal(progress, cancellationToken));
|
||||
RunInternal(progress, cancellationToken);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
private void RunInternal(IProgress<double> progress, CancellationToken cancellationToken)
|
||||
|
||||
@@ -333,17 +333,16 @@ namespace MediaBrowser.Server.Implementations.Persistence
|
||||
/// <returns>Task.</returns>
|
||||
public Task SaveCriticReviews(Guid itemId, IEnumerable<ItemReview> criticReviews)
|
||||
{
|
||||
return Task.Run(() =>
|
||||
if (!Directory.Exists(_criticReviewsPath))
|
||||
{
|
||||
if (!Directory.Exists(_criticReviewsPath))
|
||||
{
|
||||
Directory.CreateDirectory(_criticReviewsPath);
|
||||
}
|
||||
Directory.CreateDirectory(_criticReviewsPath);
|
||||
}
|
||||
|
||||
var path = Path.Combine(_criticReviewsPath, itemId + ".json");
|
||||
var path = Path.Combine(_criticReviewsPath, itemId + ".json");
|
||||
|
||||
_jsonSerializer.SerializeToFile(criticReviews.ToList(), path);
|
||||
});
|
||||
_jsonSerializer.SerializeToFile(criticReviews.ToList(), path);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -207,21 +207,29 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
/// <summary>
|
||||
/// Used to report that playback has started for an item
|
||||
/// </summary>
|
||||
/// <param name="item">The item.</param>
|
||||
/// <param name="sessionId">The session id.</param>
|
||||
/// <param name="info">The info.</param>
|
||||
/// <returns>Task.</returns>
|
||||
/// <exception cref="System.ArgumentNullException"></exception>
|
||||
public async Task OnPlaybackStart(BaseItem item, Guid sessionId)
|
||||
/// <exception cref="System.ArgumentNullException">info</exception>
|
||||
public async Task OnPlaybackStart(PlaybackInfo info)
|
||||
{
|
||||
if (item == null)
|
||||
if (info == null)
|
||||
{
|
||||
throw new ArgumentNullException();
|
||||
throw new ArgumentNullException("info");
|
||||
}
|
||||
if (info.SessionId == Guid.Empty)
|
||||
{
|
||||
throw new ArgumentNullException("info");
|
||||
}
|
||||
|
||||
var session = Sessions.First(i => i.Id.Equals(sessionId));
|
||||
var session = Sessions.First(i => i.Id.Equals(info.SessionId));
|
||||
|
||||
var item = info.Item;
|
||||
|
||||
UpdateNowPlayingItem(session, item, false, false);
|
||||
|
||||
session.CanSeek = info.CanSeek;
|
||||
session.QueueableMediaTypes = info.QueueableMediaTypes;
|
||||
|
||||
var key = item.GetUserDataKey();
|
||||
|
||||
var user = session.User;
|
||||
|
||||
@@ -101,16 +101,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackStart", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
_logger.Debug("Received PlaybackStart message");
|
||||
|
||||
var session = _sessionManager.Sessions.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var item = _dtoService.GetItemByDtoId(message.Data);
|
||||
|
||||
_sessionManager.OnPlaybackStart(item, session.Id);
|
||||
}
|
||||
ReportPlaybackStart(message);
|
||||
}
|
||||
else if (string.Equals(message.MessageType, "PlaybackProgress", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
@@ -170,5 +161,46 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||
|
||||
return _trueTaskResult;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reports the playback start.
|
||||
/// </summary>
|
||||
/// <param name="message">The message.</param>
|
||||
private void ReportPlaybackStart(WebSocketMessageInfo message)
|
||||
{
|
||||
_logger.Debug("Received PlaybackStart message");
|
||||
|
||||
var session = _sessionManager.Sessions
|
||||
.FirstOrDefault(i => i.WebSockets.Contains(message.Connection));
|
||||
|
||||
if (session != null && session.User != null)
|
||||
{
|
||||
var vals = message.Data.Split('|');
|
||||
|
||||
var item = _dtoService.GetItemByDtoId(vals[0]);
|
||||
|
||||
var queueableMediaTypes = string.Empty;
|
||||
var canSeek = true;
|
||||
|
||||
if (vals.Length > 1)
|
||||
{
|
||||
canSeek = string.Equals(vals[1], "true", StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
if (vals.Length > 2)
|
||||
{
|
||||
queueableMediaTypes = vals[2];
|
||||
}
|
||||
|
||||
var info = new PlaybackInfo
|
||||
{
|
||||
CanSeek = canSeek,
|
||||
Item = item,
|
||||
SessionId = session.Id,
|
||||
QueueableMediaTypes = queueableMediaTypes.Split(',').ToList()
|
||||
};
|
||||
|
||||
_sessionManager.OnPlaybackStart(info);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,9 @@ namespace MediaBrowser.Server.Implementations.WebSocket
|
||||
/// <returns>Task.</returns>
|
||||
public Task SendAsync(byte[] bytes, WebSocketMessageType type, bool endOfMessage, CancellationToken cancellationToken)
|
||||
{
|
||||
return Task.Run(() => UserContext.Send(bytes));
|
||||
UserContext.Send(bytes);
|
||||
|
||||
return Task.FromResult(true);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user