Skip to content

Commit

Permalink
imp - Simplified initial refresh for server instance
Browse files Browse the repository at this point in the history
---

We've simplified the initial refresh for the radio server instance so that you are only required to call a single function from RadioTools.

---

Type: imp
Breaking: False
Doc Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed May 31, 2024
1 parent 061bc1f commit aa282b1
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 4 deletions.
7 changes: 7 additions & 0 deletions BassBoom.Basolia/Playback/PlaybackPositioningTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ public static void SeekToFrame(int frame)
}
}

/// <summary>
/// Seeks according to the lyric line
/// </summary>
/// <param name="lyricLine">Lyric line instance</param>
/// <exception cref="BasoliaException"></exception>
public static void SeekLyric(LyricLine lyricLine)
{
lock (PositionLock)
Expand All @@ -153,6 +158,8 @@ public static void SeekLyric(LyricLine lyricLine)
// Check to see if the file is open
if (!FileTools.IsOpened)
throw new BasoliaException("Can't seek a file that's not open", mpg123_errors.MPG123_BAD_FILE);
if (lyricLine is null)
throw new BasoliaException("Lyric line is not provided to seek to", mpg123_errors.MPG123_BAD_FILE);

// Get the length, convert it to frames, and seek
var length = lyricLine.LineSpan.TotalSeconds;
Expand Down
2 changes: 1 addition & 1 deletion BassBoom.Basolia/Radio/IcecastServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public class IcecastServer : IRadioServer
/// <param name="serverHost">Server host name</param>
/// <param name="serverPort">Server port</param>
/// <param name="useHttps">Whether to use the HTTPS protocol or not</param>
public IcecastServer(string serverHost, int serverPort, bool useHttps)
internal IcecastServer(string serverHost, int serverPort, bool useHttps)
{
// Check to see if we're dealing with the secure Icecast server
ServerHost = serverHost;
Expand Down
16 changes: 15 additions & 1 deletion BassBoom.Basolia/Radio/RadioTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,19 @@ public static class RadioTools
{
internal static HttpClient client = new();

/// <summary>
/// Gets extended radio station information
/// </summary>
/// <param name="radioUrl">Radio station URL</param>
/// <returns>An instance of <see cref="IRadioServer"/>. <see langword="null"/> if type can't be determined. <see cref="ShoutcastServer"/> if this radio station server uses Shoutcast, and <see cref="IcecastServer"/> if it uses Icecast.</returns>
public static IRadioServer GetRadioInfo(string radioUrl) =>
GetRadioInfoAsync(radioUrl).Result;

/// <summary>
/// Gets extended radio station information asynchronously
/// </summary>
/// <param name="radioUrl">Radio station URL</param>
/// <returns>An instance of <see cref="IRadioServer"/>. <see langword="null"/> if type can't be determined. <see cref="ShoutcastServer"/> if this radio station server uses Shoutcast, and <see cref="IcecastServer"/> if it uses Icecast.</returns>
public static async Task<IRadioServer> GetRadioInfoAsync(string radioUrl)
{
// Check to see if we provided a path
Expand Down Expand Up @@ -62,14 +72,18 @@ public static async Task<IRadioServer> GetRadioInfoAsync(string radioUrl)
throw new BasoliaMiscException("Can't determine radio station server type.");

// Return the appropriate parsed server stats instance
return type switch
IRadioServer stats = type switch
{
RadioServerType.Shoutcast =>
new ShoutcastServer(uri.Host, uri.Port, uri.Scheme == "https"),
RadioServerType.Icecast =>
new IcecastServer(uri.Host, uri.Port, uri.Scheme == "https"),
_ => null,
};
if (stats is null)
return null;
await stats.RefreshAsync();
return stats;
}
}
}
2 changes: 1 addition & 1 deletion BassBoom.Basolia/Radio/ShoutcastServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public class ShoutcastServer : IRadioServer
/// <param name="serverHost">Server host name</param>
/// <param name="serverPort">Server port</param>
/// <param name="useHttps">Whether to use the HTTPS protocol or not</param>
public ShoutcastServer(string serverHost, int serverPort, bool useHttps)
internal ShoutcastServer(string serverHost, int serverPort, bool useHttps)
{
// Check to see if we're dealing with the secure Shoutcast server
ServerHost = serverHost;
Expand Down
1 change: 1 addition & 0 deletions BassBoom.Cli/CliBase/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ [ESC] Stop
[Q] Exit
[UP/DOWN] Volume control
[I] Radio station info
[CTRL] + [I] Radio station extended info
[A] Add a radio station
[B] Previous radio station
[N] Next radio station
Expand Down
1 change: 0 additions & 1 deletion BassBoom.Cli/CliBase/RadioControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ Native State
internal static void ShowExtendedStationInfo()
{
var station = RadioTools.GetRadioInfo(Common.CurrentCachedInfo.MusicPath);
station.Refresh();
var streamBuilder = new StringBuilder();
foreach (var stream in station.Streams)
{
Expand Down

0 comments on commit aa282b1

Please sign in to comment.