@ -1,5 +1,7 @@
@@ -1,5 +1,7 @@
using ErsatzTV.Core ;
using ErsatzTV.Core.Domain ;
using ErsatzTV.Core.Interfaces.Repositories ;
using ErsatzTV.FFmpeg.OutputFormat ;
using ErsatzTV.Infrastructure.Data ;
using ErsatzTV.Infrastructure.Extensions ;
using Microsoft.EntityFrameworkCore ;
@ -11,13 +13,16 @@ public class GetHlsPlaylistByChannelNumberHandler :
@@ -11,13 +13,16 @@ public class GetHlsPlaylistByChannelNumberHandler :
IRequestHandler < GetHlsPlaylistByChannelNumber , Either < BaseError , string > >
{
private readonly IDbContextFactory < TvContext > _d bContextFactory ;
private readonly IConfigElementRepository _ configElementRepository ;
private readonly IMemoryCache _ memoryCache ;
public GetHlsPlaylistByChannelNumberHandler (
IDbContextFactory < TvContext > dbContextFactory ,
IConfigElementRepository configElementRepository ,
IMemoryCache memoryCache )
{
_d bContextFactory = dbContextFactory ;
_ configElementRepository = configElementRepository ;
_ memoryCache = memoryCache ;
}
@ -31,7 +36,7 @@ public class GetHlsPlaylistByChannelNumberHandler :
@@ -31,7 +36,7 @@ public class GetHlsPlaylistByChannelNumberHandler :
return await validation . Apply ( parameters = > GetPlaylist ( dbContext , request , parameters , now ) ) ;
}
private Task < string > GetPlaylist (
private async Task < string > GetPlaylist (
TvContext dbContext ,
GetHlsPlaylistByChannelNumber request ,
Parameters parameters ,
@ -44,11 +49,25 @@ public class GetHlsPlaylistByChannelNumberHandler :
@@ -44,11 +49,25 @@ public class GetHlsPlaylistByChannelNumberHandler :
_ = > string . Empty
} ;
string endpoint = request . Mode switch
string endpoint = "ffmpeg/stream" ;
string extension = string . Empty ;
if ( request . Mode is "hls-direct" )
{
"hls-direct" = > "iptv/hls-direct" ,
_ = > "ffmpeg/stream"
} ;
endpoint = "iptv/hls-direct" ;
OutputFormatKind outputFormat = await _ configElementRepository
. GetValue < OutputFormatKind > ( ConfigElementKey . FFmpegHlsDirectOutputFormat , CancellationToken . None )
. IfNoneAsync ( OutputFormatKind . MpegTs ) ;
extension = outputFormat switch
{
OutputFormatKind . MpegTs = > ".ts" ,
OutputFormatKind . Mp4 = > ".mp4" ,
OutputFormatKind . Mkv = > ".mkv" ,
_ = > string . Empty
} ;
}
long index = GetIndexForChannel ( parameters . Channel , parameters . PlayoutItem ) ;
double timeRemaining = Math . Abs ( ( parameters . PlayoutItem . FinishOffset - now ) . TotalSeconds ) ;
@ -58,8 +77,8 @@ public class GetHlsPlaylistByChannelNumberHandler :
@@ -58,8 +77,8 @@ public class GetHlsPlaylistByChannelNumberHandler :
# EXT - X - MEDIA - SEQUENCE : { index }
# EXT - X - DISCONTINUITY
# EXTINF : { timeRemaining : F2 } ,
{ request . Scheme } : //{request.Host}/{endpoint}/{request.ChannelNumber}?index={index}{mode}
".AsTask() ;
{ request . Scheme } : //{request.Host}/{endpoint}/{request.ChannelNumber}{extension} ?index={index}{mode}
";
}
private static Task < Validation < BaseError , Parameters > > Validate (