diff --git a/src/Ombi.Api.Emby/EmbyApi.cs b/src/Ombi.Api.Emby/EmbyApi.cs index b24783e3c..c413ecded 100644 --- a/src/Ombi.Api.Emby/EmbyApi.cs +++ b/src/Ombi.Api.Emby/EmbyApi.cs @@ -115,13 +115,12 @@ namespace Ombi.Api.Emby return await Api.Request>(request); } - public async Task> GetLibraries(string apiKey, string baseUrl) + public async Task> GetLibraries(string apiKey, string baseUrl) { - var request = new Request("library/mediafolders", baseUrl, HttpMethod.Get); + var request = new Request("library/VirtualFolders", 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(); + var response = await Api.Request>(request); return response; } diff --git a/src/Ombi.Api.Emby/IEmbyApi.cs b/src/Ombi.Api.Emby/IEmbyApi.cs index 66c281de0..bbb03421e 100644 --- a/src/Ombi.Api.Emby/IEmbyApi.cs +++ b/src/Ombi.Api.Emby/IEmbyApi.cs @@ -1,4 +1,5 @@ -using System.Threading.Tasks; +using System.Collections.Generic; +using System.Threading.Tasks; using Ombi.Api.Emby.Models; using Ombi.Api.Emby.Models.Media; @@ -7,6 +8,6 @@ namespace Ombi.Api.Emby public interface IEmbyApi : IBaseEmbyApi { Task LoginConnectUser(string username, string password); - Task> GetLibraries(string apiKey, string baseUrl); + Task> GetLibraries(string apiKey, string baseUrl); } } \ No newline at end of file diff --git a/src/Ombi.Api.Emby/Models/LibraryVirtualFolders.cs b/src/Ombi.Api.Emby/Models/LibraryVirtualFolders.cs new file mode 100644 index 000000000..a75a655a2 --- /dev/null +++ b/src/Ombi.Api.Emby/Models/LibraryVirtualFolders.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace Ombi.Api.Emby.Models +{ + public class LibraryVirtualFolders + { + public string Name { get; set; } + public Libraryoptions LibraryOptions { get; set; } + public string ItemId { get; set; } + } + + public class Libraryoptions + { + public List TypeOptions { get; set; } = new List(); + } + + public class Typeoption + { + public string Type { get; set; } + } + +} diff --git a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs index 4d7e271d6..0630c0b28 100644 --- a/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs +++ b/src/Ombi.Schedule/Jobs/Emby/EmbyContentSync.cs @@ -95,6 +95,15 @@ namespace Ombi.Schedule.Jobs.Emby _logger.LogInformation($"Scanning Lib '{tvParentIdFilter.Title}'"); await ProcessTv(server, tvParentIdFilter.Key); } + + + var mixedLibs = server.EmbySelectedLibraries.Where(x => x.Enabled && x.CollectionType == "mixed"); + foreach (var m in mixedLibs) + { + _logger.LogInformation($"Scanning Lib '{m.Title}'"); + await ProcessTv(server, m.Key); + await ProcessMovies(server, m.Key); + } } else { diff --git a/src/Ombi/Controllers/V1/External/EmbyController.cs b/src/Ombi/Controllers/V1/External/EmbyController.cs index faed4bc2b..cc7c6fc47 100644 --- a/src/Ombi/Controllers/V1/External/EmbyController.cs +++ b/src/Ombi/Controllers/V1/External/EmbyController.cs @@ -98,7 +98,45 @@ namespace Ombi.Controllers.V1.External { var client = await EmbyApi.CreateClient(); var result = await client.GetLibraries(server.ApiKey, server.FullUri); - return result; + var mediaFolders = new EmbyItemContainer + { + TotalRecordCount = result.Count, + Items = new List() + }; + + foreach(var folder in result) + { + var toAdd = new MediaFolders + { + Name = folder.Name, + Id = folder.ItemId, + ServerId = server.ServerId + }; + + var types = folder?.LibraryOptions?.TypeOptions?.Select(x => x.Type); + + if (!types.Any()) + { + continue; + } + + if (types.Where(x => x.Equals("Movie", System.StringComparison.InvariantCultureIgnoreCase) + || x.Equals("Episode", System.StringComparison.InvariantCultureIgnoreCase)).Count() >= 2) + { + toAdd.CollectionType = "mixed"; + } + else if (types.Where(x => x.Equals("Movie", System.StringComparison.InvariantCultureIgnoreCase)).Any()) + { + toAdd.CollectionType = "movies"; + } + else if (types.Where(x => x.Equals("Episode", System.StringComparison.InvariantCultureIgnoreCase)).Any()) + { + toAdd.CollectionType = "tvshows"; + } + + mediaFolders.Items.Add(toAdd); + } + return mediaFolders; } } }