mirror of
https://github.com/jellyfin/jellyfin.git
synced 2024-07-11 08:10:34 +02:00
add shuffle and instant mix commands
This commit is contained in:
parent
0c32267717
commit
9f5101dee2
|
@ -39,14 +39,22 @@ namespace MediaBrowser.Model.Session
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The play now
|
/// The play now
|
||||||
/// </summary>
|
/// </summary>
|
||||||
PlayNow,
|
PlayNow = 0,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The play next
|
/// The play next
|
||||||
/// </summary>
|
/// </summary>
|
||||||
PlayNext,
|
PlayNext = 1,
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The play last
|
/// The play last
|
||||||
/// </summary>
|
/// </summary>
|
||||||
PlayLast
|
PlayLast = 2,
|
||||||
|
/// <summary>
|
||||||
|
/// The play instant mix
|
||||||
|
/// </summary>
|
||||||
|
PlayInstantMix = 3,
|
||||||
|
/// <summary>
|
||||||
|
/// The play shuffle
|
||||||
|
/// </summary>
|
||||||
|
PlayShuffle = 4
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -3,6 +3,8 @@ using MediaBrowser.Common.Extensions;
|
||||||
using MediaBrowser.Controller.Configuration;
|
using MediaBrowser.Controller.Configuration;
|
||||||
using MediaBrowser.Controller.Entities;
|
using MediaBrowser.Controller.Entities;
|
||||||
using MediaBrowser.Controller.Entities.Audio;
|
using MediaBrowser.Controller.Entities.Audio;
|
||||||
|
using MediaBrowser.Controller.Entities.Movies;
|
||||||
|
using MediaBrowser.Controller.Entities.TV;
|
||||||
using MediaBrowser.Controller.Library;
|
using MediaBrowser.Controller.Library;
|
||||||
using MediaBrowser.Controller.Persistence;
|
using MediaBrowser.Controller.Persistence;
|
||||||
using MediaBrowser.Controller.Session;
|
using MediaBrowser.Controller.Session;
|
||||||
|
@ -564,7 +566,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
|
|
||||||
return playedToCompletion;
|
return playedToCompletion;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Updates playstate position for an item but does not save
|
/// Updates playstate position for an item but does not save
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -666,7 +668,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
|
|
||||||
var controllingSession = GetSession(controllingSessionId);
|
var controllingSession = GetSession(controllingSessionId);
|
||||||
AssertCanControl(session, controllingSession);
|
AssertCanControl(session, controllingSession);
|
||||||
|
|
||||||
return session.SessionController.SendSystemCommand(command, cancellationToken);
|
return session.SessionController.SendSystemCommand(command, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -676,7 +678,7 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
|
|
||||||
var controllingSession = GetSession(controllingSessionId);
|
var controllingSession = GetSession(controllingSessionId);
|
||||||
AssertCanControl(session, controllingSession);
|
AssertCanControl(session, controllingSession);
|
||||||
|
|
||||||
return session.SessionController.SendMessageCommand(command, cancellationToken);
|
return session.SessionController.SendMessageCommand(command, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -684,14 +686,22 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
{
|
{
|
||||||
var session = GetSessionForRemoteControl(sessionId);
|
var session = GetSessionForRemoteControl(sessionId);
|
||||||
|
|
||||||
var items = command.ItemIds.Select(i => _libraryManager.GetItemById(new Guid(i)))
|
var user = session.UserId.HasValue ? _userManager.GetUserById(session.UserId.Value) : null;
|
||||||
|
|
||||||
|
var items = command.ItemIds.SelectMany(i => TranslateItemForPlayback(i, user))
|
||||||
.Where(i => i.LocationType != LocationType.Virtual)
|
.Where(i => i.LocationType != LocationType.Virtual)
|
||||||
.ToList();
|
.ToList();
|
||||||
|
|
||||||
if (session.UserId.HasValue)
|
if (command.PlayCommand == PlayCommand.PlayShuffle)
|
||||||
{
|
{
|
||||||
var user = _userManager.GetUserById(session.UserId.Value);
|
items = items.OrderBy(i => Guid.NewGuid()).ToList();
|
||||||
|
command.PlayCommand = PlayCommand.PlayNow;
|
||||||
|
}
|
||||||
|
|
||||||
|
command.ItemIds = items.Select(i => i.Id.ToString("N")).ToArray();
|
||||||
|
|
||||||
|
if (user != null)
|
||||||
|
{
|
||||||
if (items.Any(i => i.GetPlayAccess(user) != PlayAccess.Full))
|
if (items.Any(i => i.GetPlayAccess(user) != PlayAccess.Full))
|
||||||
{
|
{
|
||||||
throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name));
|
throw new ArgumentException(string.Format("{0} is not allowed to play media.", user.Name));
|
||||||
|
@ -723,13 +733,34 @@ namespace MediaBrowser.Server.Implementations.Session
|
||||||
return session.SessionController.SendPlayCommand(command, cancellationToken);
|
return session.SessionController.SendPlayCommand(command, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private IEnumerable<BaseItem> TranslateItemForPlayback(string id, User user)
|
||||||
|
{
|
||||||
|
var item = _libraryManager.GetItemById(new Guid(id));
|
||||||
|
|
||||||
|
if (item.IsFolder)
|
||||||
|
{
|
||||||
|
var folder = (Folder)item;
|
||||||
|
|
||||||
|
var items = user == null ? folder.RecursiveChildren:
|
||||||
|
folder.GetRecursiveChildren(user);
|
||||||
|
|
||||||
|
items = items.Where(i => !i.IsFolder);
|
||||||
|
|
||||||
|
items = items.OrderBy(i => i.SortName);
|
||||||
|
|
||||||
|
return items;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new[] { item };
|
||||||
|
}
|
||||||
|
|
||||||
public Task SendBrowseCommand(Guid controllingSessionId, Guid sessionId, BrowseRequest command, CancellationToken cancellationToken)
|
public Task SendBrowseCommand(Guid controllingSessionId, Guid sessionId, BrowseRequest command, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var session = GetSessionForRemoteControl(sessionId);
|
var session = GetSessionForRemoteControl(sessionId);
|
||||||
|
|
||||||
var controllingSession = GetSession(controllingSessionId);
|
var controllingSession = GetSession(controllingSessionId);
|
||||||
AssertCanControl(session, controllingSession);
|
AssertCanControl(session, controllingSession);
|
||||||
|
|
||||||
return session.SessionController.SendBrowseCommand(command, cancellationToken);
|
return session.SessionController.SendBrowseCommand(command, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue