public static async Task <string> GetToken(this NiconicoContext context) { var api = NiconicoUrls.MylistMyPageUrl; return(await context.GetStringAsync(api) .ContinueWith(x => x.Result.Substring(x.Result.IndexOf("NicoAPI.token = \"") + 17, 60))); }
public static async Task <MylistAdditionInfo> GetMylistToken(this NiconicoContext context, string group_id, string videoId) { var api = NiconicoUrls.MakeMylistAddVideoTokenApiUrl(videoId); var info = new MylistAdditionInfo() { GroupId = group_id }; var documentText = await context.GetStringAsync(api); var htmlDocument = new HtmlDocument(); htmlDocument.LoadHtml(documentText); { const string nicoAPIString = "NicoAPI.token = '"; var nicoAPIStartPosition = documentText.IndexOf(nicoAPIString); var token = new string(documentText .Skip(nicoAPIStartPosition + nicoAPIString.Length) .TakeWhile(x => '\'' != x) .ToArray() ); info.Token = token; } { var inputNodes = htmlDocument.DocumentNode.Descendants("input"); foreach (var inputNode in inputNodes) { if (!inputNode.Attributes.Contains("type")) { continue; } if (inputNode.Attributes["type"].Value != "hidden") { continue; } var kind = inputNode.Attributes["name"].Value; var value = inputNode.Attributes["value"].Value; info.Values.Add(kind, value); } } return(info); }