/// <summary> /// Returns the file name if this object is every going to be saved. /// </summary> public string GetFileName() { string[] contenttype = this.content_type.Split(';'); string subtype = contenttype[0].Split('/')[1]; if (subtype == "html") { var result = AngleSharpBridge.Get(this.raw_content_string).Title + ".html"; return(Uri.EscapeDataString(result)); } string filename = this.GetHashCode().ToString(); foreach (Parameter param in this.response.Headers) { string k = param.Name; if (k.ToLower() == "content-disposition") { string v = (string)param.Value; filename = v.Substring(v.LastIndexOf("=")); filename = filename.Substring(0, filename.Length - 1); } } return(Uri.EscapeDataString(filename) + "." + subtype); }
/// <summary> /// Create an instance of the DA object /// </summary> /// <remarks> /// This function is pivotal. /// </remarks> /// <param name="url"></param> /// <returns> /// An instance of DA opened with the given URL. /// </returns> /// <excpetion> /// An incorrect URL exeception is thrown if the input url doesn't match the /// regex: ^https?://www.deviantart.com.*$ /// Other excpetion might be thrown from Webpage class. /// </excpetion> public static DAArtistwork GetInstance(string url) { Regex rx = new Regex("^https?://www.deviantart.com/.+/art/.+$"); if (!rx.IsMatch(url)) { throw new IncorrectURL(); } DAArtistwork d = new DAArtistwork(); d.daurl = url; RequestCustomizer rc = delegate(IRestRequest request) { request.AddHeader("cache-control", "no-cache"); request.AddHeader("Connection", "keep-alive"); request.AddHeader("accept-encoding", "gzip, deflate"); request.AddHeader("Accept", "*/*"); request.AddHeader("Host", "www.deviantart.com"); // Important to each specific websites. request.AddHeader("Postman-Token", "444dc8e3-1a2c-4802-8df7-234017033b7a,ede1a149-0f07-4750-85e2-f03030318567"); request.AddHeader("Cache-Control", "no-cache"); //request.AddHeader //("User-Agent", "Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/75.0.3770.100 Mobile Safari/537.36"); return(request); }; Webpage.Client.swappable_customizer = rc; Webpage newdapage = new Webpage(url); IDocument doc = AngleSharpBridge.Get(newdapage.raw_content_string); d.dapage = newdapage; d.doc = doc; return(d); }