void OnSongParsed(RadioStationItem radio, Song song) { // Playlist returns true if need to display song if (_playlist.Add(song)) { Debug("New song on radio {0}: {1}-{2}", radio.RadioName, song.Artist, song.Title); } }
/// <summary> /// Parses and returns Song object for specifi radio station or NULL! /// </summary> /// <param name="radio"></param> public static Song Parse(RadioStationItem radio) { Song song = new Song(); song.PlayedAt = DateTime.Now; try { //Log4cs.Log(Importance.Debug, "Radio [{1}]{0}{2}", Environment.NewLine, radio.RadioName, radio.RawStationResponse); if(!string.IsNullOrEmpty(radio.RawStationResponse)) { int offset = 0; if( !string.IsNullOrEmpty(radio.beforeTitle) ) { // Use to place song title and artist position offset = radio.RawStationResponse.IndexOf(radio.beforeTitle, StringComparison.CurrentCultureIgnoreCase); } // Get song title Match m = radio.TitleRegex.Match(radio.RawStationResponse, offset); if(m.Success) { song.Title = m.Groups[radio.TitlePositon].ToString(); song.Title = StripTags(song.Title).Trim(); // TODO: clean HTML entities method song.Title = song.Title.Replace("#039;", "'"); } // Get song artist m = radio.ArtistRegex.Match(radio.RawStationResponse, offset); if(m.Success) { song.Artist = m.Groups[radio.ArtistPositon].ToString(); song.Artist = StripTags(song.Artist).Trim(); song.Artist = song.Artist.Replace("#039;", "'"); } } } catch(Exception ex) { Log4cs.Log(Importance.Error, "Error parsing response from radio station!"); Log4cs.Log(Importance.Debug, ex.ToString()); song = null; } return song; }
/// <summary> /// Parses and returns Song object for specifi radio station or NULL! /// </summary> /// <param name="radio"></param> public static Song Parse(RadioStationItem radio) { Song song = new Song(); song.PlayedAt = DateTime.Now; try { //Log4cs.Log(Importance.Debug, "Radio [{1}]{0}{2}", Environment.NewLine, radio.RadioName, radio.RawStationResponse); if (!string.IsNullOrEmpty(radio.RawStationResponse)) { int offset = 0; if (!string.IsNullOrEmpty(radio.beforeTitle)) { // Use to place song title and artist position offset = radio.RawStationResponse.IndexOf(radio.beforeTitle, StringComparison.CurrentCultureIgnoreCase); } // Get song title Match m = radio.TitleRegex.Match(radio.RawStationResponse, offset); if (m.Success) { song.Title = m.Groups[radio.TitlePositon].ToString(); song.Title = StripTags(song.Title).Trim(); // TODO: clean HTML entities method song.Title = song.Title.Replace("#039;", "'"); } // Get song artist m = radio.ArtistRegex.Match(radio.RawStationResponse, offset); if (m.Success) { song.Artist = m.Groups[radio.ArtistPositon].ToString(); song.Artist = StripTags(song.Artist).Trim(); song.Artist = song.Artist.Replace("#039;", "'"); } } } catch (Exception ex) { Log4cs.Log(Importance.Error, "Error parsing response from radio station!"); Log4cs.Log(Importance.Debug, ex.ToString()); song = null; } return(song); }
/// <summary> /// Reads and parses config file and creates task for each radio /// </summary> /// <param name="xmlConfigFile"></param> private static RadioStationItem[] LoadRadioList(string xmlConfigFile) { List<RadioStationItem> arStationsItems = new List<RadioStationItem>(); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlConfigFile); XmlElement xml = xmlDoc.DocumentElement; //XmlNode node = xml.ChildNodes[0]; if(xml.ChildNodes.Count > 0) { //arStationsItems = new RadioStationItem[xml.ChildNodes.Count]; bool isActive = false; //Log4cs.Log("There are {0}",); foreach(XmlNode radioNode in xml.ChildNodes) { RadioStationItem radio = new RadioStationItem(); //Log4cs.Log(radioNode.Name + ": " + radioNode.ChildNodes[0].Value); foreach(XmlNode var in radioNode.ChildNodes) { //Log4cs.Log(var.Name + ": " + var.ChildNodes[0].Value); switch(var.Name.ToLower()) { case "isactive": bool.TryParse(var.ChildNodes[0].Value, out isActive); radio.IsActive = isActive; break; case "title": radio.RadioName = var.ChildNodes[0].Value; break; case "titlemask": radio.TitleMask = var.ChildNodes[0].Value; break; case "titleposition": radio.ArtistPositon = Int32.Parse(var.ChildNodes[0].Value); break; case "artistemask": radio.ArtistMask = var.ChildNodes[0].Value; break; case "artistposition": radio.TitlePositon = Int32.Parse(var.ChildNodes[0].Value); break; case "url": radio.Url = var.ChildNodes[0].Value; break; case "beforetitle": if( var.HasChildNodes ) { radio.beforeTitle = var.ChildNodes[0].Value; } break; default: break; } // END SWITCH } // END FOREACH ( list all item parameter ) if( radio.IsActive ) { arStationsItems.Add(radio); } } // END FOREACH ( list all items ) } // END IF if(arStationsItems != null) { Log4cs.Log("Radio station list:"); for(int i = 0; i < arStationsItems.Count; i++) { Log4cs.Log("\t{0}", arStationsItems[i].ToString()); } } } catch(Exception ex) { Log4cs.Log("Error parsing " + xmlConfigFile, Importance.Error); Log4cs.Log(ex.ToString(), Importance.Debug); } return arStationsItems.Count > 0 ? arStationsItems.ToArray() : null; }
/// <summary> /// Reads and parses config file and creates task for each radio /// </summary> /// <param name="xmlConfigFile"></param> private static RadioStationItem[] LoadRadioList(string xmlConfigFile) { List <RadioStationItem> arStationsItems = new List <RadioStationItem>(); try { XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load(xmlConfigFile); XmlElement xml = xmlDoc.DocumentElement; //XmlNode node = xml.ChildNodes[0]; if (xml.ChildNodes.Count > 0) { //arStationsItems = new RadioStationItem[xml.ChildNodes.Count]; bool isActive = false; //Log4cs.Log("There are {0}",); foreach (XmlNode radioNode in xml.ChildNodes) { RadioStationItem radio = new RadioStationItem(); //Log4cs.Log(radioNode.Name + ": " + radioNode.ChildNodes[0].Value); foreach (XmlNode var in radioNode.ChildNodes) { //Log4cs.Log(var.Name + ": " + var.ChildNodes[0].Value); switch (var.Name.ToLower()) { case "isactive": bool.TryParse(var.ChildNodes[0].Value, out isActive); radio.IsActive = isActive; break; case "title": radio.RadioName = var.ChildNodes[0].Value; break; case "titlemask": radio.TitleMask = var.ChildNodes[0].Value; break; case "titleposition": radio.ArtistPositon = Int32.Parse(var.ChildNodes[0].Value); break; case "artistemask": radio.ArtistMask = var.ChildNodes[0].Value; break; case "artistposition": radio.TitlePositon = Int32.Parse(var.ChildNodes[0].Value); break; case "url": radio.Url = var.ChildNodes[0].Value; break; case "beforetitle": if (var.HasChildNodes) { radio.beforeTitle = var.ChildNodes[0].Value; } break; default: break; } // END SWITCH } // END FOREACH ( list all item parameter ) if (radio.IsActive) { arStationsItems.Add(radio); } } // END FOREACH ( list all items ) } // END IF if (arStationsItems != null) { Log4cs.Log("Radio station list:"); for (int i = 0; i < arStationsItems.Count; i++) { Log4cs.Log("\t{0}", arStationsItems[i].ToString()); } } } catch (Exception ex) { Log4cs.Log("Error parsing " + xmlConfigFile, Importance.Error); Log4cs.Log(ex.ToString(), Importance.Debug); } return(arStationsItems.Count > 0 ? arStationsItems.ToArray() : null); }
void OnSongParsed(RadioStationItem radio, Song song) { // Playlist returns true if need to display song if(_playlist.Add(song)) { Debug("New song on radio {0}: {1}-{2}", radio.RadioName, song.Artist, song.Title); } }