From 450548828940b4b831f7510377c7eabd0add75a4 Mon Sep 17 00:00:00 2001 From: tidusjar Date: Thu, 1 Apr 2021 10:11:47 +0100 Subject: [PATCH] added the api to get libs --- src/Ombi.Api.Jellyfin/IJellyfinApi.cs | 1 + src/Ombi.Api.Jellyfin/JellyfinApi.cs | 16 +++++++++++++--- src/Ombi.Api.Jellyfin/Models/MediaFolders.cs | 10 ++++++++++ .../V1/External/JellyfinController.cs | 8 ++++++++ 4 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 src/Ombi.Api.Jellyfin/Models/MediaFolders.cs diff --git a/src/Ombi.Api.Jellyfin/IJellyfinApi.cs b/src/Ombi.Api.Jellyfin/IJellyfinApi.cs index 72d45877c..5dcf5741f 100644 --- a/src/Ombi.Api.Jellyfin/IJellyfinApi.cs +++ b/src/Ombi.Api.Jellyfin/IJellyfinApi.cs @@ -6,5 +6,6 @@ namespace Ombi.Api.Jellyfin public interface IJellyfinApi : IBaseJellyfinApi { Task LoginConnectUser(string username, string password); + Task> GetLibraries(string apiKey, string baseUrl); } } \ No newline at end of file diff --git a/src/Ombi.Api.Jellyfin/JellyfinApi.cs b/src/Ombi.Api.Jellyfin/JellyfinApi.cs index a8d94eca6..9ec6c8241 100644 --- a/src/Ombi.Api.Jellyfin/JellyfinApi.cs +++ b/src/Ombi.Api.Jellyfin/JellyfinApi.cs @@ -1,12 +1,12 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; +using System.Linq; using System.Net.Http; using System.Threading.Tasks; -using Microsoft.EntityFrameworkCore.Internal; using Newtonsoft.Json; using Ombi.Api.Jellyfin.Models; using Ombi.Api.Jellyfin.Models.Media.Tv; using Ombi.Api.Jellyfin.Models.Movie; -using Ombi.Helpers; namespace Ombi.Api.Jellyfin { @@ -87,6 +87,16 @@ namespace Ombi.Api.Jellyfin return await Api.Request>(request); } + public async Task> GetLibraries(string apiKey, string baseUrl) + { + var request = new Request("library/mediafolders", baseUrl, HttpMethod.Get); + AddHeaders(request, apiKey); + + var response = await Api.Request>(request); + response.Items = response.Items.Where(x => !x.CollectionType.Equals("playlists", StringComparison.InvariantCultureIgnoreCase)).ToList(); + return response; + } + public async Task> GetAllMovies(string apiKey, int startIndex, int count, string userId, string baseUri) { return await GetAll("Movie", apiKey, userId, baseUri, true, startIndex, count); diff --git a/src/Ombi.Api.Jellyfin/Models/MediaFolders.cs b/src/Ombi.Api.Jellyfin/Models/MediaFolders.cs new file mode 100644 index 000000000..caa9b6813 --- /dev/null +++ b/src/Ombi.Api.Jellyfin/Models/MediaFolders.cs @@ -0,0 +1,10 @@ +namespace Ombi.Api.Jellyfin.Models +{ + public class MediaFolders + { + public string Name { get; set; } + public string ServerId { get; set; } + public string Id { get; set; } + public string CollectionType { get; set; } + } +} diff --git a/src/Ombi/Controllers/V1/External/JellyfinController.cs b/src/Ombi/Controllers/V1/External/JellyfinController.cs index 27663a5b6..5e8b87414 100644 --- a/src/Ombi/Controllers/V1/External/JellyfinController.cs +++ b/src/Ombi/Controllers/V1/External/JellyfinController.cs @@ -66,6 +66,14 @@ namespace Ombi.Controllers.V1.External return result; } + [HttpPost("Library")] + public async Task> GetLibaries([FromBody] JellyfinServers server) + { + var client = await JellyfinApi.CreateClient(); + var result = await client.GetLibraries(server.ApiKey, server.FullUri); + return result; + } + /// /// Gets the jellyfin users. ///