aboutsummaryrefslogtreecommitdiffstats
path: root/src/Services
diff options
context:
space:
mode:
Diffstat (limited to 'src/Services')
-rw-r--r--src/Services/NrkNewsService.cs (renamed from src/Services/GrabberService.cs)8
-rw-r--r--src/Services/NrkRadioService.cs31
2 files changed, 35 insertions, 4 deletions
diff --git a/src/Services/GrabberService.cs b/src/Services/NrkNewsService.cs
index d6650a2..df9d64e 100644
--- a/src/Services/GrabberService.cs
+++ b/src/Services/NrkNewsService.cs
@@ -6,9 +6,9 @@ using Microsoft.Extensions.Caching.Memory;
namespace I2R.LightNews.Services;
-public class GrabberService
+public class NrkNewsService
{
- private readonly ILogger<GrabberService> _logger;
+ private readonly ILogger<NrkNewsService> _logger;
private readonly IMemoryCache _memoryCache;
private readonly HttpClient _http;
private const string NrkPrefix = "nrkno";
@@ -18,7 +18,7 @@ public class GrabberService
HostPath = "AppData/__sitecache"
};
- public GrabberService(ILogger<GrabberService> logger, HttpClient http, IMemoryCache memoryCache) {
+ public NrkNewsService(ILogger<NrkNewsService> logger, HttpClient http, IMemoryCache memoryCache) {
_logger = logger;
_http = http;
_memoryCache = memoryCache;
@@ -100,7 +100,7 @@ public class GrabberService
result.Title = doc.QuerySelector(".article-feature__intro h1").TextContent;
var contentHtml = doc.QuerySelector(".article-feature__body").InnerHtml;
result.Content = HtmlSanitiser.SanitizeHtmlFragment(subtitle + contentHtml, string.Join(',', defaultExcludes));
- } else if (url.Contains("nrk.no/nyheter") || doc.QuerySelector(".bulletin-text") != default) {
+ } else if (url.Contains("nrk.no/nyheter") || (doc.QuerySelector(".bulletin-text") != default && doc.QuerySelector(".article-body") == defaultExcludes)) {
result.Content = HtmlSanitiser.SanitizeHtmlFragment(doc.QuerySelector(".bulletin-text").InnerHtml);
} else {
result.Content = HtmlSanitiser.SanitizeHtmlFragment(doc.QuerySelector(".article-body").InnerHtml, string.Join(',', defaultExcludes));
diff --git a/src/Services/NrkRadioService.cs b/src/Services/NrkRadioService.cs
new file mode 100644
index 0000000..a2889ce
--- /dev/null
+++ b/src/Services/NrkRadioService.cs
@@ -0,0 +1,31 @@
+using Microsoft.Extensions.Caching.Memory;
+
+namespace I2R.LightNews.Services;
+
+public class NrkRadioService
+{
+ private readonly IMemoryCache _cache;
+ private readonly HttpClient _http;
+ private const string CATEGORY_SEARCH_CACHE_KEY = "category_search";
+
+ public NrkRadioService(IMemoryCache cache, HttpClient http) {
+ _cache = cache;
+ http.BaseAddress = new Uri("https://psapi.nrk.no");
+ _http = http;
+ }
+
+ public async Task GetEverythingAsync() {
+ var path = "/radio/search/categories/alt-innhold";
+ var everything = new List<RadioSeries>();
+ while (path.HasValue()) {
+ var response = await _http.GetFromJsonAsync<RadioCategorySearchResult>(path);
+
+ }
+ }
+
+ public async Task<RadioCategorySearchResult> SearchCategoriesAsync(string query, int take = 50, int skip = 50) {
+ return await _http.GetFromJsonAsync<RadioCategorySearchResult>(
+ "/radio/search/categories/alt-innhold?q=" + query + "&take=" + take + "&skip=" + skip
+ );
+ }
+} \ No newline at end of file