public override async Task <string> Handle(HttpRequest request, HttpResponse response) { string userAgent = request.Headers["User-Agent"].ToString(); var headers = new Dictionary <string, string> { { "User-Agent", userAgent } }; string script = await HTTPUtility.GetRequestAsync("http://getlist5.obovse.ru/jsapp/app.js.php?run=js", headers); string path = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "wwwroot", "forkplayer"); string filePath = Path.Combine(path, "forkplayer.js"); if (string.IsNullOrEmpty(script) || script.Length < 1024) { if (File.Exists(filePath)) { script = await File.ReadAllTextAsync(filePath); } } else { CreateDirectoryRecursively(path); using (var outputFile = new StreamWriter(filePath, false)) { await outputFile.WriteAsync(script); } } return(script); }
public async Task <string> CurlRequest(string text) { string result; if (text.StartsWith("curlorig")) { Log.LogDebug("curlorig " + text.Substring(9)); result = await HTTPUtility.GetRequestAsync(text.Substring(9)); } else { bool verbose = text.IndexOf(" -i", StringComparison.Ordinal) > 0; bool autoredirect = text.IndexOf(" -L", StringComparison.Ordinal) > 0; string url = Regex.Match(text, "(?:\")(.*?)(?=\")").Groups[1].Value; var matches = Regex.Matches(text, "(?:-H\\s\")(.*?)(?=\")"); var header = ( from Match match in matches select match.Groups into groups where groups.Count > 1 select groups[1].Value into value where value.Contains(": ") select value).ToDictionary(value => value.Remove(value.IndexOf(": ", StringComparison.Ordinal)), value => value.Substring(value.IndexOf(": ", StringComparison.Ordinal) + 2)); if (text.Contains("--data")) { Log.LogDebug("POST DATA"); try { string dataString = Regex.Match(text, "(?:--data\\s\")(.*?)(?=\")").Groups[1].Value; result = await HTTPUtility.PostRequestAsync(url, dataString, header, verbose, autoredirect); } catch (Exception e) { result = e.ToString(); Log.LogDebug(e.ToString()); } } else { Log.LogInformation(url); result = await HTTPUtility.GetRequestAsync(url, header, verbose, autoredirect); } } return(result); }
public async Task <string> GetFileList(Dictionary <string, string> files, string key, string type) { var items = new List <Item>(); if (files.Count > 0) { if (files.Count > 1) { string stream = string.Format("{0}/ace/getstream?{1}={2}", AceStreamEngine.GetServer, type, key); return(await HTTPUtility.GetRequestAsync(stream)); } else { string stream = string.Format("{0}/ace/getstream?{1}={2}", AceStreamEngine.GetServer, type, key); string name = Path.GetFileName(files.First().Value); var item = new Item() { Name = Path.GetFileName(name), ImageLink = "http://obovse.ru/ForkPlayer2.5/img/file.png", Link = stream, Type = ItemType.FILE }; items.Add(item); stream = string.Format("{0}/ace/manifest.m3u8?{1}={2}", AceStreamEngine.GetServer, type, key); item = new Item() { Name = "(hls) " + Path.GetFileName(name), ImageLink = "http://obovse.ru/ForkPlayer2.5/img/file.png", Link = stream, Type = ItemType.FILE }; items.Add(item); } } var playlist = new Playlist { Items = items.ToArray() }; return(ResponseSerializer.PlaylistToXml(playlist)); }
public async Task <string> GetFileList(Dictionary <string, string> files, string key, string type) { var items = new List <IItem>(); if (files.Count > 0) { if (files.Count > 1) { string stream = string.Format("{0}/ace/getstream?{1}={2}", AceStreamEngine.GetServer, type, key); return(await HTTPUtility.GetRequestAsync(stream)); } else { string stream = string.Format("{0}/ace/getstream?{1}={2}", AceStreamEngine.GetServer, type, key); string name = Path.GetFileName(files.First().Value); var item = new FileItem() { Title = Path.GetFileName(name), ImageLink = "http://obovse.ru/ForkPlayer2.5/img/file.png", Link = stream }; items.Add(item); stream = string.Format("{0}/ace/manifest.m3u8?{1}={2}", AceStreamEngine.GetServer, type, key); item = new FileItem() { Title = "(hls) " + Path.GetFileName(name), ImageLink = "http://obovse.ru/ForkPlayer2.5/img/file.png", Link = stream }; items.Add(item); } } return(ResponseManager.CreateResponse(items)); }
public override async Task <string> Handle(HttpRequest request, HttpResponse response) { string result = string.Empty; Log.LogDebug(request.Host.ToUriComponent()); var requestStrings = HttpUtility.UrlDecode(request.QueryString.Value)?.Substring(1).Split('|'); if (request.Method == "POST") { var getPostParam = new StreamReader(request.Body, true); string postData = getPostParam.ReadToEnd(); requestStrings = HttpUtility.UrlDecode(postData).Substring(2).Split('|'); } if (requestStrings != null) { Log.LogDebug("Parsing: {0}", requestStrings[0]); string curlResponse = requestStrings[0].StartsWith("curl") ? await CurlRequest(requestStrings[0]) : await HTTPUtility.GetRequestAsync(requestStrings[0]); if (requestStrings.Length == 1) { result = curlResponse; } else { if (!requestStrings[1].Contains(".*?")) { if (string.IsNullOrEmpty(requestStrings[1]) && string.IsNullOrEmpty(requestStrings[2])) { result = curlResponse; } else { int num1 = curlResponse.IndexOf(requestStrings[1], StringComparison.Ordinal); if (num1 == -1) { result = string.Empty; } else { num1 += requestStrings[1].Length; int num2 = curlResponse.IndexOf(requestStrings[2], num1, StringComparison.Ordinal); result = num2 == -1 ? string.Empty : curlResponse.Substring(num1, num2 - num1); } } } else { Log.LogDebug("ParseLinkRequest: {0}", requestStrings[1] + "(.*?)" + requestStrings[2]); string pattern = requestStrings[1] + "(.*?)" + requestStrings[2]; var regex = new Regex(pattern, RegexOptions.Multiline); var match = regex.Match(curlResponse); if (match.Success) { result = match.Groups[1].Captures[0].ToString(); } } } } return(result); }