mirror of https://github.com/ErsatzTV/ErsatzTV.git
Browse Source
* fix xmltv artwork for jf and emby * proxy jellyfin and emby artwork for xmltvpull/211/head
16 changed files with 348 additions and 19 deletions
@ -0,0 +1,4 @@ |
|||||||
|
namespace ErsatzTV.Application.Emby |
||||||
|
{ |
||||||
|
public record EmbyConnectionParametersViewModel(string Address); |
||||||
|
} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
using ErsatzTV.Core; |
||||||
|
using LanguageExt; |
||||||
|
using MediatR; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Emby.Queries |
||||||
|
{ |
||||||
|
public record GetEmbyConnectionParameters : IRequest<Either<BaseError, EmbyConnectionParametersViewModel>>; |
||||||
|
} |
||||||
@ -0,0 +1,73 @@ |
|||||||
|
using System; |
||||||
|
using System.Linq; |
||||||
|
using System.Threading; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using ErsatzTV.Core; |
||||||
|
using ErsatzTV.Core.Domain; |
||||||
|
using ErsatzTV.Core.Interfaces.Repositories; |
||||||
|
using LanguageExt; |
||||||
|
using MediatR; |
||||||
|
using Microsoft.Extensions.Caching.Memory; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Emby.Queries |
||||||
|
{ |
||||||
|
public class GetEmbyConnectionParametersHandler : IRequestHandler<GetEmbyConnectionParameters, |
||||||
|
Either<BaseError, EmbyConnectionParametersViewModel>> |
||||||
|
{ |
||||||
|
private readonly IMediaSourceRepository _mediaSourceRepository; |
||||||
|
private readonly IMemoryCache _memoryCache; |
||||||
|
|
||||||
|
public GetEmbyConnectionParametersHandler( |
||||||
|
IMemoryCache memoryCache, |
||||||
|
IMediaSourceRepository mediaSourceRepository) |
||||||
|
{ |
||||||
|
_memoryCache = memoryCache; |
||||||
|
_mediaSourceRepository = mediaSourceRepository; |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<Either<BaseError, EmbyConnectionParametersViewModel>> Handle( |
||||||
|
GetEmbyConnectionParameters request, |
||||||
|
CancellationToken cancellationToken) |
||||||
|
{ |
||||||
|
if (_memoryCache.TryGetValue(request, out EmbyConnectionParametersViewModel parameters)) |
||||||
|
{ |
||||||
|
return parameters; |
||||||
|
} |
||||||
|
|
||||||
|
Either<BaseError, EmbyConnectionParametersViewModel> maybeParameters = |
||||||
|
await Validate() |
||||||
|
.MapT(cp => new EmbyConnectionParametersViewModel(cp.ActiveConnection.Address)) |
||||||
|
.Map(v => v.ToEither<EmbyConnectionParametersViewModel>()); |
||||||
|
|
||||||
|
return maybeParameters.Match( |
||||||
|
p => |
||||||
|
{ |
||||||
|
_memoryCache.Set(request, p, TimeSpan.FromHours(1)); |
||||||
|
return maybeParameters; |
||||||
|
}, |
||||||
|
error => error); |
||||||
|
} |
||||||
|
|
||||||
|
private Task<Validation<BaseError, ConnectionParameters>> Validate() => |
||||||
|
EmbyMediaSourceMustExist() |
||||||
|
.BindT(MediaSourceMustHaveActiveConnection); |
||||||
|
|
||||||
|
private Task<Validation<BaseError, EmbyMediaSource>> EmbyMediaSourceMustExist() => |
||||||
|
_mediaSourceRepository.GetAllEmby().Map(list => list.HeadOrNone()) |
||||||
|
.Map( |
||||||
|
v => v.ToValidation<BaseError>( |
||||||
|
"Emby media source does not exist.")); |
||||||
|
|
||||||
|
private Validation<BaseError, ConnectionParameters> MediaSourceMustHaveActiveConnection( |
||||||
|
EmbyMediaSource embyMediaSource) |
||||||
|
{ |
||||||
|
Option<EmbyConnection> maybeConnection = embyMediaSource.Connections.FirstOrDefault(); |
||||||
|
return maybeConnection.Map(connection => new ConnectionParameters(embyMediaSource, connection)) |
||||||
|
.ToValidation<BaseError>("Emby media source requires an active connection"); |
||||||
|
} |
||||||
|
|
||||||
|
private record ConnectionParameters( |
||||||
|
EmbyMediaSource EmbyMediaSource, |
||||||
|
EmbyConnection ActiveConnection); |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,4 @@ |
|||||||
|
namespace ErsatzTV.Application.Jellyfin |
||||||
|
{ |
||||||
|
public record JellyfinConnectionParametersViewModel(string Address); |
||||||
|
} |
||||||
@ -0,0 +1,8 @@ |
|||||||
|
using ErsatzTV.Core; |
||||||
|
using LanguageExt; |
||||||
|
using MediatR; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Jellyfin.Queries |
||||||
|
{ |
||||||
|
public record GetJellyfinConnectionParameters : IRequest<Either<BaseError, JellyfinConnectionParametersViewModel>>; |
||||||
|
} |
||||||
@ -0,0 +1,73 @@ |
|||||||
|
using System; |
||||||
|
using System.Linq; |
||||||
|
using System.Threading; |
||||||
|
using System.Threading.Tasks; |
||||||
|
using ErsatzTV.Core; |
||||||
|
using ErsatzTV.Core.Domain; |
||||||
|
using ErsatzTV.Core.Interfaces.Repositories; |
||||||
|
using LanguageExt; |
||||||
|
using MediatR; |
||||||
|
using Microsoft.Extensions.Caching.Memory; |
||||||
|
|
||||||
|
namespace ErsatzTV.Application.Jellyfin.Queries |
||||||
|
{ |
||||||
|
public class GetJellyfinConnectionParametersHandler : IRequestHandler<GetJellyfinConnectionParameters, |
||||||
|
Either<BaseError, JellyfinConnectionParametersViewModel>> |
||||||
|
{ |
||||||
|
private readonly IMediaSourceRepository _mediaSourceRepository; |
||||||
|
private readonly IMemoryCache _memoryCache; |
||||||
|
|
||||||
|
public GetJellyfinConnectionParametersHandler( |
||||||
|
IMemoryCache memoryCache, |
||||||
|
IMediaSourceRepository mediaSourceRepository) |
||||||
|
{ |
||||||
|
_memoryCache = memoryCache; |
||||||
|
_mediaSourceRepository = mediaSourceRepository; |
||||||
|
} |
||||||
|
|
||||||
|
public async Task<Either<BaseError, JellyfinConnectionParametersViewModel>> Handle( |
||||||
|
GetJellyfinConnectionParameters request, |
||||||
|
CancellationToken cancellationToken) |
||||||
|
{ |
||||||
|
if (_memoryCache.TryGetValue(request, out JellyfinConnectionParametersViewModel parameters)) |
||||||
|
{ |
||||||
|
return parameters; |
||||||
|
} |
||||||
|
|
||||||
|
Either<BaseError, JellyfinConnectionParametersViewModel> maybeParameters = |
||||||
|
await Validate() |
||||||
|
.MapT(cp => new JellyfinConnectionParametersViewModel(cp.ActiveConnection.Address)) |
||||||
|
.Map(v => v.ToEither<JellyfinConnectionParametersViewModel>()); |
||||||
|
|
||||||
|
return maybeParameters.Match( |
||||||
|
p => |
||||||
|
{ |
||||||
|
_memoryCache.Set(request, p, TimeSpan.FromHours(1)); |
||||||
|
return maybeParameters; |
||||||
|
}, |
||||||
|
error => error); |
||||||
|
} |
||||||
|
|
||||||
|
private Task<Validation<BaseError, ConnectionParameters>> Validate() => |
||||||
|
JellyfinMediaSourceMustExist() |
||||||
|
.BindT(MediaSourceMustHaveActiveConnection); |
||||||
|
|
||||||
|
private Task<Validation<BaseError, JellyfinMediaSource>> JellyfinMediaSourceMustExist() => |
||||||
|
_mediaSourceRepository.GetAllJellyfin().Map(list => list.HeadOrNone()) |
||||||
|
.Map( |
||||||
|
v => v.ToValidation<BaseError>( |
||||||
|
"Jellyfin media source does not exist.")); |
||||||
|
|
||||||
|
private Validation<BaseError, ConnectionParameters> MediaSourceMustHaveActiveConnection( |
||||||
|
JellyfinMediaSource jellyfinMediaSource) |
||||||
|
{ |
||||||
|
Option<JellyfinConnection> maybeConnection = jellyfinMediaSource.Connections.FirstOrDefault(); |
||||||
|
return maybeConnection.Map(connection => new ConnectionParameters(jellyfinMediaSource, connection)) |
||||||
|
.ToValidation<BaseError>("Jellyfin media source requires an active connection"); |
||||||
|
} |
||||||
|
|
||||||
|
private record ConnectionParameters( |
||||||
|
JellyfinMediaSource JellyfinMediaSource, |
||||||
|
JellyfinConnection ActiveConnection); |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue