/// <summary> /// Gets the specified stationid. /// </summary> /// <param name="stationid">The station id.</param> public void Get(string stationid) { var gr = new RadioTime(); gr.Settings = Grabber.Settings; GuidId = stationid; var url = string.Format("http://opml.radiotime.com/Describe.ashx?c=nowplaying&id={0}&{1}", GuidId, Grabber.Settings.GetParamString()); gr.GetData(url, false, false); var line = 0; foreach (var outline in gr.Body) { if (outline.Key == "station") { Image = outline.Image; Name = outline.Text; PresetId = outline.PresetId; GuidId = outline.GuidId; } if (outline.Key == "show") { ShowImage = string.Format("http://radiotime-logos.s3.amazonaws.com/{0}.png", GuidId); Description = outline.Text; var i = 0; if (int.TryParse(outline.Duration, out i)) { Duration = i; } i = 0; if (int.TryParse(outline.Remain, out i)) { Remains = i; } } switch (line) { case 1: Description = outline.Text; break; case 2: Location = outline.Text; break; } line++; } if (string.IsNullOrEmpty(ShowImage)) { ShowImage = Image; } }
public RadioTime(RadioTime parent) { this.Head = new RadioTimeHead(parent.Head); this.Body = new List<RadioTimeOutline>(parent.Body); this.Settings = new RadioTimeSetting(parent.Settings); this.ParentUrl = parent.ParentUrl; this.CurentUrl = parent.CurentUrl; this.Parent = parent.Parent; this.Cache = parent.Cache; this.NavigationTitle = parent.NavigationTitle; }
public RadioTime(RadioTime parent) { Head = new RadioTimeHead(parent.Head); Body = new List <RadioTimeOutline>(parent.Body); Settings = new RadioTimeSetting(parent.Settings); ParentUrl = parent.ParentUrl; CurentUrl = parent.CurentUrl; Parent = parent.Parent; Cache = parent.Cache; NavigationTitle = parent.NavigationTitle; }
public override bool Init() { grabber = new RadioTime(); updateStationLogoTimer.AutoReset = true; updateStationLogoTimer.Enabled = false; updateStationLogoTimer.Elapsed -= OnDownloadTimedEvent; updateStationLogoTimer.Elapsed += OnDownloadTimedEvent; Client.DownloadFileCompleted += Client_DownloadFileCompleted; return Load(GUIGraphicsContext.Skin + @"\RadioTimePresets.xml"); }
public override bool Init() { grabber = new RadioTime(); updateStationLogoTimer.AutoReset = true; updateStationLogoTimer.Enabled = false; updateStationLogoTimer.Elapsed -= new ElapsedEventHandler(OnDownloadTimedEvent); updateStationLogoTimer.Elapsed += new ElapsedEventHandler(OnDownloadTimedEvent); Client.DownloadFileCompleted += new System.ComponentModel.AsyncCompletedEventHandler(Client_DownloadFileCompleted); return Load(GUIGraphicsContext.Skin + @"\RadioTimePresets.xml"); }
public string GetPresetFolder() { var tempGrabber = new RadioTime(); tempGrabber.Settings = _setting; tempGrabber.GetData(_setting.PresetsUrl, false, Translation.Presets); var dlg = (GUIDialogMenu) GUIWindowManager.GetWindow((int) Window.WINDOW_DIALOG_MENU); if (dlg == null) return null; dlg.Reset(); dlg.SetHeading(Translation.SelectPresetFolder); var canShow = false; foreach (var body in tempGrabber.Body) { if (body.Type == RadioTimeOutline.OutlineType.link) { dlg.Add(body.Text); canShow = true; } } if (canShow) { dlg.DoModal(GetID); if (dlg.SelectedId == -1) return null; return tempGrabber.Body[dlg.SelectedId - 1].GuidId; } else return noPresetFolders; }
public Form1() { InitializeComponent(); grabber = new RadioTime(); }
/// <summary> /// Get and parse the online data. /// </summary> /// <param name="sUrl">The s URL.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="useNavigationLogic">if set to <c>true</c> [use navigation logic].</param> /// <param name="navigationTitle">navigation title.</param> /// <returns></returns> public bool GetData(string sUrl, bool useCache, bool useNavigationLogic, string navigationTitle) { //Log.Debug("GetData " + sUrl); if (string.IsNullOrEmpty(sUrl)) return false; CacheIsUsed = useCache; if (useCache && Cache.ContainsKey(sUrl)) { if (useNavigationLogic) Parent = new RadioTime(this); ParentUrl = CurentUrl; CurentUrl = sUrl; Head = new RadioTimeHead(Cache[sUrl].Head); Body = new List<RadioTimeOutline>(Cache[sUrl].Body); if (useNavigationLogic) { string properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return true; } else { Stream response = RetrieveData(sUrl); if (response != null) { if (sUrl != CurentUrl) { if (useNavigationLogic) { Parent = new RadioTime(this); } ParentUrl = CurentUrl; CurentUrl = sUrl; } // Get the stream associated with the response. StreamReader reader = new StreamReader(response, System.Text.Encoding.UTF8, true); String sXmlData = reader.ReadToEnd().Replace('\0', ' '); response.Close(); reader.Close(); try { XmlDocument doc = new XmlDocument(); doc.LoadXml(sXmlData); // skip xml node XmlNode root = doc.FirstChild.NextSibling; XmlNode headnodetitle = root.SelectSingleNode("head/title"); if (headnodetitle != null) { Head.Title = headnodetitle.InnerText.Trim(); } else { Head.Title = ""; } XmlNodeList bodynodes = root.SelectNodes("body/outline"); Body.Clear(); foreach (XmlNode node in bodynodes) { if (node.HasChildNodes) { foreach (XmlNode childnode in node.ChildNodes) { Body.Add(new RadioTimeOutline(childnode)); } } else { Body.Add(new RadioTimeOutline(node)); } } if (useCache) { Cache.Add(sUrl, new RadioTime(this)); } } catch (XmlException) { return false; } response.Close(); if (useNavigationLogic) { string properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return true; } return true; } }
/// <summary> /// Gets the specified stationid. /// </summary> /// <param name="stationid">The station id.</param> /// <param name="hassong">The station hass song or not</param> public void Get(string stationid, bool hassong) { var gr = new RadioTime(); gr.Settings = Grabber.Settings; GuidId = stationid; var url = string.Format("http://opml.radiotime.com/Describe.ashx?c=nowplaying&id={0}&{1}", GuidId, Grabber.Settings.GetParamString()); gr.GetData(url, false, false); var line = 0; foreach (var outline in gr.Body) { if (outline.Key == "station") { Image = outline.Image; Name = outline.Text; PresetId = outline.PresetId; GuidId = outline.GuidId; } if (outline.Key == "show") { // ShowImage = string.Format("http://radiotime-logos.s3.amazonaws.com/{0}.png", GuidId); ShowImage = string.Format("http://cdn-radiotime-logos.tunein.com/{0}.png", GuidId); Description = outline.Text; IsShow = true; ShowGuidId = outline.GuidId; var i = 0; if (int.TryParse(outline.Duration, out i)) { Duration = i; } i = 0; if (int.TryParse(outline.Remain, out i)) { Remains = i; } continue; } switch (line) { case 1: // if station has song then [Artists - Song] else [Description] if (!hassong) { Description = (string.IsNullOrEmpty(Description) ? "" : " - ") + outline.Text; } break; case 2: // if station has song then [Genre | Description] else if Show [Other] else [Location] if (hassong) { // Description = outline.Text; Description = string.Empty; } else { if (IsShow) // !Show { Location = outline.Text; } } break; case 3: // if station has song then [Location] if (hassong) { Location = outline.Text; } break; } line++; } if (string.IsNullOrEmpty(ShowImage)) { ShowImage = Image; } }
/// <summary> /// Gets the specified stationid. /// </summary> /// <param name="stationid">The station id.</param> /// <param name="hassong">The station hass song or not</param> public void Get(string stationid, bool hassong) { var gr = new RadioTime(); gr.Settings = Grabber.Settings; GuidId = stationid; var url = string.Format("http://opml.radiotime.com/Describe.ashx?c=nowplaying&id={0}&{1}", GuidId, Grabber.Settings.GetParamString()); gr.GetData(url, false, false); var line = 0; foreach (var outline in gr.Body) { if (outline.Key == "station") { Image = outline.Image; Name = outline.Text; PresetId = outline.PresetId; GuidId = outline.GuidId; } if (outline.Key == "show") { // ShowImage = string.Format("http://radiotime-logos.s3.amazonaws.com/{0}.png", GuidId); ShowImage = string.Format("http://cdn-radiotime-logos.tunein.com/{0}.png", GuidId); Description = outline.Text; IsShow = true; ShowGuidId = outline.GuidId; var i = 0; if (int.TryParse(outline.Duration, out i)) Duration = i; i = 0; if (int.TryParse(outline.Remain, out i)) Remains = i; continue; } switch (line) { case 1: // if station has song then [Artists - Song] else [Description] if (!hassong) { Description = (string.IsNullOrEmpty(Description) ? "" : " - ") + outline.Text; } break; case 2: // if station has song then [Genre | Description] else if Show [Other] else [Location] if (hassong) { // Description = outline.Text; Description = string.Empty; } else { if (IsShow) // !Show { Location = outline.Text; } } break; case 3: // if station has song then [Location] if (hassong) { Location = outline.Text; } break; } line++; } if (string.IsNullOrEmpty(ShowImage)) ShowImage = Image; }
/// <summary> /// Gets the specified stationid. /// </summary> /// <param name="stationid">The station id.</param> public void Get(string stationid) { RadioTime gr = new RadioTime(); gr.Settings = Grabber.Settings; GuidId = stationid; string url = string.Format("http://opml.radiotime.com/Describe.ashx?c=nowplaying&id={0}&{1}", GuidId, Grabber.Settings.GetParamString()); gr.GetData(url,false, false); int line = 0; foreach (RadioTimeOutline outline in gr.Body) { if (outline.Key == "station") { Image = outline.Image; Name = outline.Text; PresetId = outline.PresetId; GuidId = outline.GuidId; } if (outline.Key == "show") { ShowImage = string.Format("http://radiotime-logos.s3.amazonaws.com/{0}.png", GuidId); Description = outline.Text; int i = 0; if (int.TryParse(outline.Duration, out i)) Duration = i; i = 0; if (int.TryParse(outline.Remain, out i)) Remains = i; } switch (line) { case 1: Description = outline.Text; break; case 2: Location = outline.Text; break; } line++; } if (string.IsNullOrEmpty(ShowImage)) ShowImage = Image; }
/// <summary> /// Get and parse the online data. /// </summary> /// <param name="sUrl">The s URL.</param> /// <param name="useCache">if set to <c>true</c> [use cache].</param> /// <param name="useNavigationLogic">if set to <c>true</c> [use navigation logic].</param> /// <param name="navigationTitle">navigation title.</param> /// <returns></returns> public bool GetData(string sUrl, bool useCache, bool useNavigationLogic, string navigationTitle) { //Log.Debug("GetData " + sUrl); if (string.IsNullOrEmpty(sUrl)) { return(false); } CacheIsUsed = useCache; if (useCache && Cache.ContainsKey(sUrl)) { if (useNavigationLogic) { Parent = new RadioTime(this); } ParentUrl = CurentUrl; CurentUrl = sUrl; Head = new RadioTimeHead(Cache[sUrl].Head); Body = new List <RadioTimeOutline>(Cache[sUrl].Body); if (useNavigationLogic) { var properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return(true); } else { var response = RetrieveData(sUrl); if (response != null) { if (sUrl != CurentUrl) { if (useNavigationLogic) { Parent = new RadioTime(this); } ParentUrl = CurentUrl; CurentUrl = sUrl; } // Get the stream associated with the response. var reader = new StreamReader(response, Encoding.UTF8, true); var sXmlData = reader.ReadToEnd().Replace('\0', ' '); response.Close(); reader.Close(); try { var doc = new XmlDocument(); doc.LoadXml(sXmlData); // skip xml node var root = doc.FirstChild.NextSibling; var headnodetitle = root.SelectSingleNode("head/title"); if (headnodetitle != null) { Head.Title = headnodetitle.InnerText.Trim(); } else { Head.Title = ""; } var bodynodes = root.SelectNodes("body/outline"); Body.Clear(); foreach (XmlNode node in bodynodes) { if (node.HasChildNodes) { foreach (XmlNode childnode in node.ChildNodes) { Body.Add(new RadioTimeOutline(childnode)); } } else { Body.Add(new RadioTimeOutline(node)); } } if (useCache) { Cache.Add(sUrl, new RadioTime(this)); } } catch (XmlException) { return(false); } response.Close(); if (useNavigationLogic) { var properTitle = Head.Title == string.Empty ? navigationTitle : Head.Title; NavigationTitle = NavigationTitle == string.Empty ? properTitle : NavigationTitle + " / " + properTitle; Parent.NavigationTitle = NavigationTitle; } return(true); } return(true); } }
/// <summary> /// Adds to favorites. /// </summary> /// <param name="p">The station id.</param> private void AddToFavorites(string presetid) { List<RadioTimeOutline> tempresets = new List<RadioTimeOutline>(); string folderid = ""; string selectedID = ""; RadioTime tempGrabber = new RadioTime(); tempGrabber.Settings = _setting; tempGrabber.GetData(_setting.PresetsUrl, false, false, Translation.Presets); int folderCount = 0; foreach (RadioTimeOutline body in tempGrabber.Body) { if (body.Type == RadioTimeOutline.OutlineType.link) folderCount++; } if (folderCount == 0) // only one preset folder (main) - plugin chooses first empty space to put preset { // first i have to fill the list with taken preset numbers List<int> takenPresets = new List<int>(); foreach (RadioTimeOutline body in tempGrabber.Body) { if (!string.IsNullOrEmpty(body.PresetNumber)) takenPresets.Add(body.PresetNumberAsInt); } int i = 1; while (takenPresets.Contains(i)) // find empty space i++; selectedID = i.ToString(); } else // more folders - ask user { var dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU); if (dlg == null) return; dlg.Reset(); dlg.SetHeading(Translation.SelectPresetFolder); foreach (RadioTimeOutline body in tempGrabber.Body) { if (body.Type == RadioTimeOutline.OutlineType.link) dlg.Add(body.Text); } dlg.DoModal(GetID); if (dlg.SelectedId == -1) return; folderid = tempGrabber.Body[dlg.SelectedId - 1].GuidId; tempGrabber.GetData(tempGrabber.Body[dlg.SelectedId - 1].Url, false, false); // first i have to find out the largest preset number int biggestPresetNumber = 0; foreach (RadioTimeOutline body in tempGrabber.Body) { if (!string.IsNullOrEmpty(body.PresetNumber) && body.PresetNumberAsInt > biggestPresetNumber) biggestPresetNumber = body.PresetNumberAsInt; } // then i fill x number of presets for (int i = 0; i < (biggestPresetNumber + Settings.LOCAL_PRESETS_NUMBER); i++) { tempresets.Add(new RadioTimeOutline()); } // then i fill the list with existing presets from the folder foreach (RadioTimeOutline body in tempGrabber.Body) { if (!string.IsNullOrEmpty(body.PresetNumber) && body.PresetNumberAsInt-1 < tempresets.Count) { tempresets[body.PresetNumberAsInt-1] = body; } } dlg.Reset(); dlg.SetHeading(Translation.SelectPresetNumber); for (int i = 0; i < tempresets.Count; i++) { RadioTimeOutline outline = tempresets[i]; if (string.IsNullOrEmpty(outline.Text)) dlg.Add(string.Format("<{0}>", Translation.Empty)); else dlg.Add(outline.Text); } dlg.DoModal(GetID); if (dlg.SelectedId == -1) return; selectedID = dlg.SelectedId.ToString(); } try { grabber.AddPreset(presetid, folderid, selectedID); //UpdateList(); } catch (Exception) { ErrMessage(Translation.ComunicationError); } }
//// do the clicked action protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { //// //// look for button pressed //// //// record ? if (actionType == Action.ActionType.ACTION_RECORD) { //ExecuteRecord(); } else if (control == btnSwitchView) { switch ((View)mapSettings.ViewAs) { case View.List: mapSettings.ViewAs = (int)View.Icons; break; case View.Icons: mapSettings.ViewAs = (int)View.BigIcons; break; case View.BigIcons: mapSettings.ViewAs = (int)View.List; break; } ShowPanel(); // GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == listControl) { // execute only for enter keys if (actionType == Action.ActionType.ACTION_SELECT_ITEM) { // station selected DoListSelection(); } } else if (control == sortButton) { //sort button selected OnShowSortOptions(); GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == searchArtistButton) { DoSearchArtist(); GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == searchButton) { DoSearch(); GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == homeButton) { ShowPanel(); DoHome(); GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == genresButton) { ShowPanel(); DoGenres(); GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == presetsButton) { ShowPanel(); DoPresets(); GUIControl.FocusControl(GetID, listControl.GetID); } else if (control == nowPlayingButton) { GUIWindowManager.ActivateWindow(25652); } else if (control == localpresetsButton) { GUIWindowManager.ActivateWindow(25653); } else if (control == randomButton) { GUIControl.FocusControl(GetID, listControl.GetID); RadioTime gr = new RadioTime(); gr.Settings = grabber.Settings; gr.GetData(grabber.CurentUrl + "&filter=random"); if (gr.Body.Count == 1) { if (!string.IsNullOrEmpty(gr.Body[0].GuidId)) DoPlay(gr.Body[0]); else if (!string.IsNullOrEmpty(gr.Body[0].Text)) ErrMessage(gr.Body[0].Text); } else ErrMessage(Translation.NoStationsOrShowsAvailable); } base.OnClicked(controlId, control, actionType); }