using System.Globalization; using System.Text; using System.Text.RegularExpressions; using LiteCqrs; using Microsoft.Extensions.Hosting; using TeleWave.Api.Common; using TeleWave.Application.Common.Interfaces; using TeleWave.Application.Streaming; using TeleWave.Application.Streaming.GetLivePlaylist; using TeleWave.Application.Streaming.GetPublicEpg; using TeleWave.Application.Streaming.ListPublicChannels; using TeleWave.Infrastructure.Media; using TeleWave.Infrastructure.Streaming; namespace TeleWave.Api.Endpoints; public static class StreamingEndpoints { private const string StreamCookieName = "tw_stream"; private static readonly Regex SegmentFileName = new(@"^seg\d{1,6}\.ts$", RegexOptions.Compiled); public static IEndpointRouteBuilder MapStreamingEndpoints(this IEndpointRouteBuilder app) { // Публичный API канала (Bearer): список, EPG, выдача stream-cookie. var channels = app.MapGroup("/api/channels").WithTags("Channels").RequireAuthorization(); channels.MapGet("", ListChannels).Produces>(); channels.MapPost("/{slug}/watch", Watch).Produces(StatusCodes.Status204NoContent); channels.MapGet("/{slug}/epg", Epg); // Раздача эфира (cookie tw_stream): плейлист и сегменты — их грузит