public static async Task <Server[]> GetServers(string animeId) { return(await Task.Run(async() => { IConfiguration config = Configuration.Default; IBrowsingContext context = BrowsingContext.New(config); List <Server> servers = new List <Server>(); RestRequest request = new RestRequest(APINodes.GET_EPISODES(animeId)); RestResponse response = (RestResponse)client.Execute(request); if (response.IsSuccessful) { IDocument document = await context.OpenAsync(req => req.Content(response.Content)); IHtmlCollection <IElement> serverElements = document.QuerySelectorAll("section div.head .tabs.servers span"); foreach (IElement serverElement in serverElements) { Server server = new Server(int.Parse(serverElement.GetAttribute("data-id")), serverElement.TextContent); IHtmlCollection <IElement> episodeElements = document.QuerySelectorAll("section div.body a[data-sources]"); foreach (IElement episodeElement in episodeElements) { JObject dataSources = JObject.Parse(episodeElement.GetAttribute("data-sources")); server.Episodes.Add(new Episode(dataSources[server.Id.ToString()].ToString(), episodeElement.GetAttribute("href"), episodeElement.TextContent)); } servers.Add(server); } } RestRequest mcloudKeyRequest = new RestRequest("https://mcloud.to/key"); mcloudKeyRequest.AddHeader("Referer", client.BaseUrl.ToString()); RestResponse mcloudKeyResponse = (RestResponse)client.Execute(mcloudKeyRequest); if (mcloudKeyResponse.IsSuccessful) { Match match = Regex.Match(mcloudKeyResponse.Content, Patterns.REGEX_MCLOUDKEY); if (match.Success) { mcloudKey = match.Groups["key"].Value; } } return servers.ToArray(); })); }
public static async Task <string> GetVideoUrl(int serverId, string episodeId) { IConfiguration config = Configuration.Default; IBrowsingContext context = BrowsingContext.New(config); return(await Task.Run(async() => { RestRequest infoRequest = new RestRequest(APINodes.GET_EPISODEINFO(serverId, episodeId, mcloudKey)); RestResponse infoResponse = (RestResponse)client.Execute(infoRequest); if (infoResponse.IsSuccessful) { EpisodeInfoResponse info = JsonConvert.DeserializeObject <EpisodeInfoResponse>(infoResponse.Content); if (info != null) { string decryptedUrl = Decrypt(info.url); RestRequest request = new RestRequest(decryptedUrl); RestResponse response = (RestResponse)client.Execute(request); if (response.IsSuccessful) { switch (serverId) { case 28: // MyCloud { return string.Empty; // TODO } case 35: // Mp4upload { return string.Empty; // TODO } case 40: // Streamtape { IDocument document = await context.OpenAsync(req => req.Content(response.Content)); IElement videoElement = document.QuerySelector("#videolink"); return string.Format("https:{0}", videoElement.TextContent); } } } } } return string.Empty; })); }