public static Radio.RadioFull[] Add(Radio.RadioFull[] radios, Radio.RadioFull station) { Array.Resize(ref radios, radios.Length + 1); radios[radios.Length - 1] = station; Save(radios); return(radios); }
public static Radio.RadioFull[] Read() { try { var favorites = new Radio.RadioFull[0]; if (File.Exists(path)) { var FavoriteData = ""; FavoriteData = File.ReadAllText(path, Encoding.UTF8); favorites = JsonConvert.DeserializeObject <Radio.RadioFull[]>(FavoriteData); } else { File.Create(path); return(new Radio.RadioFull[0]); } return(favorites); } catch (Exception ex) { return(new Radio.RadioFull[0]); } }
private StackPanel CreateRadioButton(Radio.RadioFull radio, bool shadow = true) { StackPanel stack = new StackPanel { Width = 105, Height = 125, DataContext = radio, Background = new SolidColorBrush(Colors.White), Margin = new Thickness(3), Cursor = Cursors.Hand }; Label NameRadiostation = new Label { Content = radio.Name, Uid = radio.Name, Width = 105, HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Bottom, HorizontalContentAlignment = HorizontalAlignment.Center, FontSize = 14 }; Grid LabelGrid = new Grid { Width = 105 }; LabelGrid.Children.Add(NameRadiostation); if (Favorite.Coincidence(FavoriteRadio, radio.Name) && shadow) { LabelGrid.Background = (Brush)this.TryFindResource("BottomGradientRadio"); } Image cover = new Image { Margin = new Thickness(0, 7, 0, 0), Width = 90, Height = 90, Source = new BitmapImage(new Uri(radio.Picture)), Uid = radio.Name }; cover.PreviewMouseLeftButtonDown += Grid_PreviewMouseLeftButtonDown; LabelGrid.MouseEnter += LabelGrid_MouseEnter; LabelGrid.MouseLeave += LabelGrid_MouseLeave; LabelGrid.PreviewMouseLeftButtonDown += LabelGrid_PreviewMouseLeftButtonDown; stack.Children.Add(cover); stack.Children.Add(LabelGrid); stack.MouseLeave += Grid_MouseLeave; stack.MouseEnter += Grid_MouseEnter; return(stack); }
private void PlayRadio(Image panel) { Radio.RadioFull station = (GetData.GetParentStack(panel) as StackPanel).DataContext as Radio.RadioFull; station = GetStations.GetStream((panel.DataContext as Radio.RadioFull).Url, station); if (station != null) { StationJanre.Content = $"[{ station.Janre}]"; StationNameLabel.Content = station.Name; StationNameLabel.Uid = station.WhoPlay; StationCoverImage.ImageSource = new BitmapImage(new Uri(station.Picture)); StationWhoPlayLabel.Content = GetTrack.Get(station.WhoPlay); StationWhoPlayLabel.Uid = station.WhoPlay; FirstQualityButton.IsEnabled = true; FirstQualityButton.Background = (Brush)this.TryFindResource("GeneralColor"); FirstQualityButton.Content = station.QualityStream[0]; FirstQualityButton.Uid = station.Stream[0]; PlayGrid.DataContext = station; SecondQualityButton.IsEnabled = true; if (station.QualityStream[1] != null) { SecondQualityButton.Content = station.QualityStream[1]; SecondQualityButton.Uid = station.Stream[1]; } else { SecondQualityButton.Content = "-"; SecondQualityButton.IsEnabled = false; } FirstQualityButton.Background = (Brush)this.TryFindResource("GeneralColor"); SecondQualityButton.Background = new SolidColorBrush(Colors.WhiteSmoke); bool found = Favorite.Coincidence(FavoriteRadio, station.Name); if (found) { FavoriteRadioButton.Source = new BitmapImage(new Uri("pack://application:,,/Resources/Icons/pl_start_fav.png")); FavoriteRadioButton.Uid = "1"; } else { FavoriteRadioButton.Source = new BitmapImage(new Uri("pack://application:,,/Resources/Icons/pl_star.png")); FavoriteRadioButton.Uid = "0"; } PlayMusic(station.Stream[0]); } }
private void FavoriteRadioButton_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Radio.RadioFull data = PlayGrid.DataContext as Radio.RadioFull; if (FavoriteRadioButton.Uid.IndexOf("1") > -1) { RemoveFromFavoritePanel(data.Name); FavoriteRadioButton.Uid = "0"; FavoriteRadioButton.Source = new BitmapImage(new Uri("pack://application:,,/Resources/Icons/pl_star.png")); } else { AddToFavoritePanel(data); FavoriteRadioButton.Uid = "1"; FavoriteRadioButton.Source = new BitmapImage(new Uri("pack://application:,,/Resources/Icons/pl_start_fav.png")); } }
private void LabelGrid_MouseEnter(object sender, MouseEventArgs e) { Radio.RadioFull radio = (GetData.GetParentStack(sender as Grid) as StackPanel).DataContext as Radio.RadioFull; WrapPanel panel = GetData.GetWrapPanel(sender); Label label = (sender as Grid).Children[0] as Label; (sender as Grid).Background = null; if (Favorite.Coincidence(FavoriteRadio, radio.Name)) { label.Content = (String)this.TryFindResource("Delete"); } else { label.Content = (String)this.TryFindResource("ToFavorite"); } }
private void LabelGrid_MouseLeave(object sender, MouseEventArgs e) { Radio.RadioFull radio = (GetData.GetParentStack(sender as Grid) as StackPanel).DataContext as Radio.RadioFull; WrapPanel panel = GetData.GetWrapPanel(sender); Label label = (sender as Grid).Children[0] as Label; if (panel != null && radio != null) { if (panel.Name.IndexOf("Favorite_Radio_Wrap") == -1 && Favorite.Coincidence(FavoriteRadio, radio.Name)) { (sender as Grid).Background = (Brush)this.TryFindResource("BottomGradientRadio"); } else { (sender as Grid).Background = null; } label.Content = radio.Name; } }
private void LabelGrid_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { WrapPanel panel; Radio.RadioFull radio = (GetData.GetParentStack((sender as Grid)) as StackPanel).DataContext as Radio.RadioFull; Label label = (sender as Grid).Children[0] as Label; if (!SearchBox.IsVisible) { panel = Search_WrapPanel; } else { panel = GetData.GetWrapPanel(MainTab.SelectedItem as TabItem); } //delete from favorite if (String.Compare(label.Content.ToString(), (String)this.TryFindResource("Delete")) == 0) { if (PlayGrid.DataContext != null && String.Compare(radio.Name, (PlayGrid.DataContext as Radio.RadioFull).Name) == 0) { FavoriteRadioButton.Uid = "0"; FavoriteRadioButton.Source = new BitmapImage(new Uri("pack://application:,,/Res/star.png")); } RemoveFromFavoritePanel(radio.Name); label.Content = (String)this.TryFindResource("ToFavorite"); } //add to favorite else { if (PlayGrid.DataContext != null && String.Compare(radio.Name, (PlayGrid.DataContext as Radio.RadioFull).Name) == 0) { FavoriteRadioButton.Uid = "1"; FavoriteRadioButton.Source = new BitmapImage(new Uri("pack://application:,,/Res/fav.png")); } AddToFavoritePanel(radio); label.Content = (String)this.TryFindResource("Delete"); } }
public static Radio.RadioFull[] Get(object url) { var stations = new Radio.RadioFull[0]; var hw = new HtmlWeb(); var htmlDoc = hw.Load(url as string); var table = htmlDoc.GetElementbyId("catalog_items"); htmlDoc.LoadHtml(table.InnerHtml); var j = 0; foreach (var link in htmlDoc.DocumentNode.SelectNodes("//a[@href]")) { if (link.Attributes.Count < 1 || link.FirstChild == null || link.FirstChild.Attributes.Count < 1) { break; } Array.Resize(ref stations, stations.Length + 1); stations[j] = new Radio.RadioFull { Name = link.InnerText, Picture = "https://www.radiobells.com" + link.FirstChild.Attributes[0].Value, Url = "https://www.radiobells.com" + link.Attributes[0].Value }; j++; if (j == count) { break; } } return(stations); }
public static Radio.RadioFull GetStream(string url, Radio.RadioFull station) { try { var client = new WebClient(); client.Encoding = Encoding.UTF8; var parse = client.DownloadString(url); station.Site = GetSite(parse); parse = parse.Substring(parse.IndexOf("playradio"), parse.IndexOf("var colors") - parse.IndexOf("playradio")); parse = parse.Replace("\n", ""); var pattern = "\"(.*?)\""; var regex = new Regex(pattern); var match = regex.Match(parse); station.Stream = new string[2]; station.QualityStream = new string[2]; var matchCut = ""; for (var i = 0; match.Success; i++) { matchCut = match.Value; matchCut = matchCut.Trim('"'); switch (i) { case 0: station.Stream[0] = matchCut; break; case 1: if (match.Value.IndexOf("http://") == -1) { station.Stream[1] = null; } else { station.Stream[1] = matchCut; } break; case 4: station.WhoPlay = matchCut; break; case 6: station.QualityStream[0] = matchCut; break; case 7: if (station.Stream[1] == null) { station.QualityStream[1] = null; } else { station.QualityStream[1] = matchCut; } break; case 8: station.Janre = matchCut; break; } match = match.NextMatch(); } return(station); } catch (Exception ex) { return(null); } }
private void AddToFavoritePanel(Radio.RadioFull radio) { FavoriteRadio = Favorite.Add(FavoriteRadio, radio); Favorite_Radio_Wrap.Children.Add(CreateRadioButton(radio, false)); }