@ -1,6 +1,7 @@
@@ -1,6 +1,7 @@
using System ;
using System.IO ;
using System.Net.Http ;
using System.Threading ;
using System.Threading.Tasks ;
using ErsatzTV.Application.Emby ;
using ErsatzTV.Application.Emby.Queries ;
@ -40,30 +41,30 @@ namespace ErsatzTV.Controllers
@@ -40,30 +41,30 @@ namespace ErsatzTV.Controllers
[HttpHead("/iptv/artwork/posters/{fileName}.jpg")]
[HttpGet("/iptv/artwork/posters/{fileName}.jpg")]
[HttpGet("/artwork/posters/{fileName}")]
public async Task < IActionResult > GetPoster ( string fileName )
public async Task < IActionResult > GetPoster ( string fileName , CancellationToken cancellationToken )
{
Either < BaseError , CachedImagePathViewModel > cachedImagePath =
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . Poster , 4 4 0 ) ) ;
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . Poster , 4 4 0 ) , cancellationToken ) ;
return cachedImagePath . Match < IActionResult > (
Left : _ = > new NotFoundResult ( ) ,
Right : r = > new PhysicalFileResult ( r . FileName , r . MimeType ) ) ;
}
[HttpGet("/artwork/watermarks/{fileName}")]
public async Task < IActionResult > GetWatermark ( string fileName )
public async Task < IActionResult > GetWatermark ( string fileName , CancellationToken cancellationToken )
{
Either < BaseError , CachedImagePathViewModel > cachedImagePath =
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . Watermark ) ) ;
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . Watermark ) , cancellationToken ) ;
return cachedImagePath . Match < IActionResult > (
Left : _ = > new NotFoundResult ( ) ,
Right : r = > new PhysicalFileResult ( r . FileName , r . MimeType ) ) ;
}
[HttpGet("/artwork/fanart/{fileName}")]
public async Task < IActionResult > GetFanArt ( string fileName )
public async Task < IActionResult > GetFanArt ( string fileName , CancellationToken cancellationToken )
{
Either < BaseError , CachedImagePathViewModel > cachedImagePath =
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . FanArt ) ) ;
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . FanArt ) , cancellationToken ) ;
return cachedImagePath . Match < IActionResult > (
Left : _ = > new NotFoundResult ( ) ,
Right : r = > new PhysicalFileResult ( r . FileName , r . MimeType ) ) ;
@ -77,14 +78,14 @@ namespace ErsatzTV.Controllers
@@ -77,14 +78,14 @@ namespace ErsatzTV.Controllers
[HttpGet("/iptv/artwork/thumbnails/jellyfin/{*path}")]
[HttpGet("/artwork/thumbnails/jellyfin/{*path}")]
[HttpGet("/artwork/fanart/jellyfin/{*path}")]
public Task < IActionResult > GetJellyfin ( string path )
public Task < IActionResult > GetJellyfin ( string path , CancellationToken cancellationToken )
{
if ( Request . QueryString . HasValue )
{
path + = Request . QueryString . Value ;
}
return GetJellyfinArtwork ( path ) ;
return GetJellyfinArtwork ( path , cancellationToken ) ;
}
[HttpHead("/iptv/artwork/posters/emby/{*path}")]
@ -94,54 +95,54 @@ namespace ErsatzTV.Controllers
@@ -94,54 +95,54 @@ namespace ErsatzTV.Controllers
[HttpGet("/iptv/artwork/thumbnails/emby/{*path}")]
[HttpGet("/artwork/thumbnails/emby/{*path}")]
[HttpGet("/artwork/fanart/emby/{*path}")]
public Task < IActionResult > GetEmby ( string path )
public Task < IActionResult > GetEmby ( string path , CancellationToken cancellationToken )
{
if ( Request . QueryString . HasValue )
{
path + = Request . QueryString . Value ;
}
return GetEmbyArtwork ( path ) ;
return GetEmbyArtwork ( path , cancellationToken ) ;
}
[HttpHead("/iptv/artwork/posters/plex/{plexMediaSourceId}/{*path}")]
[HttpGet("/iptv/artwork/posters/plex/{plexMediaSourceId}/{*path}")]
[HttpGet("/artwork/posters/plex/{plexMediaSourceId}/{*path}")]
public Task < IActionResult > GetPlexPoster ( int plexMediaSourceId , string path ) = >
public Task < IActionResult > GetPlexPoster ( int plexMediaSourceId , string path , CancellationToken cancellationToken ) = >
GetPlexArtwork (
plexMediaSourceId ,
$"photo/:/transcode?url=/{path}&height=440&width=304&minSize=1&upscale=0" ) ;
$"photo/:/transcode?url=/{path}&height=440&width=304&minSize=1&upscale=0" ,
cancellationToken ) ;
[HttpGet("/artwork/fanart/plex/{plexMediaSourceId}/{*path}")]
public Task < IActionResult > GetPlexFanArt ( int plexMediaSourceId , string path ) = >
GetPlexArtwork (
plexMediaSourceId ,
$"/{path}" ) ;
public Task < IActionResult > GetPlexFanArt ( int plexMediaSourceId , string path , CancellationToken cancellationToken ) = >
GetPlexArtwork ( plexMediaSourceId , $"/{path}" , cancellationToken ) ;
[HttpGet("/artwork/thumbnails/plex/{plexMediaSourceId}/{*path}")]
public Task < IActionResult > GetPlexThumbnail ( int plexMediaSourceId , string path ) = >
public Task < IActionResult > GetPlexThumbnail ( int plexMediaSourceId , string path , CancellationToken cancellationToken ) = >
GetPlexArtwork (
plexMediaSourceId ,
$"photo/:/transcode?url=/{path}&height=220&width=392&minSize=1&upscale=0" ) ;
$"photo/:/transcode?url=/{path}&height=220&width=392&minSize=1&upscale=0" ,
cancellationToken ) ;
[HttpHead("/iptv/artwork/thumbnails/{fileName}")]
[HttpGet("/iptv/artwork/thumbnails/{fileName}")]
[HttpHead("/iptv/artwork/thumbnails/{fileName}.jpg")]
[HttpGet("/iptv/artwork/thumbnails/{fileName}.jpg")]
[HttpGet("/artwork/thumbnails/{fileName}")]
public async Task < IActionResult > GetThumbnail ( string fileName )
public async Task < IActionResult > GetThumbnail ( string fileName , CancellationToken cancellationToken )
{
Either < BaseError , CachedImagePathViewModel > cachedImagePath =
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . Thumbnail , 2 2 0 ) ) ;
await _ mediator . Send ( new GetCachedImagePath ( fileName , ArtworkKind . Thumbnail , 2 2 0 ) , cancellationToken ) ;
return cachedImagePath . Match < IActionResult > (
Left : _ = > new NotFoundResult ( ) ,
Right : r = > new PhysicalFileResult ( r . FileName , r . MimeType ) ) ;
}
private async Task < IActionResult > GetPlexArtwork ( int plexMediaSourceId , string transcodePath )
private async Task < IActionResult > GetPlexArtwork ( int plexMediaSourceId , string transcodePath , CancellationToken cancellationToken )
{
Either < BaseError , PlexConnectionParametersViewModel > connectionParameters =
await _ mediator . Send ( new GetPlexConnectionParameters ( plexMediaSourceId ) ) ;
await _ mediator . Send ( new GetPlexConnectionParameters ( plexMediaSourceId ) , cancellationToken ) ;
return await connectionParameters . Match < Task < IActionResult > > (
Left : _ = > new NotFoundResult ( ) . AsTask < IActionResult > ( ) ,
@ -153,8 +154,9 @@ namespace ErsatzTV.Controllers
@@ -153,8 +154,9 @@ namespace ErsatzTV.Controllers
var fullPath = new Uri ( r . Uri , transcodePath ) ;
HttpResponseMessage response = await client . GetAsync (
fullPath ,
HttpCompletionOption . ResponseHeadersRead ) ;
Stream stream = await response . Content . ReadAsStreamAsync ( ) ;
HttpCompletionOption . ResponseHeadersRead ,
cancellationToken ) ;
Stream stream = await response . Content . ReadAsStreamAsync ( cancellationToken ) ;
return new FileStreamResult (
stream ,
@ -162,10 +164,10 @@ namespace ErsatzTV.Controllers
@@ -162,10 +164,10 @@ namespace ErsatzTV.Controllers
} ) ;
}
private async Task < IActionResult > GetJellyfinArtwork ( string path )
private async Task < IActionResult > GetJellyfinArtwork ( string path , CancellationToken cancellationToken )
{
Either < BaseError , JellyfinConnectionParametersViewModel > connectionParameters =
await _ mediator . Send ( new GetJellyfinConnectionParameters ( ) ) ;
await _ mediator . Send ( new GetJellyfinConnectionParameters ( ) , cancellationToken ) ;
return await connectionParameters . Match < Task < IActionResult > > (
Left : _ = > new NotFoundResult ( ) . AsTask < IActionResult > ( ) ,
@ -176,8 +178,9 @@ namespace ErsatzTV.Controllers
@@ -176,8 +178,9 @@ namespace ErsatzTV.Controllers
Url fullPath = JellyfinUrl . ForArtwork ( vm . Address , path ) ;
HttpResponseMessage response = await client . GetAsync (
fullPath ,
HttpCompletionOption . ResponseHeadersRead ) ;
Stream stream = await response . Content . ReadAsStreamAsync ( ) ;
HttpCompletionOption . ResponseHeadersRead ,
cancellationToken ) ;
Stream stream = await response . Content . ReadAsStreamAsync ( cancellationToken ) ;
return new FileStreamResult (
stream ,
@ -185,10 +188,10 @@ namespace ErsatzTV.Controllers
@@ -185,10 +188,10 @@ namespace ErsatzTV.Controllers
} ) ;
}
private async Task < IActionResult > GetEmbyArtwork ( string path )
private async Task < IActionResult > GetEmbyArtwork ( string path , CancellationToken cancellationToken )
{
Either < BaseError , EmbyConnectionParametersViewModel > connectionParameters =
await _ mediator . Send ( new GetEmbyConnectionParameters ( ) ) ;
await _ mediator . Send ( new GetEmbyConnectionParameters ( ) , cancellationToken ) ;
return await connectionParameters . Match < Task < IActionResult > > (
Left : _ = > new NotFoundResult ( ) . AsTask < IActionResult > ( ) ,
@ -199,8 +202,9 @@ namespace ErsatzTV.Controllers
@@ -199,8 +202,9 @@ namespace ErsatzTV.Controllers
Url fullPath = EmbyUrl . ForArtwork ( vm . Address , path ) ;
HttpResponseMessage response = await client . GetAsync (
fullPath ,
HttpCompletionOption . ResponseHeadersRead ) ;
Stream stream = await response . Content . ReadAsStreamAsync ( ) ;
HttpCompletionOption . ResponseHeadersRead ,
cancellationToken ) ;
Stream stream = await response . Content . ReadAsStreamAsync ( cancellationToken ) ;
return new FileStreamResult (
stream ,