added parser to config and register on startup
This commit is contained in:
@@ -2,7 +2,14 @@ namespace Tv7Playlist
|
||||
{
|
||||
public class AppConfig
|
||||
{
|
||||
public enum SourceTypeEnum
|
||||
{
|
||||
M3U,
|
||||
XSPF
|
||||
}
|
||||
|
||||
public string TV7Url { get; set; }
|
||||
public SourceTypeEnum SourceType { get; set; }
|
||||
public string UdpxyUrl { get; set; }
|
||||
public string DownloadFileName { get; set; }
|
||||
}
|
||||
|
@@ -1,4 +1,5 @@
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using System;
|
||||
using Microsoft.AspNetCore.Builder;
|
||||
using Microsoft.AspNetCore.Hosting;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
@@ -7,6 +8,9 @@ using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Tv7Playlist.Core;
|
||||
using Tv7Playlist.Core.Parsers;
|
||||
using Tv7Playlist.Core.Parsers.M3u;
|
||||
using Tv7Playlist.Core.Parsers.Xspf;
|
||||
using Tv7Playlist.Data;
|
||||
|
||||
namespace Tv7Playlist
|
||||
@@ -33,10 +37,9 @@ namespace Tv7Playlist
|
||||
options.MinimumSameSitePolicy = SameSiteMode.None;
|
||||
});
|
||||
|
||||
//TODO: Move to settings to make it configurable within docker.
|
||||
var connection = "Data Source=playlist.db";
|
||||
services.AddDbContext<PlaylistContext>(options => options.UseSqlite(connection));
|
||||
|
||||
ConfigureParser(services);
|
||||
ConfigureDatabase(services);
|
||||
|
||||
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
|
||||
}
|
||||
|
||||
@@ -68,6 +71,29 @@ namespace Tv7Playlist
|
||||
});
|
||||
}
|
||||
|
||||
private void ConfigureParser(IServiceCollection services)
|
||||
{
|
||||
var type = Configuration.Get<AppConfig>().SourceType;
|
||||
switch (type)
|
||||
{
|
||||
case AppConfig.SourceTypeEnum.M3U:
|
||||
services.AddTransient<IPlaylistParser, M3UParser>();
|
||||
break;
|
||||
case AppConfig.SourceTypeEnum.XSPF:
|
||||
services.AddTransient<IPlaylistParser, XspfParser>();
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private static void ConfigureDatabase(IServiceCollection services)
|
||||
{
|
||||
//TODO: Move to settings to make it configurable within docker.
|
||||
var connection = "Data Source=playlist.db";
|
||||
services.AddDbContext<PlaylistContext>(options => options.UseSqlite(connection));
|
||||
}
|
||||
|
||||
private void LogConfiguration()
|
||||
{
|
||||
var appConfig = Configuration.Get<AppConfig>();
|
||||
|
@@ -1,5 +1,5 @@
|
||||
@{
|
||||
ViewData["Title"] = "Home Page";
|
||||
ViewData["Title"] = "TV7 Playlist";
|
||||
}
|
||||
|
||||
<div class="text-center">
|
||||
|
@@ -7,6 +7,7 @@
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"SourceType": "M3U",
|
||||
"TV7Url": "https://api.init7.net/tvchannels.m3u",
|
||||
"UdpxyUrl": "http://192.168.15.2:4022/udp",
|
||||
"DownloadFileName": "PlaylistTV7udpxy.m3u"
|
||||
|
Reference in New Issue
Block a user