/// <summary> /// 通过HAP插件解析网页内容,获取Ranked歌曲列表 /// </summary> /// <param name="html">网页的文本内容</param> /// <returns>BeatMap列表</returns> private List<BeatMap> GetBeatMapsListByHAP(ConfigModel xpModel) { List<BeatMap> beatMaps = new List<BeatMap>(); beatMaps.Clear(); HtmlDocument hDoc = new HtmlWeb().Load(xpModel.WebRankListUrl); //加载网页,实例化对象。 HtmlNode rootNode = hDoc.DocumentNode; HtmlNodeCollection categoryNodeList = rootNode.SelectNodes(xpModel.CategoryListXPath); //定位HTML标签至遍历处,获取内容(包含BeatMapList列表集合) HtmlNode temp = null; BeatMap beatMap = null; foreach (HtmlNode categoryNode in categoryNodeList) { temp = HtmlNode.CreateNode(categoryNode.OuterHtml); //获取一个包含BeatMapList的内容。 //读出值: beatMap = new BeatMap(); beatMap.Id = temp.SelectSingleNode(xpModel.IdXPath).GetAttributeValue("Id", 0000); beatMap.Title = temp.SelectSingleNode(xpModel.TitleXPath).InnerText; beatMap.Artist = temp.SelectSingleNode(xpModel.ArtistXPath).InnerText; beatMap.Mapper = temp.SelectSingleNode(xpModel.MapperXPath).InnerText; beatMap.Styles = temp.SelectSingleNode(xpModel.StylesXPath).InnerText; beatMap.Language = temp.SelectSingleNode(xpModel.LanguageXPath).InnerText; if (temp.SelectSingleNode(xpModel.SbXPath) != null) { beatMap.Sb = temp.SelectSingleNode(xpModel.SbXPath).GetAttributeValue("class", "NoSb"); } else { beatMap.Sb = "NoSb"; } beatMaps.Add(beatMap); } return beatMaps; }
/// <summary> /// 用XML文件初始化Config对象 /// </summary> /// <param name="xe">xml</param> /// <returns>Config对象</returns> private ConfigModel ReadTo_ConfigModel(XElement xe) { ConfigModel config = new ConfigModel(); config.WebRankListUrl = xe.Element("WebRankListUrl").Value; config.CategoryListXPath = xe.Element("CategoryListXPath").Value; config.IdXPath = xe.Element("IdXPath").Value; config.TitleXPath = xe.Element("TitleXPath").Value; config.ArtistXPath = xe.Element("ArtistXPath").Value; config.MapperXPath = xe.Element("MapperXPath").Value; config.StylesXPath = xe.Element("StylesXPath").Value; config.LanguageXPath = xe.Element("LanguageXPath").Value; config.SbXPath = xe.Element("SbXPath").Value; config.PictureUrl = xe.Element("PictureUrl").Value; config.SongTasteUrl = xe.Element("SongTasteUrl").Value; config.DownUrl_osz_so = xe.Element("DownUrl_osz_so").Value; return config; }
/// <summary> /// 获取osu官网最新Rank的歌曲列表 /// </summary> /// <param name="config">程序配置信息</param> /// <returns>歌曲列表</returns> public List<BeatMap> GetBeatMaps(ConfigModel config) { List<BeatMap> beatMaps = GetBeatMapsListByHAP(config); return beatMaps; }
public string ToBeatMapDownUrl(ConfigModel cfg, string id) { return Path.Combine(cfg.DownUrl_osz_so, id); }