|
|
|
@ -15,6 +15,7 @@ namespace ErsatzTV.Infrastructure.Jellyfin; |
|
|
|
public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
private readonly IFallbackMetadataProvider _fallbackMetadataProvider; |
|
|
|
private readonly IFallbackMetadataProvider _fallbackMetadataProvider; |
|
|
|
|
|
|
|
private readonly IHttpClientFactory _httpClientFactory; |
|
|
|
private readonly IJellyfinPathReplacementService _jellyfinPathReplacementService; |
|
|
|
private readonly IJellyfinPathReplacementService _jellyfinPathReplacementService; |
|
|
|
private readonly ILogger<JellyfinApiClient> _logger; |
|
|
|
private readonly ILogger<JellyfinApiClient> _logger; |
|
|
|
private readonly IMemoryCache _memoryCache; |
|
|
|
private readonly IMemoryCache _memoryCache; |
|
|
|
@ -23,11 +24,13 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
IMemoryCache memoryCache, |
|
|
|
IMemoryCache memoryCache, |
|
|
|
IJellyfinPathReplacementService jellyfinPathReplacementService, |
|
|
|
IJellyfinPathReplacementService jellyfinPathReplacementService, |
|
|
|
IFallbackMetadataProvider fallbackMetadataProvider, |
|
|
|
IFallbackMetadataProvider fallbackMetadataProvider, |
|
|
|
|
|
|
|
IHttpClientFactory httpClientFactory, |
|
|
|
ILogger<JellyfinApiClient> logger) |
|
|
|
ILogger<JellyfinApiClient> logger) |
|
|
|
{ |
|
|
|
{ |
|
|
|
_memoryCache = memoryCache; |
|
|
|
_memoryCache = memoryCache; |
|
|
|
_jellyfinPathReplacementService = jellyfinPathReplacementService; |
|
|
|
_jellyfinPathReplacementService = jellyfinPathReplacementService; |
|
|
|
_fallbackMetadataProvider = fallbackMetadataProvider; |
|
|
|
_fallbackMetadataProvider = fallbackMetadataProvider; |
|
|
|
|
|
|
|
_httpClientFactory = httpClientFactory; |
|
|
|
_logger = logger; |
|
|
|
_logger = logger; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -37,7 +40,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
IJellyfinApi service = RestService.For<IJellyfinApi>(address); |
|
|
|
IJellyfinApi service = ServiceForAddress(address); |
|
|
|
var cts = new CancellationTokenSource(); |
|
|
|
var cts = new CancellationTokenSource(); |
|
|
|
cts.CancelAfter(TimeSpan.FromSeconds(5)); |
|
|
|
cts.CancelAfter(TimeSpan.FromSeconds(5)); |
|
|
|
return await service.GetSystemInformation(apiKey, cts.Token) |
|
|
|
return await service.GetSystemInformation(apiKey, cts.Token) |
|
|
|
@ -59,7 +62,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
IJellyfinApi service = RestService.For<IJellyfinApi>(address); |
|
|
|
IJellyfinApi service = ServiceForAddress(address); |
|
|
|
List<JellyfinLibraryResponse> libraries = await service.GetLibraries(apiKey); |
|
|
|
List<JellyfinLibraryResponse> libraries = await service.GetLibraries(apiKey); |
|
|
|
return libraries |
|
|
|
return libraries |
|
|
|
.Map(Project) |
|
|
|
.Map(Project) |
|
|
|
@ -189,7 +192,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
IJellyfinApi service = RestService.For<IJellyfinApi>(address); |
|
|
|
IJellyfinApi service = ServiceForAddress(address); |
|
|
|
JellyfinPlaybackInfoResponse playbackInfo = await service.GetPlaybackInfo(apiKey, itemId); |
|
|
|
JellyfinPlaybackInfoResponse playbackInfo = await service.GetPlaybackInfo(apiKey, itemId); |
|
|
|
Option<MediaVersion> maybeVersion = ProjectToMediaVersion(playbackInfo); |
|
|
|
Option<MediaVersion> maybeVersion = ProjectToMediaVersion(playbackInfo); |
|
|
|
return maybeVersion.ToEither(() => BaseError.New("Unable to locate Jellyfin statistics")); |
|
|
|
return maybeVersion.ToEither(() => BaseError.New("Unable to locate Jellyfin statistics")); |
|
|
|
@ -209,7 +212,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
IJellyfinApi service = RestService.For<IJellyfinApi>(address); |
|
|
|
IJellyfinApi service = ServiceForAddress(address); |
|
|
|
JellyfinLibraryItemsResponse itemsResponse = await service.GetShowLibraryItems( |
|
|
|
JellyfinLibraryItemsResponse itemsResponse = await service.GetShowLibraryItems( |
|
|
|
apiKey, |
|
|
|
apiKey, |
|
|
|
parentId: library.ItemId, |
|
|
|
parentId: library.ItemId, |
|
|
|
@ -240,7 +243,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
{ |
|
|
|
{ |
|
|
|
try |
|
|
|
try |
|
|
|
{ |
|
|
|
{ |
|
|
|
IJellyfinApi service = RestService.For<IJellyfinApi>(address); |
|
|
|
IJellyfinApi service = ServiceForAddress(address); |
|
|
|
JellyfinSearchHintsResponse searchResponse = await service.SearchHints( |
|
|
|
JellyfinSearchHintsResponse searchResponse = await service.SearchHints( |
|
|
|
apiKey, |
|
|
|
apiKey, |
|
|
|
showTitle, |
|
|
|
showTitle, |
|
|
|
@ -281,7 +284,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static async IAsyncEnumerable<Tuple<TItem, int>> GetPagedLibraryItems<TItem>( |
|
|
|
private async IAsyncEnumerable<Tuple<TItem, int>> GetPagedLibraryItems<TItem>( |
|
|
|
string address, |
|
|
|
string address, |
|
|
|
Option<JellyfinLibrary> maybeLibrary, |
|
|
|
Option<JellyfinLibrary> maybeLibrary, |
|
|
|
int mediaSourceId, |
|
|
|
int mediaSourceId, |
|
|
|
@ -289,7 +292,7 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
Func<IJellyfinApi, string, int, int, Task<JellyfinLibraryItemsResponse>> getItems, |
|
|
|
Func<IJellyfinApi, string, int, int, Task<JellyfinLibraryItemsResponse>> getItems, |
|
|
|
Func<Option<JellyfinLibrary>, JellyfinLibraryItemResponse, Option<TItem>> mapper) |
|
|
|
Func<Option<JellyfinLibrary>, JellyfinLibraryItemResponse, Option<TItem>> mapper) |
|
|
|
{ |
|
|
|
{ |
|
|
|
IJellyfinApi service = RestService.For<IJellyfinApi>(address); |
|
|
|
IJellyfinApi service = ServiceForAddress(address); |
|
|
|
|
|
|
|
|
|
|
|
const int PAGE_SIZE = 10; |
|
|
|
const int PAGE_SIZE = 10; |
|
|
|
|
|
|
|
|
|
|
|
@ -1043,4 +1046,11 @@ public class JellyfinApiClient : IJellyfinApiClient |
|
|
|
return version; |
|
|
|
return version; |
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IJellyfinApi ServiceForAddress(string address) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
var client = _httpClientFactory.CreateClient("RefitCustomClient"); |
|
|
|
|
|
|
|
client.BaseAddress = new Uri(address); |
|
|
|
|
|
|
|
return RestService.For<IJellyfinApi>(client); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|