public VM管理(番组 bgm = null) { Search = new DelegateCommand((o) => _Search()); VisitHP = new DelegateCommand((o) => _VisitHP()); VisitBgm = new DelegateCommand((o) => _VisitBgm()); EditBgm = new DelegateCommand((o) => _EditBgm(o)); EditAnime = new DelegateCommand((o) => _EditAnime(o)); OpenAnime = new DelegateCommand((o) => _OpenAnime()); AddBgm = new DelegateCommand((o) => _AddBgm(o)); DelBgm = new DelegateCommand((o) => _DelBgm()); DelAnime = new DelegateCommand((o) => _DelAnime()); WinClose = new DelegateCommand((o) => _WinClose()); DropBgm = new DelegateCommand((o) => _DropBgm(o)); UpdateInfo = new DelegateCommand((o) => _UpdateInfo()); MusicInfo = new DelegateCommand((o) => _MusicInfo()); if (bgm != null) { BgmList = new ObservableCollection <番组>() { bgm }; SelectedBangumi = bgm; } }
public static 番组 解析信息(string code, 番组 bgm) { var url = "http://bangumi.tv/subject/" + code; try { WebClient client = new WebClient(); byte[] data = client.DownloadData(url); string page = Encoding.UTF8.GetString(data); int s = page.IndexOf("<h1 class"); int e = page.IndexOf("</h1>"); string title = page.Substring(s, e - s); s = page.IndexOf("<ul id=\"infobox\">"); e = page.IndexOf("</ul>", s); string info = page.Substring(s, e - s); string temp = Regex.Match(title, ">.+</a>").Value; bgm.原名 = temp.Substring(1, temp.Length - 5); var result = new string[6]; string[] infos = new string[] { "中文名: ", "放送开始: ", "原作: ", "动画制作: ", "官方网站: ", "话数: " }; for (int i = 0; i < 6; i++) { temp = Regex.Match(info, infos[i] + ".+</li>").Value; if (string.IsNullOrEmpty(temp)) { continue; } result[i] = Regex.Replace(temp, "<.+?>", string.Empty).Remove(0, infos[i].Length); } bgm.译名 = result[0]; result[1] = Regex.Replace(result[1], "年|月|日", "/").Trim('/'); if (string.IsNullOrEmpty(bgm.版权链接)) { bgm.首播 = DateTime.Parse(result[1]); } bgm.原作 = result[2]; bgm.动画制作 = result[3]; bgm.官网 = result[4]; int hs = 0; int.TryParse(result[5], out hs); bgm.话数 = hs; return(bgm); } catch { return(bgm); } }
public VM番组(番组 Bgm = null) { OK = new DelegateCommand((o) => _OK()); Go = new DelegateCommand((o) => _Go()); Bangumi = Bgm ?? new 番组(); }