-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCatalogEndpoint.cs
More file actions
43 lines (38 loc) · 1.64 KB
/
CatalogEndpoint.cs
File metadata and controls
43 lines (38 loc) · 1.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using MediaBrowser.Controller.Net;
using MediaBrowser.Model.Services;
using StreamingCatalogs.Data;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
namespace StreamingCatalogs.Api
{
// Definiert die API-Route. Die Anfrage selbst benötigt keine Parameter.
[Route("/StreamingCatalogs/Catalogs", "GET", Summary = "Ruft alle zwischengespeicherten Streaming-Kataloge ab")]
public class GetCatalogs : IReturn<Dictionary<string, Dictionary<string, List<CatalogItem>>>>
{
}
// Die Implementierung des API-Dienstes
public class CatalogEndpoint : IService
{
// Die Methode wird für GET-Anfragen auf die oben definierte Route aufgerufen.
public async Task<object> Get(GetCatalogs request)
{
var plugin = Plugin.Instance;
if (plugin?.CacheService == null)
{
// Wenn der Cache-Service nicht bereit ist, ein leeres Objekt zurückgeben.
return new Dictionary<string, Dictionary<string, List<CatalogItem>>>();
}
var allItems = await plugin.CacheService.GetAllCachedItems();
// Gruppiert die Elemente zuerst nach Anbieter, dann nach Medientyp (Filme/Serien)
var grouped = allItems
.GroupBy(i => i.ProviderId)
.ToDictionary(
providerGroup => providerGroup.Key,
providerGroup => providerGroup
.GroupBy(i => i.MediaType)
.ToDictionary(mediaTypeGroup => mediaTypeGroup.Key, mediaTypeGroup => mediaTypeGroup.ToList()));
return grouped;
}
}
}