feat: stream live to laut.fm and import from its library

The Settings page gets a laut.fm card: a switch, the live access data
from Radioadmin (server, port, mountpoint, user, password) and the
station id and Radioadmin token for the library. Password and token
are written to settings.json encrypted with DPAPI for the Windows user.

While laut.fm is on, the Schedule page shows a Live button next to
"Jetzt starten". It logs in at the Icecast server with PUT and sends a
copy of the broadcast mix as MP3 at 128 kbit/s, encoded by Windows
Media Foundation. ProgramOutput hands that copy out through a live
feed. Each item that starts sets the stream title; ad items send
START_AD_BREAK at most once every 15 minutes.

LautFmProvider searches the station's tracks through the Radioadmin
API and the Import page lists it while laut.fm is on, so laut.fm tracks
are imported into the same library as local songs. Providers can now
hide themselves with IsAvailable.

Nothing was tested against a real laut.fm account; the tests use a
local fake server and fake HTTP answers.

Refs #15

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
fraujulianandClaude Opus 5.5 committed 2026-11-25 08:36:39 +01:00
1 parent 5d261717fe
commit a94fb862d2
16 files changed
+999 -16

No files matched your search

@@ -86,6 +86,16 @@
Icon="{ui:SymbolIcon Play24}"
ToolTip="Plant ab diesem Moment und geht sofort auf Sendung. Die Startzeit wird ignoriert."
Click="OnStartNow" />
<!-- Only while laut.fm is on: sends the program live to the station, independent of the plan. -->
<ui:Button x:Name="LiveButton"
MinWidth="100"
Margin="8,8,0,0"
VerticalAlignment="Center"
Content="Live"
Icon="{ui:SymbolIcon Live24}"
ToolTip="Sendet alles, was auf Sendung ist, live auf deine laut.fm-Station."
Visibility="Collapsed"
Click="OnLiveToggle" />
</WrapPanel>
<ui:InfoBar x:Name="Message"
@@ -31,10 +31,12 @@ public partial class SchedulePage : Page
private readonly Microphone _microphone;
private readonly ProgramMixer _mixer;
private readonly LiveController _live;
public SchedulePage(ScheduleController controller, Microphone microphone, ProgramOutput output)
public SchedulePage(ScheduleController controller, Microphone microphone, ProgramOutput output, LiveController live)
{
_controller = controller;
_live = live;
_microphone = microphone;
_mixer = output.Mixer;
InitializeComponent();
@@ -53,6 +55,7 @@ public partial class SchedulePage : Page
_controller.ItemStarted += OnItemStarted;
_controller.ItemFailed += OnItemFailed;
_controller.Finished += OnFinished;
_live.Problem += OnLiveProblem;
_loading = true;
VolumeSlider.Value = _controller.Volume;
@@ -63,6 +66,7 @@ public partial class SchedulePage : Page
MusicForMeSlider.IsEnabled = !_mixer.ListenToBroadcast;
_loading = false;
ShowMicrophone(); // it stays on while the user visits other pages
ShowLive();
FillStartTimes();
if (_controller.Plan.Count > 0)
UnlimitedBox.IsChecked = _controller.IsUnlimited;
@@ -82,6 +86,7 @@ public partial class SchedulePage : Page
_controller.ItemStarted -= OnItemStarted;
_controller.ItemFailed -= OnItemFailed;
_controller.Finished -= OnFinished;
_live.Problem -= OnLiveProblem;
_progressTimer.Stop();
}
@@ -216,6 +221,47 @@ public partial class SchedulePage : Page
System.Windows.Automation.AutomationProperties.SetName(MicButton, on ? "Mikrofon ausschalten, es ist auf Sendung" : "Mikrofon einschalten");
}
private async void OnLiveToggle(object sender, RoutedEventArgs e)
{
LiveButton.IsEnabled = false;
try
{
if (_live.IsLive)
{
await Task.Run(_live.Stop);
}
else
{
// Opening the devices and the connection can take a moment, so it runs off the UI thread.
await Task.Run(() => _live.StartAsync());
Message.IsOpen = false;
}
}
catch (Exception ex) when (ex is LiveStreamException or NAudio.MmException)
{
ShowMessage(InfoBarSeverity.Error, "Live nicht möglich", ex.Message);
}
LiveButton.IsEnabled = true;
ShowLive();
}
// Comes from a background thread; the stream may have ended.
private void OnLiveProblem(object? sender, string message) => Dispatcher.BeginInvoke(() =>
{
ShowMessage(InfoBarSeverity.Warning, "laut.fm", message);
ShowLive();
});
private void ShowLive()
{
var live = _live.IsLive;
// Stays visible while live, so a stream can be stopped after laut.fm was switched off.
LiveButton.Visibility = _live.IsEnabled || live ? Visibility.Visible : Visibility.Collapsed;
LiveButton.Content = live ? "Live beenden" : "Live";
LiveButton.Appearance = live ? ControlAppearance.Danger : ControlAppearance.Secondary;
System.Windows.Automation.AutomationProperties.SetName(LiveButton, live ? "Livestream zu laut.fm beenden, er läuft" : "Livestream zu laut.fm starten");
}
private void OnEndNow(object sender, RoutedEventArgs e)
{
try
@@ -154,6 +154,74 @@
</Grid>
</Border>
<!-- laut.fm: live streaming and the station's library -->
<Border Style="{StaticResource Card}">
<StackPanel>
<ui:ToggleSwitch x:Name="LautFmSwitch" Content="laut.fm"
Checked="OnLautFmChanged" Unchecked="OnLautFmChanged" />
<ui:TextBlock Margin="0,8,0,0" TextWrapping="Wrap"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Sendet live auf deine laut.fm-Station und bietet ihre Musik beim Import an. Im Plan erscheint dann der Button „Live“." />
<Grid x:Name="LautFmFields" Margin="0,4,0,0">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="220" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<ui:TextBlock Margin="0,12,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Live senden" />
<Label Grid.Row="1" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Server" Target="{Binding ElementName=LautFmHostBox}" />
<ui:TextBox x:Name="LautFmHostBox" Grid.Row="1" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="laut.fm-Server" />
<Label Grid.Row="2" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Port" Target="{Binding ElementName=LautFmPortBox}" />
<ui:NumberBox x:Name="LautFmPortBox" Grid.Row="2" Grid.Column="1" Margin="0,8,0,0"
Width="130" HorizontalAlignment="Left" Minimum="1" Maximum="65535"
MaxDecimalPlaces="0" SmallChange="1" ClearButtonEnabled="False"
AutomationProperties.Name="laut.fm-Port" />
<Label Grid.Row="3" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Mountpoint" Target="{Binding ElementName=LautFmMountBox}" />
<ui:TextBox x:Name="LautFmMountBox" Grid.Row="3" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="laut.fm-Mountpoint" />
<Label Grid.Row="4" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Benutzer" Target="{Binding ElementName=LautFmUserBox}" />
<ui:TextBox x:Name="LautFmUserBox" Grid.Row="4" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="laut.fm-Benutzer" />
<Label Grid.Row="5" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Passwort" Target="{Binding ElementName=LautFmPasswordBox}" />
<ui:PasswordBox x:Name="LautFmPasswordBox" Grid.Row="5" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="laut.fm-Passwort" />
<ui:TextBlock Grid.Row="6" Grid.ColumnSpan="2" Margin="0,8,0,0" TextWrapping="Wrap"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Diese Werte stehen in Radioadmin unter „Live senden“." />
<ui:TextBlock Grid.Row="7" Margin="0,16,0,0" Grid.ColumnSpan="2" FontTypography="BodyStrong" Text="Bibliothek" />
<Label Grid.Row="8" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Stations-ID" Target="{Binding ElementName=LautFmStationBox}" />
<ui:TextBox x:Name="LautFmStationBox" Grid.Row="8" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="laut.fm-Stations-ID" />
<Label Grid.Row="9" Margin="0,8,0,0" VerticalAlignment="Center"
Content="Radioadmin-Token" Target="{Binding ElementName=LautFmTokenBox}" />
<ui:PasswordBox x:Name="LautFmTokenBox" Grid.Row="9" Grid.Column="1" Margin="0,8,0,0"
AutomationProperties.Name="Radioadmin-Token"
ToolTip="Nach dem Login in Radioadmin in den Entwicklertools des Browsers: Lokaler Speicher, SchlĂĽssel laut.fm.api.token." />
</Grid>
<ui:TextBlock x:Name="LautFmHint" Margin="0,12,0,0" TextWrapping="Wrap"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Text="Passwort und Token werden verschlĂĽsselt fĂĽr deinen Windows-Benutzer gespeichert. Die Bibliothek nutzt eine nicht offizielle laut.fm-Schnittstelle und kann ohne Vorwarnung ausfallen." />
</StackPanel>
</Border>
<StackPanel Margin="0,4,0,0" Orientation="Horizontal">
<ui:Button Appearance="Primary" MinWidth="110" Content="Speichern" Icon="{ui:SymbolIcon Save24}" Click="OnSave" />
<ui:Button Margin="8,0,0,0" MinWidth="110" Content="ZurĂĽcksetzen" Icon="{ui:SymbolIcon ArrowReset24}"
@@ -41,8 +41,21 @@ public partial class SettingsPage : Page
NewsMinutesBox.Value = settings.NewsMinutesPerHour;
ModeratorMinutesBox.Value = settings.ModeratorMinutesPerHour;
AdMinutesBox.Value = settings.AdMinutesPerHour;
LautFmSwitch.IsChecked = settings.LautFmEnabled;
LautFmHostBox.Text = settings.LautFmHost;
LautFmPortBox.Value = settings.LautFmPort;
LautFmMountBox.Text = settings.LautFmMount;
LautFmUserBox.Text = settings.LautFmUser;
LautFmPasswordBox.Password = settings.LautFmPassword;
LautFmStationBox.Text = settings.LautFmStationId;
LautFmTokenBox.Password = settings.LautFmToken;
OnLautFmChanged(this, new RoutedEventArgs());
}
// The access fields only matter while laut.fm is on.
private void OnLautFmChanged(object sender, RoutedEventArgs e) =>
LautFmFields.Visibility = LautFmSwitch.IsChecked == true ? Visibility.Visible : Visibility.Collapsed;
// An emptied number box counts as its default.
private static AppSettings Defaults { get; } = new();
@@ -59,6 +72,14 @@ public partial class SettingsPage : Page
AdMinutesPerHour = (int)(AdMinutesBox.Value ?? Defaults.AdMinutesPerHour),
BroadcastDevice = BroadcastDeviceBox.SelectedIndex > 0 ? (string)BroadcastDeviceBox.SelectedItem : null,
MonitorDevice = MonitorDeviceBox.SelectedIndex > 0 ? (string)MonitorDeviceBox.SelectedItem : null,
LautFmEnabled = LautFmSwitch.IsChecked == true,
LautFmHost = LautFmHostBox.Text.Trim(),
LautFmPort = (int)(LautFmPortBox.Value ?? Defaults.LautFmPort),
LautFmMount = LautFmMountBox.Text.Trim(),
LautFmUser = LautFmUserBox.Text.Trim(),
LautFmPassword = LautFmPasswordBox.Password,
LautFmStationId = LautFmStationBox.Text.Trim(),
LautFmToken = LautFmTokenBox.Password.Trim(),
};
private void OnSave(object sender, RoutedEventArgs e)