aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-11-18 21:45:12 -0500
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-11-18 21:45:12 -0500
commitdc8c24ed2905934e1d715d8a36b05f01807371f3 (patch)
tree19df8bc97e70e5559e51e3bb4fdf43fd264b947e /MediaBrowser.Api
parent124754a04f1a85fc949e229e45bfd67e5ac6ff62 (diff)
get channel media info at runtime
Diffstat (limited to 'MediaBrowser.Api')
-rw-r--r--MediaBrowser.Api/Library/LibraryService.cs30
-rw-r--r--MediaBrowser.Api/MediaBrowser.Api.csproj1
-rw-r--r--MediaBrowser.Api/Playback/MediaInfoService.cs64
-rw-r--r--MediaBrowser.Api/Session/SessionsService.cs7
4 files changed, 99 insertions, 3 deletions
diff --git a/MediaBrowser.Api/Library/LibraryService.cs b/MediaBrowser.Api/Library/LibraryService.cs
index ec7b1f0b35..06d8e0478e 100644
--- a/MediaBrowser.Api/Library/LibraryService.cs
+++ b/MediaBrowser.Api/Library/LibraryService.cs
@@ -5,8 +5,10 @@ using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Entities.Movies;
using MediaBrowser.Controller.Entities.TV;
using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.LiveTv;
using MediaBrowser.Controller.Net;
using MediaBrowser.Controller.Persistence;
+using MediaBrowser.Controller.Playlists;
using MediaBrowser.Controller.Session;
using MediaBrowser.Model.Dto;
using MediaBrowser.Model.Entities;
@@ -146,7 +148,7 @@ namespace MediaBrowser.Api.Library
}
[Route("/Items/{Id}", "DELETE", Summary = "Deletes an item from the library and file system")]
- [Authenticated(Roles = "Delete")]
+ [Authenticated]
public class DeleteItem : IReturnVoid
{
[ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "DELETE")]
@@ -241,12 +243,13 @@ namespace MediaBrowser.Api.Library
private readonly IDtoService _dtoService;
private readonly IChannelManager _channelManager;
private readonly ISessionManager _sessionManager;
+ private readonly IAuthorizationContext _authContext;
/// <summary>
/// Initializes a new instance of the <see cref="LibraryService" /> class.
/// </summary>
public LibraryService(IItemRepository itemRepo, ILibraryManager libraryManager, IUserManager userManager,
- IDtoService dtoService, IUserDataManager userDataManager, IChannelManager channelManager, ISessionManager sessionManager)
+ IDtoService dtoService, IUserDataManager userDataManager, IChannelManager channelManager, ISessionManager sessionManager, IAuthorizationContext authContext)
{
_itemRepo = itemRepo;
_libraryManager = libraryManager;
@@ -255,6 +258,7 @@ namespace MediaBrowser.Api.Library
_userDataManager = userDataManager;
_channelManager = channelManager;
_sessionManager = sessionManager;
+ _authContext = authContext;
}
public object Get(GetMediaFolders request)
@@ -466,6 +470,28 @@ namespace MediaBrowser.Api.Library
{
var item = _libraryManager.GetItemById(request.Id);
+ var auth = _authContext.GetAuthorizationInfo(Request);
+ var user = _userManager.GetUserById(auth.UserId);
+
+ if (item is Playlist)
+ {
+ // For now this is allowed if user can see the playlist
+ }
+ else if (item is ILiveTvRecording)
+ {
+ if (!user.Configuration.EnableLiveTvManagement)
+ {
+ throw new UnauthorizedAccessException();
+ }
+ }
+ else
+ {
+ if (!user.Configuration.EnableContentDeletion)
+ {
+ throw new UnauthorizedAccessException();
+ }
+ }
+
var task = _libraryManager.DeleteItem(item);
Task.WaitAll(task);
diff --git a/MediaBrowser.Api/MediaBrowser.Api.csproj b/MediaBrowser.Api/MediaBrowser.Api.csproj
index bc6cba5b9f..dae3790990 100644
--- a/MediaBrowser.Api/MediaBrowser.Api.csproj
+++ b/MediaBrowser.Api/MediaBrowser.Api.csproj
@@ -79,6 +79,7 @@
<Compile Include="FilterService.cs" />
<Compile Include="Library\ChapterService.cs" />
<Compile Include="Playback\Hls\MpegDashService.cs" />
+ <Compile Include="Playback\MediaInfoService.cs" />
<Compile Include="PlaylistService.cs" />
<Compile Include="StartupWizardService.cs" />
<Compile Include="Subtitles\SubtitleService.cs" />
diff --git a/MediaBrowser.Api/Playback/MediaInfoService.cs b/MediaBrowser.Api/Playback/MediaInfoService.cs
new file mode 100644
index 0000000000..b9973df40b
--- /dev/null
+++ b/MediaBrowser.Api/Playback/MediaInfoService.cs
@@ -0,0 +1,64 @@
+using MediaBrowser.Controller.Channels;
+using MediaBrowser.Controller.Entities;
+using MediaBrowser.Controller.Library;
+using MediaBrowser.Controller.Net;
+using MediaBrowser.Model.Dto;
+using MediaBrowser.Model.MediaInfo;
+using ServiceStack;
+using System.Collections.Generic;
+using System.Linq;
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace MediaBrowser.Api.Playback
+{
+ [Route("/Items/{Id}/MediaInfo", "GET", Summary = "Gets live playback media info for an item")]
+ public class GetLiveMediaInfo : IReturn<LiveMediaInfoResult>
+ {
+ [ApiMember(Name = "Id", Description = "Item Id", IsRequired = true, DataType = "string", ParameterType = "path", Verb = "GET")]
+ public string Id { get; set; }
+
+ [ApiMember(Name = "UserId", Description = "User Id", IsRequired = true, DataType = "string", ParameterType = "query", Verb = "GET")]
+ public string UserId { get; set; }
+ }
+
+ [Authenticated]
+ public class MediaInfoService : BaseApiService
+ {
+ private readonly ILibraryManager _libraryManager;
+ private readonly IChannelManager _channelManager;
+ private readonly IUserManager _userManager;
+
+ public MediaInfoService(ILibraryManager libraryManager, IChannelManager channelManager, IUserManager userManager)
+ {
+ _libraryManager = libraryManager;
+ _channelManager = channelManager;
+ _userManager = userManager;
+ }
+
+ public async Task<object> Get(GetLiveMediaInfo request)
+ {
+ var item = _libraryManager.GetItemById(request.Id);
+ IEnumerable<MediaSourceInfo> mediaSources;
+
+ var channelItem = item as IChannelMediaItem;
+ var user = _userManager.GetUserById(request.UserId);
+
+ if (channelItem != null)
+ {
+ mediaSources = await _channelManager.GetChannelItemMediaSources(request.Id, true, CancellationToken.None)
+ .ConfigureAwait(false);
+ }
+ else
+ {
+ var hasMediaSources = (IHasMediaSources)item;
+ mediaSources = hasMediaSources.GetMediaSources(true, user);
+ }
+
+ return ToOptimizedResult(new LiveMediaInfoResult
+ {
+ MediaSources = mediaSources.ToList()
+ });
+ }
+ }
+}
diff --git a/MediaBrowser.Api/Session/SessionsService.cs b/MediaBrowser.Api/Session/SessionsService.cs
index 4d68cbf393..7721107942 100644
--- a/MediaBrowser.Api/Session/SessionsService.cs
+++ b/MediaBrowser.Api/Session/SessionsService.cs
@@ -357,7 +357,12 @@ namespace MediaBrowser.Api.Session
if (!user.Configuration.EnableRemoteControlOfOtherUsers)
{
- result = result.Where(i => !i.UserId.HasValue || i.ContainsUser(request.ControllableByUserId.Value));
+ result = result.Where(i => i.ContainsUser(request.ControllableByUserId.Value));
+ }
+
+ if (!user.Configuration.EnableSharedDeviceControl)
+ {
+ result = result.Where(i => !i.UserId.HasValue);
}
}