From 98676ce8b213d36ac3a39eca6b19354a9270438e Mon Sep 17 00:00:00 2001 From: Tsanie Date: Mon, 2 Aug 2021 17:22:36 +0800 Subject: [PATCH] resolved bookmark issue, related illusts issue. --- Pixiview.iOS.OpenExtension/Info.plist | 4 +- Pixiview.iOS/Info.plist | 4 +- Pixiview.iOS/Renderers/AdaptedPageRenderer.cs | 2 +- Pixiview/Illust/FavoritesPage.xaml.cs | 0 Pixiview/Illust/IllustCollectionPage.cs | 11 +- Pixiview/Illust/MainPage.xaml | 4 +- Pixiview/Illust/MainPage.xaml.cs | 18 +-- Pixiview/Illust/RelatedIllustsPage.xaml.cs | 2 +- Pixiview/Utils/HttpUtility.cs | 26 ++--- Pixiview/Utils/IllustData.cs | 11 +- Pixiview/Utils/Stores.cs | 110 +++++------------- 11 files changed, 80 insertions(+), 112 deletions(-) mode change 100755 => 100644 Pixiview/Illust/FavoritesPage.xaml.cs mode change 100755 => 100644 Pixiview/Illust/IllustCollectionPage.cs mode change 100755 => 100644 Pixiview/Illust/RelatedIllustsPage.xaml.cs mode change 100755 => 100644 Pixiview/Utils/HttpUtility.cs mode change 100755 => 100644 Pixiview/Utils/IllustData.cs mode change 100755 => 100644 Pixiview/Utils/Stores.cs diff --git a/Pixiview.iOS.OpenExtension/Info.plist b/Pixiview.iOS.OpenExtension/Info.plist index f51c174..ce47e56 100755 --- a/Pixiview.iOS.OpenExtension/Info.plist +++ b/Pixiview.iOS.OpenExtension/Info.plist @@ -29,8 +29,8 @@ com.apple.share-services CFBundleShortVersionString - 1.2.727 + 1.3.802 CFBundleVersion - 31 + 32 diff --git a/Pixiview.iOS/Info.plist b/Pixiview.iOS/Info.plist index d894f72..970e9b7 100755 --- a/Pixiview.iOS/Info.plist +++ b/Pixiview.iOS/Info.plist @@ -79,9 +79,9 @@ CFBundleShortVersionString - 1.2.727 + 1.3.802 CFBundleVersion - 31 + 32 CFBundleDevelopmentRegion China diff --git a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs index d4bb7b3..f3bef95 100644 --- a/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs +++ b/Pixiview.iOS/Renderers/AdaptedPageRenderer.cs @@ -90,7 +90,7 @@ namespace Pixiview.iOS.Renderers if (Element is AdaptedPage page) { AppShell.Current?.SetStatusBarHeight( - NavigationController.NavigationBar.Frame.Height, + NavigationController?.NavigationBar.Frame.Height ?? 0, UIApplication.SharedApplication.StatusBarFrame.Height); var landscape = lastOrientation == UIDeviceOrientation.LandscapeLeft || diff --git a/Pixiview/Illust/FavoritesPage.xaml.cs b/Pixiview/Illust/FavoritesPage.xaml.cs old mode 100755 new mode 100644 diff --git a/Pixiview/Illust/IllustCollectionPage.cs b/Pixiview/Illust/IllustCollectionPage.cs old mode 100755 new mode 100644 index dcafa5f..328741b --- a/Pixiview/Illust/IllustCollectionPage.cs +++ b/Pixiview/Illust/IllustCollectionPage.cs @@ -630,7 +630,16 @@ namespace Pixiview.Illust { if (item.Image == null) { - var url = Configs.GetThumbnailUrl(item.ImageUrl); + string url; + try + { + url = Configs.GetThumbnailUrl(item.ImageUrl); + } + catch (Exception ex) + { + App.DebugError("image.getthumbnail", $"{item.ImageUrl}, {ex}"); + continue; + } var image = Stores.LoadPreviewImage(url, false); if (image == null) { diff --git a/Pixiview/Illust/MainPage.xaml b/Pixiview/Illust/MainPage.xaml index 7236f12..69c1a1d 100644 --- a/Pixiview/Illust/MainPage.xaml +++ b/Pixiview/Illust/MainPage.xaml @@ -31,8 +31,8 @@ - + i.ConvertToItem()); + return data.body.illusts.Where(i => i.url != null).Select(i => i.ConvertToItem()); } protected override IllustRecommendsData DoLoadIllustData(bool force) diff --git a/Pixiview/Utils/HttpUtility.cs b/Pixiview/Utils/HttpUtility.cs old mode 100755 new mode 100644 index 73ee878..97b6f00 --- a/Pixiview/Utils/HttpUtility.cs +++ b/Pixiview/Utils/HttpUtility.cs @@ -80,7 +80,7 @@ namespace Pixiview.Utils } if (!response.IsSuccessStatusCode) { - App.DebugPrint($"http failed with code: {response.StatusCode}"); + App.DebugPrint($"http failed with code: {(int)response.StatusCode} - {response.StatusCode}"); error = response.StatusCode.ToString(); return default; } @@ -188,7 +188,7 @@ namespace Pixiview.Utils { headers.Referrer = new Uri(Configs.Referer); headers.Add("User-Agent", Configs.UserAgent); - headers.Add("Accept", Configs.AcceptImage); + headers.Add("Accept", Configs.AcceptPureImage); }); if (response == null) { @@ -345,19 +345,19 @@ namespace Pixiview.Utils { using (var request = new HttpRequestMessage(post == null ? HttpMethod.Get : HttpMethod.Post, uri.PathAndQuery) { - Version = new Version(2, 0) + Version = new Version(1, 1) }) { var headers = request.Headers; headerAction(headers); - if (proxy == null) - { - var time = BitConverter.GetBytes(DateTime.UtcNow.Ticks); - headers.Add("X-Reverse-Ticks", Convert.ToBase64String(time)); - time = time.Concat(Encoding.UTF8.GetBytes("_reverse_for_pixiv_by_tsanie")).ToArray(); - var reverse = System.Security.Cryptography.SHA256.Create().ComputeHash(time); - headers.Add("X-Reverse", Convert.ToBase64String(reverse)); - } + //if (proxy == null) + //{ + // var time = BitConverter.GetBytes(DateTime.UtcNow.Ticks); + // headers.Add("X-Reverse-Ticks", Convert.ToBase64String(time)); + // time = time.Concat(Encoding.UTF8.GetBytes("_reverse_for_pixiv_by_tsanie")).ToArray(); + // var reverse = System.Security.Cryptography.SHA256.Create().ComputeHash(time); + // headers.Add("X-Reverse", Convert.ToBase64String(reverse)); + //} headers.Add("Accept-Language", Configs.AcceptLanguage); //headers.Add("Accept-Encoding", Configs.AcceptEncoding); if (post != null) @@ -410,7 +410,7 @@ namespace Pixiview.Utils { using (var request = new HttpRequestMessage(HttpMethod.Head, uri.PathAndQuery) { - Version = new Version(2, 0) + Version = new Version(1, 1) }) { var headers = request.Headers; @@ -434,7 +434,7 @@ namespace Pixiview.Utils { using (var request = new HttpRequestMessage(HttpMethod.Get, uri.PathAndQuery) { - Version = new Version(2, 0) + Version = new Version(1, 1) }) { var headers = request.Headers; diff --git a/Pixiview/Utils/IllustData.cs b/Pixiview/Utils/IllustData.cs old mode 100755 new mode 100644 index abbbbe6..a83c81c --- a/Pixiview/Utils/IllustData.cs +++ b/Pixiview/Utils/IllustData.cs @@ -66,7 +66,7 @@ namespace Pixiview.Utils { Id = illustId ?? id, BookmarkId = bookmarkData?.id, - Title = illustTitle, + Title = illustTitle ?? title, IllustType = (IllustType)illustType, Image = image, ImageUrl = urls?.x360 ?? url, @@ -94,6 +94,13 @@ namespace Pixiview.Utils public int partial; } + public class IllustFavoriteData : IllustResponse { } + public class IllustFavoriteBody + { + public int total; + public Illust[] works; + } + public class IllustData : IllustResponse { } public class IllustBody { @@ -191,7 +198,7 @@ namespace Pixiview.Utils public IllustItem CopyToItem(IllustItem item) { item.BookmarkId = bookmarkData?.id; - item.Title = illustTitle; + item.Title = illustTitle ?? title; item.IllustType = (IllustType)illustType; item.ImageUrl = urls?.regular; item.IsRestrict = xRestrict == 1; diff --git a/Pixiview/Utils/Stores.cs b/Pixiview/Utils/Stores.cs old mode 100755 new mode 100644 index 110f221..707ef76 --- a/Pixiview/Utils/Stores.cs +++ b/Pixiview/Utils/Stores.cs @@ -498,89 +498,40 @@ namespace Pixiview.Utils return result; } - private static readonly Regex regexIllust = new Regex( - @"book_id\[\]"" value=""([0-9]+)"".*data-src=""([^""]+)"".*data-id=""([0-9]+)"".*" + - @"data-tags=""([^""]+)"".*data-user-id=""([0-9]+)"".*" + - @"class=""title"" title=""([^""]+)"".*data-user_name=""([^""]+)"".*" + - @"_bookmark-icon-inline"">([0-9]+)", - RegexOptions.Compiled); + //private static readonly Regex regexIllust = new Regex( + // @"book_id\[\]"" value=""([0-9]+)"".*data-src=""([^""]+)"".*data-id=""([0-9]+)"".*" + + // @"data-tags=""([^""]+)"".*data-user-id=""([0-9]+)"".*" + + // @"class=""title"" title=""([^""]+)"".*data-user_name=""([^""]+)"".*" + + // @"_bookmark-icon-inline"">([0-9]+)", + // RegexOptions.Compiled); public static IllustItem[] LoadOnlineFavorites() { + var userId = Configs.UserId; var list = new List(); - int p = 1; - while (p > 0) + int offset = 0; + while (offset >= 0) { - var url = Configs.UrlFavoriteList; - if (p > 1) + var result = HttpUtility.LoadObject( + null, + string.Format(Configs.UrlFavoriteList, userId, offset, 48), + string.Format(Configs.RefererFavorites, userId), + out _); + if (result == null || result.error) { - url += $"&p={p}"; + App.DebugPrint($"error when load favorites data: {result?.message}"); } - var array = HttpUtility.LoadObject( - null, - url, - null, - out _, - action: content => - { - // page - p = -1; - var index = content.IndexOf(" 0) - { - var page = content.Substring(index + 45, content.IndexOf('\"', index + 45) - index - 45); - if (int.TryParse(page, out var next)) - { - p = next; - } - } - // list - index = content.IndexOf("
  • "); - if (index < 0) - { - return null; - } - content = content.Substring(index + 23); - index = content.IndexOf("
  • "); - if (index < 0) - { - return null; - } - return content.Substring(0, index); - }, - @return: content => - { - if (content == null) - { - return null; - } - var lines = content.Split("
  • "); - var illusts = new IllustItem[lines.Length]; - for (var i = 0; i < illusts.Length; i++) - { - var line = lines[i]; - var m = regexIllust.Match(line); - if (m.Success) - { - illusts[i] = new IllustItem - { - IsFavorite = true, - BookmarkId = m.Groups[1].Value, - ImageUrl = m.Groups[2].Value, - Id = m.Groups[3].Value, - Tags = m.Groups[4].Value.Split(' '), - UserId = m.Groups[5].Value, - Title = m.Groups[6].Value, - UserName = m.Groups[7].Value, - RatingCount = int.Parse(m.Groups[8].Value) - }; - } - } - return illusts; - }); - if (array != null && array.Length > 0) + else { - list.AddRange(array); + if (offset + 48 < result.body.total) + { + offset += 48; + } + else + { + offset = -1; + } + list.AddRange(result.body.works.Select(i => i.ConvertToItem())); } } return list.Where(l => l != null).ToArray(); @@ -763,6 +714,7 @@ namespace Pixiview.Utils public const string RefererIllust = "https://www.pixiv.net/artworks/{0}"; public const string RefererIllustRanking = "https://www.pixiv.net/ranking.php?{0}"; public const string RefererIllustUser = "https://www.pixiv.net/users/{0}/illustrations"; + public const string RefererFavorites = "https://www.pixiv.net/users/{0}/bookmarks/artworks"; public static int DownloadIllustThreads; public static bool IsOnR18; @@ -856,20 +808,20 @@ namespace Pixiview.Utils public static string UrlIllustUgoira => Prefix + "ajax/illust/{0}/ugoira_meta?lang=zh"; public static string UrlIllustRecommendsInit => Prefix + "ajax/illust/{0}/recommend/init?limit=18&lang=zh"; public static string UrlIllustRecommendsList => Prefix + "ajax/illust/recommend/illusts?{0}lang=zh"; - public static string UrlFavoriteList => Prefix + "bookmark.php?rest=show"; + public static string UrlFavoriteList => Prefix + "ajax/user/{0}/illusts/bookmarks?tag=&offset={1}&limit={2}&rest=show&lang=zh"; public static string BookmarkAdd => Prefix + "ajax/illusts/bookmarks/add"; public static string BookmarkRpc => Prefix + "rpc/index.php"; - 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 UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 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 AcceptPureImage = "image/*,*/*;q=0.8"; + public const string AcceptPureImage = "image/avif,image/webp,image/apng,image/svg+xml,image/*,*/*;q=0.8"; public const string AcceptJson = "application/json"; public const string AcceptUrlEncoded = "application/x-www-form-urlencoded"; //public const string AcceptEncoding = "gzip, deflate"; public const string AcceptLanguage = "zh-cn"; - private const string URL_PREVIEW = "https://i.pximg.net/c/360x360_70"; + private const string URL_PREVIEW = "https://i.pximg.net"; // /c/360x360_70 public static string GetThumbnailUrl(string url) {