public string GetLatestCommitHash() { Regex shaRegex = new Regex(@"""sha"": ""([0-9a-f\.]*)"","); BetterWebClient apiClient = new BetterWebClient(); string apiResponse = apiClient.DownloadString(GithubAPIRepoBaseURL + _user + "/" + _repo + "/releases"); return(shaRegex.Match(apiResponse).Groups[1].Value); }
public bool FetchDeviantArtPage() { BetterWebClient pageClient = new BetterWebClient(); _cookieContainer = new CookieContainer(); _deviantPageString = pageClient.DownloadString(_url); _cookieContainer.SetCookies(new Uri(_url), pageClient.GetCookies()); return(_deviantPageString != null); }
public string GetLatestReleaseTag() { Regex shaRegex = new Regex(@"""tag_name"": ""([0-9a-f]{40})"","); BetterWebClient apiClient = new BetterWebClient(); string apiResponse = apiClient.DownloadString(GithubAPIRepoBaseURL + _user + "/" + _repo + "/releases"); _latestTag = shaRegex.Match(apiResponse).Groups[1].Value; return(_latestTag); }
public Scenery GetScenery(int sceneryPackId) { using (var client = new BetterWebClient()) { client.Encoding = Encoding.UTF8; var sceneryScript = client.DownloadString(this.baseUrl + "scenery/" + sceneryPackId.ToString()); var sceneryResponse = JsonConvert.DeserializeObject <SceneryResponse>(sceneryScript); return(sceneryResponse.Scenery); } }
public Airport GetAirport(string icaoCode) { using (var client = new BetterWebClient()) { client.Encoding = Encoding.UTF8; var airportString = client.DownloadString(this.baseUrl + "airport/" + icaoCode); var airportResponse = JsonConvert.DeserializeObject <AirportResponse>(airportString); return(airportResponse.Airport); } }
public AirportList GetAllAirports() { using (var client = new BetterWebClient()) { client.Encoding = Encoding.UTF8; var airportsString = client.DownloadString(this.baseUrl + "airports"); var airportList = JsonConvert.DeserializeObject <AirportList>(airportsString); return(airportList); } }
public string GetLatestVersionString() { if (string.IsNullOrEmpty(_versionMatchURL) || _versionMatchURL == (GithubBaseURL + _user + _repo)) { return(_usetags ? GetLatestReleaseTag() : GetLatestCommitHash()); } Regex versionRegex = new Regex(_versionRegexPattern); if (string.IsNullOrEmpty(_versionPageString)) { BetterWebClient versionPageClient = new BetterWebClient(); _versionPageString = versionPageClient.DownloadString(_versionMatchURL); } return(versionRegex.Match(_versionPageString).Groups[_versionMatchGroup].Value); }
public string GetLatestVersionString() { Regex versionRegex = new Regex(_versionRegexPattern); if (string.IsNullOrEmpty(_versionMatchURL) || _versionMatchURL == _url) { if (string.IsNullOrEmpty(_deviantPageString)) { if (!FetchDeviantArtPage()) { throw new Exception("Couldn't fetch the DeviantArt page of this item."); } } return(versionRegex.Match(_deviantPageString).Groups[_versionMatchGroup].Value); } if (string.IsNullOrEmpty(_versionPageString)) { BetterWebClient versionPageClient = new BetterWebClient(); _versionPageString = versionPageClient.DownloadString(_versionMatchURL); } return(versionRegex.Match(_versionPageString).Groups[_versionMatchGroup].Value); }
/*private void AddHeader(string key, string value) * { * if (Headers.ContainsKey(key)) * { * Headers[key] = value; * } * else * { * Headers.Add(key, value); * } * }*/ Response getRequest(string url_from, string Referer = null, CookieContainer cookies = null) { try { ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072; using (var client = new BetterWebClient(cookies == null ? CookieContainer : cookies)) { client.Headers[HttpRequestHeader.UserAgent] = islogin ? "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.2; Win64; x64; Trident/7.0; .NET4.0C; .NET4.0E; .NET CLR 2.0.50727; .NET CLR 3.0.30729; .NET CLR 3.5.30729; Tablet PC 2.0; Zoom 3.6.0)" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36"; if (!string.IsNullOrWhiteSpace(Referer)) { client.Headers[HttpRequestHeader.Referer] = Referer; } string response = client.DownloadString(url_from); extractCookies(client.ResponseHeaders["Set-Cookie"]); return(new Response { Page = response, Location = client.Location, StatusCode = client.StatusCode, ResponseUri = client.ResponseUri }); } } catch (Exception ex) { return(null); } }
private void Button_Click(object sender, RoutedEventArgs e) { string siteKinofrukt = "kinofrukt"; string siteKinopoisk = "kinopoisk"; if (tbSeasonNumber.Text != "") { seasonNumber = Int32.Parse(tbSeasonNumber.Text); } url = tbUrlKF.Text; WebClient webClient = new BetterWebClient(); if (tbUrlKF.Text.Contains(siteKinopoisk)) { webClient.Headers.Add("Accept", "text / html, application / xhtml + xml, application / xml; q = 0.9,image / webp,image / apng,*/*;q=0.8"); webClient.Headers.Add("Accept-Encoding", "gzip, deflate, br"); webClient.Headers.Add("Accept-Language", "en-US,en;q=0.9,uk;q=0.8,ru;q=0.7"); webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36"); } else if (tbUrlKF.Text.Contains(siteKinofrukt)) { webClient.Headers.Add("Content-Type", "text"); webClient.Encoding = System.Text.Encoding.UTF8; webClient.Headers.Add("UserAgent", "Opera/9.80 (Windows NT 6.1; WOW64; MRA 8.2 (build 6870)) Presto/2.12.388 Version/12.16"); } string html = webClient.DownloadString(url); string needCapchaKP = "https://www.kinopoisk.ru/captcha/voiceintro"; if (html.Contains(needCapchaKP)) { rtbKF.AppendText("Кинопоиск требует капчу"); return; } //убираем всякие закорюки из кода if (html.Contains(" ")) { html = html.Replace(" ", " "); } if (html.Contains("é")) { html = html.Replace("é", "é"); } if (html.Contains("é")) { html = html.Replace("é", "é"); } if (html.Contains("«")) { html = html.Replace("«", "«"); } if (html.Contains("»")) { html = html.Replace("»", "»"); } if (html.Contains("Ö")) { html = html.Replace("Ö", "Ö"); } if (html.Contains("ü")) { html = html.Replace("ü", "ü"); } HtmlDocument doc = new HtmlDocument(); doc.LoadHtml(html); //если в юрл есть слово кинофрукт if (tbUrlKF.Text.Contains(siteKinofrukt)) { try { //возвращает название nodesNazv = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/h1"); if (nodesNazv == null) { return; } foreach (HtmlNode node in nodesNazv) { nazv = node.InnerText; if (nazv.Contains("1,2")) { nazv1 = nazv.Substring("", " 1,2"); } if (nazv.Contains("(фильм")) { nazv1 = nazv.Substring("", " (фильм"); } if (nazv.Contains("(20")) { nazv1 = nazv.Substring("", " (20"); } } } catch { rtbKF.AppendText("Нет названия!"); } try { //возвращает страну nodesCountry = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][2]"); if (nodesCountry == null) { country = "-"; } foreach (HtmlNode node in nodesCountry) { country = node.InnerText; country2 = country.Substring("var actors = '", "';"); } } catch { country = "-"; } try { //возвращает год nodesYear = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][1]/i/a"); if (nodesYear == null) { year = "-"; } foreach (HtmlNode node in nodesYear) { year = node.InnerText; } if (seasonNumber > 1) { year = "2018"; } } catch { year = "-"; } try { //возвращает жанр nodesZhanr = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][3]/i"); if (nodesZhanr == null) { zhanr = "-"; } foreach (HtmlNode node in nodesZhanr) { zhanr = node.InnerText; zhanr = zhanr.ToLower(); } } catch { zhanr = "-"; } try { //возвращает режиссера nodesDirector = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][4]"); if (nodesDirector == null) { director = "-"; } foreach (HtmlNode node in nodesDirector) { director = node.InnerText; director2 = director.Substring("var actors = '", "';"); } } catch { director = "-"; } try { //возвращает актеров nodesActors = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-descr-line'][5]"); if (nodesActors == null) { actors = "-"; } foreach (HtmlNode node in nodesActors) { actors = node.InnerText; actors2 = actors.Substring("var actors = '", "';"); } } catch { actors = "-"; } try { //возвращает картинку nodesImage = doc.DocumentNode.SelectNodes( "/html[1]/body[1]/div[3]/div[2]/div[2]/div[2]/div[1]/div[6]/div[2]/div[1]/div[1]/ul[1]/li[2]/div[1]/a[1]/img[1]"); if (nodesImage == null) { image = "-"; } foreach (HtmlNode node in nodesImage) { image = node.OuterHtml; } if (image.Contains(nazv) != true) { nodesImage2 = doc.DocumentNode.SelectNodes( "/html/body/div[@class='body2']/div[@class='main-center-block']/div[@class='content-block']/div[@class='right-col']/div[@id='dle-content']/div[@class='main-news']/div[@class='main-news-content']/div[@class='main-news-image']/img/@src"); if (nodesImage2 == null) { image = "-"; } foreach (HtmlNode node in nodesImage2) { image = node.OuterHtml; } } } catch { image = "-"; } //если в юрл есть слово кинопоиск } else if (tbUrlKF.Text.Contains(siteKinopoisk)) { try { //возвращает название основное //бывает, что нет русского названия, то русское название пишем в поле внизу у кнопки результат if (tbAnglNazv.Text == "") { if (html.Contains("moviename-big")) { nazv1 = html.Substring("<h1 class=\"moviename-big\" itemprop=\"name\">", "</h1>"); } else { nazv1 = html.Substring("<span itemprop=\"alternativeHeadline\">", "</span>"); } //var nodesNazv = doc.DocumentNode.SelectSingleNode("//h1[@class='moviename-big' and itemprop='name']"); //if (nodesNazv != null) //{ // nazv1 = nodesNazv.InnerText; //} } else { nazv1 = tbAnglNazv.Text; } if (nazv1.Contains(" <span>(сериал")) { nazv1 = nazv1.Substring("", " <span>(сериал"); } if (nazv1.Contains(" <span>(видео")) { nazv1 = nazv1.Substring("", " <span>(видео"); } if (nazv1.Contains(" <span>(ТВ")) { nazv1 = nazv1.Substring("", " <span>(ТВ"); } if (nazv1.Contains(" <span>(мини")) { nazv1 = nazv1.Substring("", " <span>(мини"); } } catch { rtbKF.AppendText("Нет названия!"); } try { //возращает название ориг if (tbAnglNazv.Text == "") { if (html.Contains("alternativeHeadline")) { nazvAngl = html.Substring("<span itemprop=\"alternativeHeadline\">", "</span>"); } } else { nazvAngl = tbAnglNazv.Text; } } catch { nazvAngl = "-"; } try { //возвращает страну country2 = html.Substring("<td class=\"type\">страна</td>", "</td>"); //country2 = country2.Substring("/\">", "</a>"); country2 = StripHtmlTagsUsingRegex(country2); country2 = country2.Replace("\n ", ""); country2 = country2.Trim(); } catch { country2 = "-"; } try { //возвращает год if (html.Contains("премьера (РФ)")) { year = html.Substring("data-ical-date=\"", "\" data-date-premier"); year = year.Substring(year.Length - 4); } else if (html.Contains("премьера (мир)")) { year = html.Substring("title=\"\">", "</a>"); year = year.Substring(year.Length - 4); } year = html.Substring("<td class=\"type\">год</td>", "</td>"); year = year.Substring("title=\"\">", "</a>"); if (seasonNumber > 1) { year = "2018"; } } catch { year = "2018"; } try { //возвращает жанр zhanr = html.Substring("<span itemprop=\"genre\">", "an>"); string zajve = "</sp"; zhanr = zhanr.Replace(zajve, ""); zhanr = StripHtmlTagsUsingRegex(zhanr); } catch { zhanr = "-"; } try { //возвращает режиссера director2 = html.Substring("<td itemprop=\"director\">", "</td>"); director2 = StripHtmlTagsUsingRegex(director2); var zajve = ", ..."; director2 = director2.Replace(zajve, ""); } catch { director2 = "-"; } try { //возвращает актеров actors2 = html.Substring("<li itemprop=\"actors\">", "</li></ul>"); var zajve = "</li>"; actors2 = actors2.Replace(zajve, ", "); actors2 = StripHtmlTagsUsingRegex(actors2); var zajve2 = ", ..."; actors2 = actors2.Replace(zajve2, ""); } catch { actors2 = "-"; } try { //возвращает картинку image = html.Substring("<a class=\"popupBigImage\"", "</a>"); image = image.Substring("src=\"", "\" alt"); } catch { image = "-"; } } //поисковый запрос в ютуб if (cbIfSerial.IsChecked == true) { if (seasonNumber > 1) { Search.q = $"{nazv1} {seasonNumber} сезон ({year}) анонс сериала"; } else { Search.q = $"{nazv1} ({year}) анонс сериала"; } } else { Search.q = $"{nazv1} ({year}) трейлер"; } Search.YTBsearch(); //собираем кусочки if (image != "") { ImageResize.GetImage(); } Sborka(); }