-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e2b4f40
commit 2637d8c
Showing
22 changed files
with
376 additions
and
159 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
Class-Libraries/RedditPodcastPoster.BBC/BBCPageMetaDataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using System.Net; | ||
using Microsoft.Extensions.Logging; | ||
using RedditPodcastPoster.PodcastServices.Abstractions; | ||
|
||
namespace RedditPodcastPoster.BBC; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public class BBCPageMetaDataExtractor( | ||
IBBCHttpClient httpClient, | ||
IiPlayerPageMetaDataExtractor iPlayerPageMetaDataExtractor, | ||
ISoundsPageMetaDataExtractor soundsPageMetaDataExtractor, | ||
ILogger<BBCPageMetaDataExtractor> logger | ||
) : IBBCPageMetaDataExtractor | ||
{ | ||
public async Task<NonPodcastServiceItemMetaData> GetMetaData(Uri url) | ||
{ | ||
var pageResponse = await httpClient.GetAsync(url); | ||
if (pageResponse.StatusCode != HttpStatusCode.OK) | ||
{ | ||
throw new NonPodcastServiceMetaDataExtractionException(url, pageResponse.StatusCode); | ||
} | ||
NonPodcastServiceItemMetaData metaData; | ||
if (ServiceMatcher.IsSounds(url)) | ||
{ | ||
logger.LogInformation("For url '{url}' using extractor of type '{extractorType}'.", url, nameof(ISoundsPageMetaDataExtractor)); | ||
metaData = await soundsPageMetaDataExtractor.Extract(url, pageResponse); | ||
} | ||
else if (ServiceMatcher.IsIplayer(url)) | ||
{ | ||
logger.LogInformation("For url '{url}' using extractor of type '{extractorType}'.", url, nameof(IiPlayerPageMetaDataExtractor)); | ||
metaData = await iPlayerPageMetaDataExtractor.Extract(url, pageResponse); | ||
} | ||
else | ||
{ | ||
throw new InvalidOperationException($"Unknown bbc-service for url '{url}'."); | ||
} | ||
return metaData; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
Class-Libraries/RedditPodcastPoster.BBC/DTOs/BBCSoundsMetaData.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs; | ||
|
||
public class BBCSoundsMetaData | ||
{ | ||
[JsonPropertyName("programmes")] | ||
public required Programmes Programmes { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs | ||
{ | ||
public class Duration | ||
{ | ||
[JsonPropertyName("value")] | ||
public int? Seconds { get; set; } | ||
|
||
public TimeSpan? Length => Seconds==null? null: TimeSpan.FromSeconds(Seconds.Value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs | ||
{ | ||
public class Guidance | ||
{ | ||
[JsonPropertyName("warnings")] | ||
public Dictionary<string, string>? Warnings { get; set; } | ||
|
||
public bool HasWarnings => Warnings != null && Warnings.Any(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs; | ||
|
||
public class Programme | ||
{ | ||
[JsonPropertyName("release")] | ||
public required Release Release { get; set; } | ||
|
||
[JsonPropertyName("titles")] | ||
public required Titles Titles { get; set; } | ||
|
||
[JsonPropertyName("synopses")] | ||
public required Synopses Synopses { get; set; } | ||
|
||
[JsonPropertyName("duration")] | ||
public required Duration Duration { get; set; } | ||
|
||
[JsonPropertyName("guidance")] | ||
public required Guidance Guidance { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs; | ||
|
||
public class Programmes | ||
{ | ||
[JsonPropertyName("current")] | ||
public required Programme CurrentProgramme { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs; | ||
|
||
public class Release | ||
{ | ||
[JsonPropertyName("date")] | ||
public required DateTime Date { get; set; } | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs | ||
{ | ||
public class Synopses | ||
{ | ||
[JsonPropertyName("short")] | ||
public string? Short { get; set; } | ||
|
||
[JsonPropertyName("medium")] | ||
public string? Medium { get; set; } | ||
|
||
[JsonPropertyName("long")] | ||
public string? Long { get; set; } | ||
|
||
public string Description => Long ?? Medium ?? Short ?? string.Empty; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
using System.Text.Json.Serialization; | ||
|
||
namespace RedditPodcastPoster.BBC.DTOs; | ||
|
||
public class Titles | ||
{ | ||
[JsonPropertyName("primary")] | ||
public String? Primary { get; set; } | ||
|
||
[JsonPropertyName("secondary")] | ||
public String? Secondary { get; set; } | ||
|
||
[JsonPropertyName("tertiary")] | ||
public String? Tertiary { get; set; } | ||
|
||
[JsonPropertyName("entity_title")] | ||
public String? EntityTitle { get; set; } | ||
|
||
public string Title => EntityTitle ?? Tertiary ?? Secondary ?? Primary ?? string.Empty; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
Class-Libraries/RedditPodcastPoster.BBC/IBBCPageMetaDataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
using RedditPodcastPoster.PodcastServices.Abstractions; | ||
|
||
namespace RedditPodcastPoster.BBC; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public interface IBBCPageMetaDataExtractor | ||
{ | ||
Task<NonPodcastServiceItemMetaData> GetMetaData(Uri url); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
Class-Libraries/RedditPodcastPoster.BBC/ISoundsPageMetaDataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace RedditPodcastPoster.BBC; | ||
|
||
public interface ISoundsPageMetaDataExtractor : IMetaDataExtractor { } |
10 changes: 2 additions & 8 deletions
10
Class-Libraries/RedditPodcastPoster.BBC/IiPlayerPageMetaDataExtractor.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,3 @@ | ||
using RedditPodcastPoster.PodcastServices.Abstractions; | ||
namespace RedditPodcastPoster.BBC; | ||
|
||
namespace RedditPodcastPoster.BBC; | ||
|
||
// ReSharper disable once InconsistentNaming | ||
public interface IiPlayerPageMetaDataExtractor | ||
{ | ||
Task<NonPodcastServiceItemMetaData> GetMetaData(Uri url); | ||
} | ||
public interface IiPlayerPageMetaDataExtractor : IMetaDataExtractor { } |
108 changes: 0 additions & 108 deletions
108
Class-Libraries/RedditPodcastPoster.BBC/MetaDataExtractor.cs
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
namespace RedditPodcastPoster.BBC; | ||
|
||
public static class ServiceMatcher | ||
{ | ||
private static bool IsBBC(Uri url) | ||
{ | ||
return url.Host.ToLower().Contains("bbc.co.uk"); | ||
} | ||
public static bool IsIplayer(Uri url) | ||
{ | ||
return IsBBC(url) && url.AbsolutePath.StartsWith("/iplayer/episode"); | ||
} | ||
public static bool IsSounds(Uri url) | ||
{ | ||
return IsBBC(url) && url.AbsolutePath.StartsWith("/sounds/play/"); | ||
} | ||
|
||
} |
Oops, something went wrong.