added some logoutputs
This commit is contained in:
@@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
|
|||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace tv7playlist.Controllers
|
namespace tv7playlist.Controllers
|
||||||
{
|
{
|
||||||
@@ -14,16 +15,23 @@ namespace tv7playlist.Controllers
|
|||||||
{
|
{
|
||||||
private const string PlayListContentType = "audio/mpegurl";
|
private const string PlayListContentType = "audio/mpegurl";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This is the regex used to build up the proxy url.
|
||||||
|
/// The first part (udp://@) is ignored while generating the final url
|
||||||
|
/// The multicast address is expected to be a ip-address with a port and is reused
|
||||||
|
/// </summary>
|
||||||
private static readonly Regex MultiCastRegex = new Regex(@"(udp\:\/\/@)([0-9.:]+)",
|
private static readonly Regex MultiCastRegex = new Regex(@"(udp\:\/\/@)([0-9.:]+)",
|
||||||
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
|
RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
|
||||||
|
|
||||||
private readonly string _downloadFileName;
|
private readonly string _downloadFileName;
|
||||||
|
private readonly ILogger<PlayListController> _logger;
|
||||||
private readonly string _proxyUrl;
|
private readonly string _proxyUrl;
|
||||||
|
|
||||||
private readonly string _tv7Url;
|
private readonly string _tv7Url;
|
||||||
|
|
||||||
public PlayListController(IConfiguration configuration)
|
public PlayListController(ILogger<PlayListController> logger, IConfiguration configuration)
|
||||||
{
|
{
|
||||||
|
_logger = logger ?? throw new ArgumentNullException(nameof(logger));
|
||||||
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
|
if (configuration == null) throw new ArgumentNullException(nameof(configuration));
|
||||||
|
|
||||||
var appConfig = configuration.Get<AppConfig>();
|
var appConfig = configuration.Get<AppConfig>();
|
||||||
@@ -34,14 +42,26 @@ namespace tv7playlist.Controllers
|
|||||||
}
|
}
|
||||||
|
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
public async Task<FileStreamResult> Get()
|
public async Task<ActionResult> Get()
|
||||||
{
|
{
|
||||||
using (var httpClient = new HttpClient())
|
using (var httpClient = new HttpClient())
|
||||||
{
|
{
|
||||||
|
_logger.LogInformation(LoggingEvents.Playlist, "Downloading playlist from {tv7url}", _tv7Url);
|
||||||
var tv7Response = await httpClient.GetAsync(_tv7Url);
|
var tv7Response = await httpClient.GetAsync(_tv7Url);
|
||||||
|
|
||||||
|
if (!tv7Response.IsSuccessStatusCode)
|
||||||
|
{
|
||||||
|
_logger.LogWarning(LoggingEvents.PlaylistNotFound,
|
||||||
|
"Could not download playlist from {tv7url}. The StatusCode was: {StatusCode}", _tv7Url,
|
||||||
|
tv7Response.StatusCode);
|
||||||
|
return StatusCode((int) tv7Response.StatusCode);
|
||||||
|
}
|
||||||
|
|
||||||
var modifiedPlaylist = await BuildProxyPlaylist(tv7Response);
|
var modifiedPlaylist = await BuildProxyPlaylist(tv7Response);
|
||||||
|
|
||||||
|
_logger.LogInformation(LoggingEvents.Playlist, "Sending updated playlist {filename}",
|
||||||
|
_downloadFileName);
|
||||||
|
|
||||||
return new FileStreamResult(modifiedPlaylist, PlayListContentType)
|
return new FileStreamResult(modifiedPlaylist, PlayListContentType)
|
||||||
{
|
{
|
||||||
FileDownloadName = _downloadFileName
|
FileDownloadName = _downloadFileName
|
||||||
@@ -53,6 +73,7 @@ namespace tv7playlist.Controllers
|
|||||||
{
|
{
|
||||||
var outStream = new MemoryStream();
|
var outStream = new MemoryStream();
|
||||||
var outWriter = new StreamWriter(outStream);
|
var outWriter = new StreamWriter(outStream);
|
||||||
|
_logger.LogInformation(LoggingEvents.Playlist, "Building m3u file content");
|
||||||
|
|
||||||
using (var tv7ReadStream = await tv7Response.Content.ReadAsStreamAsync())
|
using (var tv7ReadStream = await tv7Response.Content.ReadAsStreamAsync())
|
||||||
using (var reader = new StreamReader(tv7ReadStream))
|
using (var reader = new StreamReader(tv7ReadStream))
|
||||||
@@ -60,8 +81,9 @@ namespace tv7playlist.Controllers
|
|||||||
while (!reader.EndOfStream)
|
while (!reader.EndOfStream)
|
||||||
{
|
{
|
||||||
var line = await reader.ReadLineAsync();
|
var line = await reader.ReadLineAsync();
|
||||||
line = MultiCastRegex.Replace(line, $"{_proxyUrl}/$2/");
|
var proxyLine = MultiCastRegex.Replace(line, $"{_proxyUrl}/$2/");
|
||||||
outWriter.WriteLine(line);
|
outWriter.WriteLine(proxyLine);
|
||||||
|
_logger.LogDebug(LoggingEvents.Playlist, "Transformed {src} to {dst}", line, proxyLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
await outWriter.FlushAsync();
|
await outWriter.FlushAsync();
|
||||||
|
10
LoggingEvents.cs
Normal file
10
LoggingEvents.cs
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
namespace tv7playlist
|
||||||
|
{
|
||||||
|
public class LoggingEvents
|
||||||
|
{
|
||||||
|
public const int Startup = 1000;
|
||||||
|
public const int Playlist = 1001;
|
||||||
|
|
||||||
|
public const int PlaylistNotFound = 4000;
|
||||||
|
}
|
||||||
|
}
|
@@ -1,5 +1,6 @@
|
|||||||
using Microsoft.AspNetCore;
|
using Microsoft.AspNetCore;
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
|
using Microsoft.Extensions.Logging;
|
||||||
|
|
||||||
namespace tv7playlist
|
namespace tv7playlist
|
||||||
{
|
{
|
||||||
@@ -15,6 +16,12 @@ namespace tv7playlist
|
|||||||
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
public static IWebHostBuilder CreateWebHostBuilder(string[] args)
|
||||||
{
|
{
|
||||||
return WebHost.CreateDefaultBuilder(args)
|
return WebHost.CreateDefaultBuilder(args)
|
||||||
|
.ConfigureLogging((hostingContext, logging) =>
|
||||||
|
{
|
||||||
|
logging.AddConfiguration(hostingContext.Configuration.GetSection("Logging"));
|
||||||
|
logging.AddConsole();
|
||||||
|
logging.AddDebug();
|
||||||
|
})
|
||||||
.UseStartup<Startup>();
|
.UseStartup<Startup>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
34
Startup.cs
34
Startup.cs
@@ -1,23 +1,20 @@
|
|||||||
using System;
|
using Microsoft.AspNetCore.Builder;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using Microsoft.AspNetCore.Builder;
|
|
||||||
using Microsoft.AspNetCore.Hosting;
|
using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.AspNetCore.HttpsPolicy;
|
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
|
||||||
|
|
||||||
namespace tv7playlist
|
namespace tv7playlist
|
||||||
{
|
{
|
||||||
public class Startup
|
public class Startup
|
||||||
{
|
{
|
||||||
public Startup(IConfiguration configuration)
|
private readonly ILogger _logger;
|
||||||
|
|
||||||
|
public Startup(IConfiguration configuration, ILogger<Startup> logger)
|
||||||
{
|
{
|
||||||
Configuration = configuration;
|
Configuration = configuration;
|
||||||
|
_logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public IConfiguration Configuration { get; }
|
public IConfiguration Configuration { get; }
|
||||||
@@ -33,15 +30,20 @@ namespace tv7playlist
|
|||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
|
||||||
{
|
{
|
||||||
if (env.IsDevelopment())
|
LogConfiguration();
|
||||||
{
|
|
||||||
app.UseDeveloperExceptionPage();
|
if (env.IsDevelopment()) app.UseDeveloperExceptionPage();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
app.UseHsts();
|
|
||||||
}
|
|
||||||
app.UseMvc();
|
app.UseMvc();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void LogConfiguration()
|
||||||
|
{
|
||||||
|
var appConfig = Configuration.Get<AppConfig>();
|
||||||
|
_logger.LogInformation(LoggingEvents.Startup, "Using TV7 URL: {TV7Url}", appConfig.TV7Url);
|
||||||
|
_logger.LogInformation(LoggingEvents.Startup, "Using Udpxy URL: {UdpxyUrl}", appConfig.UdpxyUrl);
|
||||||
|
_logger.LogInformation(LoggingEvents.Startup, "Using DownloadFileName: {DownloadFileName}",
|
||||||
|
appConfig.DownloadFileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1,11 +1,13 @@
|
|||||||
{
|
{
|
||||||
"Logging": {
|
"Logging": {
|
||||||
"LogLevel": {
|
"LogLevel": {
|
||||||
"Default": "Warning"
|
"Default": "Information",
|
||||||
|
"System": "Information",
|
||||||
|
"Microsoft": "Information"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"TV7Url":"https://api.init7.net/tvchannels.m3u",
|
"TV7Url": "https://api.init7.net/tvchannels.m3u",
|
||||||
"UdpxyUrl":"http://192.168.15.2:4022/udp",
|
"UdpxyUrl": "http://192.168.15.2:4022/udp",
|
||||||
"DownloadFileName":"PlaylistTV7udpxy.m3u"
|
"DownloadFileName": "PlaylistTV7udpxy.m3u"
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user