Download MovieFinder.Client.Scraper/ExtensionMethods.cs from niobures/VideoSearch: direct link, hf CLI and curl.
- Browser
- Download file 2.41 kB
-
https://huggingface.co/niobures/VideoSearch/resolve/main/MovieFinder.Client.Scraper/ExtensionMethods.cs
- Command line
-
hf download hf://niobures/VideoSearch/MovieFinder.Client.Scraper/ExtensionMethods.cs
-
curl -L -o ExtensionMethods.cs https://huggingface.co/niobures/VideoSearch/resolve/main/MovieFinder.Client.Scraper/ExtensionMethods.cs
2.41 kB
| using System; | |
| using System.Collections.Generic; | |
| using System.Text; | |
| using System.Web; | |
| namespace Client.Scraper | |
| { | |
| public static class HttpExtensions | |
| { | |
| public static Uri AddQuery(this Uri uri, string name, string value) | |
| { | |
| var ub = new UriBuilder(uri); | |
| // decodes urlencoded pairs from uri.Query to HttpValueCollection | |
| var httpValueCollection = HttpUtility.ParseQueryString(uri.Query); | |
| httpValueCollection.Add(name, value); | |
| // this code block is taken from httpValueCollection.ToString() method | |
| // and modified so it encodes strings with HttpUtility.UrlEncode | |
| if (httpValueCollection.Count == 0) | |
| ub.Query = String.Empty; | |
| else | |
| { | |
| var sb = new StringBuilder(); | |
| for (int i = 0; i < httpValueCollection.Count; i++) | |
| { | |
| string text = httpValueCollection.GetKey(i); | |
| { | |
| text = HttpUtility.UrlEncode(text); | |
| string val = (text != null) ? (text + "=") : string.Empty; | |
| string[] vals = httpValueCollection.GetValues(i); | |
| if (sb.Length > 0) | |
| sb.Append('&'); | |
| if (vals == null || vals.Length == 0) | |
| sb.Append(val); | |
| else | |
| { | |
| if (vals.Length == 1) | |
| { | |
| sb.Append(val); | |
| sb.Append(HttpUtility.UrlEncode(vals[0])); | |
| } | |
| else | |
| { | |
| for (int j = 0; j < vals.Length; j++) | |
| { | |
| if (j > 0) | |
| sb.Append('&'); | |
| sb.Append(val); | |
| sb.Append(HttpUtility.UrlEncode(vals[j])); | |
| } | |
| } | |
| } | |
| } | |
| } | |
| ub.Query = sb.ToString(); | |
| } | |
| return ub.Uri; | |
| } | |
| } | |
| } | |