Working search

This commit is contained in:
Fishandchips321 2026-02-22 21:58:23 +00:00
parent 271cf1f407
commit 2a572e8bc4
15 changed files with 217 additions and 39 deletions

View file

@ -1,19 +1,20 @@
using JellyGlass.Models;
using JellyGlass.Models.JellyfinApi;
namespace JellyGlass.Services;
public class LibraryService : ILibraryService
{
private IClientService _serverService;
private IClientService _clientService;
public LibraryService(IClientService serverService)
{
_serverService = serverService;
_clientService = serverService;
}
public async Task<Library[]> GetLibraries()
{
var clients = await _serverService.GetJellyfinClients();
var clients = await _clientService.GetJellyfinClients();
var libraries = new Dictionary<string, Library>();
@ -21,7 +22,7 @@ public class LibraryService : ILibraryService
{
var clientLibraries = await client.GetInstanceLibraries();
foreach (var library in clientLibraries.Items)
foreach (var library in clientLibraries)
{
if (library.Name == "Collections" || library.Name == "Playlists")
{
@ -43,9 +44,73 @@ public class LibraryService : ILibraryService
return libraries.Values.ToArray();
}
public async Task<ItemDTO[]> GetItemsFromLibrary(string libraryName)
public async Task<Item> GetLibrary(string libraryName, string serverId)
{
throw new NotImplementedException();
var client = await _clientService.GetClientForServerId(serverId);
if (client == null)
{
throw new Exception($"Could not find client with ID of {serverId}");
}
var libraries = await client.GetInstanceLibraries();
foreach (var library in libraries)
{
if (library.Name == libraryName)
{
return library;
}
}
throw new Exception("Couldn't find library");
}
public async Task<ItemDTO[]> GetItemsFromLibrary(string libraryName, string serverId)
{
var client = await _clientService.GetClientForServerId(serverId);
var library = await GetLibrary(libraryName, serverId);
var items = await client.GetItemChildren(library.Id);
var dtos = new List<ItemDTO>();
foreach (var item in items)
{
dtos.Add(new ItemDTO(item, client.InstanceUrl));
}
return dtos.ToArray();
}
public async Task<Library[]> GetLibrariesFromServer(string serverId)
{
var client = await _clientService.GetClientForServerId(serverId);
var libraries = new Dictionary<string, Library>();
var clientLibraries = await client.GetInstanceLibraries();
foreach (var library in clientLibraries)
{
if (library.Name == "Collections" || library.Name == "Playlists")
{
continue;
}
if (!libraries.ContainsKey(library.Name))
{
libraries.Add(library.Name, new Library()
{
Name = library.Name,
ThumbnailUrl = $"{client.InstanceUrl}/Items/{library.Id}/Primary"
});
}
}
return libraries.Values.ToArray();
}
// public async Task<ItemDTO[]> GetChildrenFromItems(ItemDTO[] items)