diff --git a/Pixiview/Illust/ViewIllustPage.xaml.cs b/Pixiview/Illust/ViewIllustPage.xaml.cs index 1cc5c1a..fac6e8b 100644 --- a/Pixiview/Illust/ViewIllustPage.xaml.cs +++ b/Pixiview/Illust/ViewIllustPage.xaml.cs @@ -104,6 +104,7 @@ namespace Pixiview.Illust items[i] = new IllustDetailItem(); if (i == 0) { + items[i].Loading = true; items[i].Image = illust.Image; } } diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs index cf3f1ba..6080675 100644 --- a/Pixiview/Utils/Stores.cs +++ b/Pixiview/Utils/Stores.cs @@ -1,8 +1,8 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.Net.Http; +using System.Net.Http.Headers; using System.Text; using Newtonsoft.Json; using Pixiview.Illust; @@ -43,7 +43,7 @@ namespace Pixiview.Utils } } - private static T LoadObject(string file, string url, string referer = null, bool force = false, IEnumerable<(string header, string value)> headers = null) + private static T LoadObject(string file, string url, string referer = null, bool force = false) { string content = null; if (!force && File.Exists(file)) @@ -59,7 +59,14 @@ namespace Pixiview.Utils } if (content == null) { - var response = Download(url, referer, headers); + var response = Download(url, headers => + { + headers.Referrer = referer == null ? Configs.Referer : new Uri(referer); + headers.Add("user-agent", Configs.UserAgent); + headers.Add("accept", Configs.AcceptJson); + headers.Add("cookie", Configs.Cookie); + headers.Add("x-user-id", Configs.UserId); + }); if (response == null) { return default; @@ -157,12 +164,7 @@ namespace Pixiview.Utils var result = LoadObject( file, Configs.UrlIllustList, - force: force, - headers: new[] - { - ("cookie", Configs.Cookie), - ("x-user-id", Configs.UserId) - }); + force: force); return result; } @@ -173,12 +175,7 @@ namespace Pixiview.Utils file, string.Format(Configs.UrlIllustPage, id), string.Format(Configs.UrlIllust, id), - force: force, - headers: new[] - { - ("cookie", Configs.Cookie), - ("x-user-id", Configs.UserId) - }); + force: force); return result; } @@ -259,7 +256,12 @@ namespace Pixiview.Utils } var file = Path.Combine(directory, Path.GetFileName(url)); App.DebugPrint($"download, url: {url}"); - var response = Download(url); + var response = Download(url, headers => + { + headers.Referrer = Configs.Referer; + headers.Add("user-agent", Configs.UserAgent); + headers.Add("accept", Configs.AcceptImage); + }); if (response == null) { return null; @@ -301,14 +303,15 @@ namespace Pixiview.Utils return default; } - private static HttpResponseMessage Download(string url, string referer = null, IEnumerable<(string header, string value)> headers = null) + private static HttpResponseMessage Download(string url, Action headerAction) { App.DebugPrint($"GET: {url}"); var uri = new Uri(url); var handler = new HttpClientHandler { Proxy = Configs.Proxy, - UseProxy = true + UseProxy = true, + AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate }; var client = new HttpClient(handler) { @@ -321,15 +324,10 @@ namespace Pixiview.Utils Version = new Version(2, 0) }) { - request.Headers.Referrer = referer == null ? Configs.Referer : new Uri(referer); - request.Headers.Add("user-agent", Configs.UserAgent); - if (headers != null) - { - foreach (var (header, value) in headers) - { - request.Headers.Add(header, value); - } - } + var headers = request.Headers; + headerAction(headers); + headers.Add("accept-language", Configs.AcceptLanguage); + headers.Add("accept-encoding", Configs.AcceptEncoding); return client.SendAsync(request).Result; } }); @@ -342,24 +340,25 @@ namespace Pixiview.Utils public static readonly Uri Referer = new Uri("https://www.pixiv.net/"); public const int MaxThreads = 3; - public const string UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.129 Safari/537.36"; public const string UrlIllustList = "https://www.pixiv.net/ajax/top/illust?mode=all&lang=zh"; public const string UrlIllust = "https://www.pixiv.net/artworks/{0}"; public const string UrlIllustPage = "https://www.pixiv.net/ajax/illust/{0}/pages?lang=zh"; - public const string Cookie = "first_visit_datetime_pc=2019-10-29+22%3A05%3A30; p_ab_id=2; p_ab_id_2=6;" + - " p_ab_d_id=1155161977; a_type=0; b_type=1; d_type=2; module_orders_mypage=%5B%7B%22name%22%3A%22s" + - "ketch_live%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22tag_follow%22%2C%22visible%22%3Atrue" + - "%7D%2C%7B%22name%22%3A%22recommended_illusts%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22ev" + - "eryone_new_illusts%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22following_new_illusts%22%2C%" + - "22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22mypixiv_new_illusts%22%2C%22visible%22%3Atrue%7D%2C%7" + - "B%22name%22%3A%22spotlight%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22fanbox%22%2C%22visib" + - "le%22%3Atrue%7D%2C%7B%22name%22%3A%22featured_tags%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3" + - "A%22contests%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22user_events%22%2C%22visible%22%3At" + - "rue%7D%2C%7B%22name%22%3A%22sensei_courses%22%2C%22visible%22%3Atrue%7D%2C%7B%22name%22%3A%22boot" + - "h_follow_items%22%2C%22visible%22%3Atrue%7D%5D; yuid_b=NgcXQWQ; login_ever=yes; c_type=31; PHPSES" + - "SID=2603358_VHyGPeRaz7LpeoFkRsHvjXIpApCMb56a; __cfduid=d9fa2d4d1ddd30db85ebb519f9855d256158780674" + - "7; privacy_policy_agreement=2"; + public const string UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_4) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.138 Safari/537.36"; + public const string AcceptImage = "image/png,image/svg+xml,image/*;q=0.8,video/*;q=0.8,*/*;q=0.5"; + public const string AcceptJson = "application/json"; + public const string AcceptEncoding = "gzip, deflate"; + public const string AcceptLanguage = "zh-cn"; + public const string UserId = "2603358"; + public const string Cookie = + "PHPSESSID=2603358_VHyGPeRaz7LpeoFkRsHvjXIpApCMb56a; " + + "a_type=0; b_type=1; c_type=31; d_type=2; " + + "p_ab_id=2; p_ab_id_2=6; p_ab_d_id=1155161977; " + + "privacy_policy_agreement=2; " + + "login_ever=yes; " + + "__cfduid=d9fa2d4d1ddd30db85ebb519f9855d2561587806747; " + + "first_visit_datetime_pc=2019-10-29+22%3A05%3A30; " + + "yuid_b=NgcXQWQ"; public static string GetThumbnailUrl(string url) {