diff --git a/Handlers/MPDHandler.cs b/Handlers/MPDHandler.cs
index bbb4dd2..3203c4e 100644
--- a/Handlers/MPDHandler.cs
+++ b/Handlers/MPDHandler.cs
@@ -364,7 +364,14 @@ namespace unison
else
{
using MemoryStream stream = new MemoryStream(data.ToArray());
- _cover = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
+ try
+ {
+ _cover = BitmapFrame.Create(stream, BitmapCreateOptions.None, BitmapCacheOption.OnLoad);
+ }
+ catch (System.NotSupportedException e)
+ {
+ _cover = null;
+ }
}
UpdateCover();
}
diff --git a/Views/MainWindow.xaml.cs b/Views/MainWindow.xaml.cs
index cc3d829..e9004fe 100644
--- a/Views/MainWindow.xaml.cs
+++ b/Views/MainWindow.xaml.cs
@@ -70,11 +70,12 @@ namespace unison
SongTitle.Text = _mpd.GetCurrentSong().Title;
else if (_mpd.GetCurrentSong().HasName && _mpd.GetCurrentSong().Name.Length > 0)
SongTitle.Text = _mpd.GetCurrentSong().Name;
- else
+ else if (_mpd.GetCurrentSong().Path != null)
{
int start = _mpd.GetCurrentSong().Path.LastIndexOf("/") + 1;
int end = _mpd.GetCurrentSong().Path.LastIndexOf(".");
- SongTitle.Text = _mpd.GetCurrentSong().Path.Substring(start, end - start);
+ if (start > 0 && end > 0 && end > start)
+ SongTitle.Text = _mpd.GetCurrentSong().Path.Substring(start, end - start);
}
SongTitle.ToolTip = _mpd.GetCurrentSong().Path;
@@ -216,7 +217,7 @@ namespace unison
snapcast.LaunchOrExit();
}
- public async void Radios_Clicked(object sender, RoutedEventArgs e)
+ public void Radios_Clicked(object sender, RoutedEventArgs e)
{
_radiosWin.Show();
_radiosWin.Activate();
diff --git a/Views/Radios.xaml b/Views/Radios.xaml
index 2674f40..aed7557 100644
--- a/Views/Radios.xaml
+++ b/Views/Radios.xaml
@@ -3,20 +3,77 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
+ xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
xmlns:local="clr-namespace:unison"
mc:Ignorable="d"
- Title="Radios" Closing="Window_Closing" SizeToContent="WidthAndHeight">
+ Title="Radios" Closing="Window_Closing" SizeToContent="WidthAndHeight" ResizeMode="NoResize">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
-
diff --git a/Views/Radios.xaml.cs b/Views/Radios.xaml.cs
index 4cd42da..62657d5 100644
--- a/Views/Radios.xaml.cs
+++ b/Views/Radios.xaml.cs
@@ -1,6 +1,5 @@
using RadioBrowser;
using RadioBrowser.Models;
-using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
@@ -9,86 +8,179 @@ using System;
using System.ComponentModel;
using System.Windows.Interop;
using System.Windows.Controls;
-using System.Windows.Data;
+using System.Windows.Input;
+using System.Collections.Generic;
namespace unison
{
- public class StationView : StationInfo
+ public class CountryListItem
{
- public StationView(string _name, Uri _url, int _bitrate, string _codec, string _country, Uri _favicon)
- {
- Name = _name;
- Url = _url;
- Bitrate = _bitrate;
- Codec = _codec;
- CountryCode = _country;
- Favicon = _favicon;
- }
+ public uint Count { get; set; }
+ public string Name { get; set; }
public override string ToString()
{
- return $"{this.Name} - {this.Bitrate} - {this.Codec} - {this.CountryCode}";
+ if (Name == "")
+ return "None";
+ return $"{Name} ({Count})";
+ }
+ }
+
+ public class StationListItem
+ {
+ public string Name { get; set; }
+ public string Codec { get; set; }
+ public string Tags { get; set; }
+ public Uri Url { get; set; }
+
+ private string _country;
+ public string Country
+ {
+ get
+ {
+ if (_country.Length == 0)
+ return "🏴☠️";
+ return string.Concat(_country.ToUpper().Select(x => char.ConvertFromUtf32(x + 0x1F1A5))); // return emoji
+ }
+ set
+ {
+ _country = value;
+ }
+ }
+
+ private string _bitrate;
+ public string Bitrate
+ {
+ get
+ {
+ if (_bitrate == "0")
+ return "—";
+ return _bitrate.ToString();
+ }
+ set
+ {
+ _bitrate = value;
+ }
}
}
public partial class Radios : Window
{
- RadioBrowserClient _radioBrowser;
- List _stations = new List();
-
+ private RadioBrowserClient _radioBrowser;
private MPDHandler _mpd;
public Radios()
{
InitializeComponent();
+
_radioBrowser = new RadioBrowserClient();
+ Initialize();
}
- public async Task Search(string name)
+ public async void Initialize()
{
- var searchByName = await _radioBrowser.Search.ByNameAsync(name);
- Debug.WriteLine(searchByName.FirstOrDefault()?.Name);
- Debug.WriteLine("");
- }
-
- public async Task SearchAdvanced(string name)
- {
- Debug.Write(name);
-
- _stations.Clear();
- var advancedSearch = await _radioBrowser.Search.AdvancedAsync(new AdvancedSearchOptions
+ List Countries = await _radioBrowser.Lists.GetCountriesAsync();
+ CountryList.Items.Add(new CountryListItem { Name = "", Count = 0 });
+
+ foreach (NameAndCount Country in Countries)
{
- Name = name
- });
- foreach (var station in advancedSearch)
- _stations.Add(new StationView(station.Name, station.Url, station.Bitrate, station.Codec, station.CountryCode, station.Favicon));
- lvDataBinding.ItemsSource = _stations;
- ICollectionView view = CollectionViewSource.GetDefaultView(_stations);
- view.Refresh();
-
- Debug.WriteLine(_stations[0].Url.AbsoluteUri);
+ CountryList.Items.Add(new CountryListItem
+ {
+ Name = Country.Name,
+ Count = Country.Stationcount
+ });
+ }
}
- private void SelectionChanged(object sender, SelectionChangedEventArgs e)
+ private string CleanString(string str)
{
- Debug.WriteLine("Selected: {0}", e.AddedItems[0]);
+ return str.Replace("\r\n", "").Replace("\n", "").Replace("\r", "");
+ }
+
+ public async Task SearchAdvanced(string name, string country, string tags)
+ {
+ SearchStatus.Text = "Loading stations...";
+
+ List advancedSearch = await _radioBrowser.Search.AdvancedAsync(new AdvancedSearchOptions
+ {
+ Name = name,
+ Country = country,
+ TagList = tags
+ });
+
+ RadioListGrid.Items.Clear();
+ if (advancedSearch.Count > 0)
+ {
+ SearchStatus.Text = "";
+ foreach (StationInfo station in advancedSearch)
+ {
+ RadioListGrid.Items.Add(new StationListItem
+ {
+ Name = CleanString(station.Name),
+ Country = station.CountryCode,
+ Codec = station.Codec,
+ Bitrate = station.Bitrate.ToString(),
+ Url = station.Url,
+ Tags = string.Join(", ", station.Tags)
+ });
+ }
+ FitToContent();
+ }
+ else
+ SearchStatus.Text = "No stations found!";
+ }
+
+ private void FitToContent()
+ {
+ foreach (DataGridColumn column in RadioListGrid.Columns)
+ column.Width = new DataGridLength(1.0, DataGridLengthUnitType.SizeToCells);
+ }
+
+ private void Row_DoubleClick(object sender, MouseButtonEventArgs e)
+ {
+ DataGrid grid = sender as DataGrid;
+ StationListItem station;
+ try
+ {
+ station = grid.Items[grid.SelectedIndex] as StationListItem;
+ }
+ catch (System.ArgumentOutOfRangeException)
+ {
+ Debug.WriteLine("Error: Invalid index.");
+ return;
+ }
+
+ if (station.Url == null)
+ {
+ Debug.WriteLine("Error: Invalid station.");
+ return;
+ }
_mpd = (MPDHandler)Application.Current.Properties["mpd"];
_mpd.ClearQueue();
-
- StationView station = (StationView)e.AddedItems[0];
_mpd.AddSong(station.Url.AbsoluteUri);
_mpd.PlayCommand();
}
- public List GetStations()
- {
- return _stations;
- }
-
private async void Search_Clicked(object sender, RoutedEventArgs e)
{
- await SearchAdvanced(SearchBar.Text);
+ CountryListItem a = (CountryListItem)CountryList.SelectedItem;
+ await SearchAdvanced(NameSearch.Text, a?.Name, TagSearch.Text);
+ }
+
+ private void Reset_Clicked(object sender, RoutedEventArgs e)
+ {
+ NameSearch.Text = "";
+ TagSearch.Text = "";
+ CountryList.SelectedIndex = 0;
+ }
+
+ private void SearchHandler(object sender, KeyEventArgs e)
+ {
+ if (e.Key == Key.Return)
+ {
+ Search_Clicked(null, null);
+ }
}
private void Window_Closing(object sender, CancelEventArgs e)
@@ -104,4 +196,4 @@ namespace unison
helper.EnsureHandle();
}
}
-}
+}
\ No newline at end of file