private async Task <JObject> HandleRelatedPlaylistAsync(Dictionary <string, object> queries) { try { byte[] data = await QuickHttp.SendAsync($"https://music.163.com/playlist?id={queries["id"]}", "Get", $"User-Agent: {Request.ChooseUserAgent("pc")}"); string s = Encoding.UTF8.GetString(data); var matchs = Regex.Matches(s, @"<div class=""cver u-cover u-cover-3"">[\s\S]*?<img src=""([^""]+)"">[\s\S]*?<a class=""sname f-fs1 s-fc0"" href=""([^""]+)""[^>]*>([^<]+?)<\/a>[\s\S]*?<a class=""nm nm f-thide s-fc3"" href=""([^""]+)""[^>]*>([^<]+?)<\/a>"); var playlists = new JArray(matchs.Cast <Match>().Select(match => new JObject { ["creator"] = new JObject { ["userId"] = match.Groups[4].Value.Substring("/user/home?id=".Length), ["nickname"] = match.Groups[5].Value }, ["coverImgUrl"] = match.Groups[1].Value.Substring(0, match.Groups[1].Value.Length - "?param=50y50".Length), ["name"] = match.Groups[3].Value, ["id"] = match.Groups[2].Value.Substring("/playlist?id=".Length), })); return(new JObject { ["code"] = 200, ["playlists"] = playlists }); } catch (Exception ex) { return(new JObject { ["code"] = 500, ["msg"] = ex.ToFullString() }); } }
private async Task <JObject> HandleLoginStatusAsync() { try { const string GUSER = "******"; const string GBINDS = "GBinds="; byte[] data = await QuickHttp.SendAsync("https://music.163.com", "Get", $"Cookie: {QuickHttp.ToCookieHeader(Cookies)}"); string s = Encoding.UTF8.GetString(data); int index = s.IndexOf(GUSER, StringComparison.Ordinal); if (index == -1) { return new JObject { ["code"] = 301 } } ; var json = new JObject { ["code"] = 200 }; using (var reader = new StringReader(s.Substring(index + GUSER.Length))) using (var jsonReader = new JsonTextReader(reader)) json.Add("profile", JObject.Load(jsonReader)); index = s.IndexOf(GBINDS, StringComparison.Ordinal); if (index == -1) { return new JObject { ["code"] = 301 } } ; using (var reader = new StringReader(s.Substring(index + GBINDS.Length))) using (var jsonReader = new JsonTextReader(reader)) json.Add("bindings", JArray.Load(jsonReader)); return(json); } catch { return(new JObject { ["code"] = 301 }); } }