From 66d3d0aa31db5c0ae4274f0be168faf818c49f9e Mon Sep 17 00:00:00 2001 From: LamGC Date: Wed, 15 Apr 2020 21:54:30 +0800 Subject: [PATCH] =?UTF-8?q?[Change]=20=E9=80=82=E9=85=8DPixivURL=E7=9A=84?= =?UTF-8?q?=E4=BF=AE=E6=94=B9(#ad1922bc);=20[Add]=20=E5=A2=9E=E5=8A=A0?= =?UTF-8?q?=E7=94=A8=E4=BA=8E=E9=80=9A=E8=BF=87=E6=8E=A5=E5=8F=A3=E8=BF=94?= =?UTF-8?q?=E5=9B=9E=E6=95=B0=E6=8D=AE=E5=88=A4=E5=88=AB=E4=BD=9C=E5=93=81?= =?UTF-8?q?=E7=B1=BB=E5=9E=8B=E7=9A=84PixivIllustType=20Enum=E7=B1=BB;?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../net/lamgc/cgj/pixiv/PixivDownload.java | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java b/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java index 3cf51ca..d6a604e 100644 --- a/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java +++ b/src/main/java/net/lamgc/cgj/pixiv/PixivDownload.java @@ -546,7 +546,7 @@ public class PixivDownload { * @throws IOException 当请求发生异常, 或接口返回错误信息时抛出. */ public JsonObject getIllustInfoByIllustId(int illustId) throws IOException { - HttpGet request = createHttpGetRequest(PixivURL.getPixivIllustInfoAPI(new int[] {illustId})); + HttpGet request = createHttpGetRequest(PixivURL.getPixivIllustInfoAPI(illustId)); HttpResponse response = httpClient.execute(request); String responseStr = EntityUtils.toString(response.getEntity()); log.debug("Response Content: {}", responseStr); @@ -571,4 +571,64 @@ public class PixivDownload { request.setHeader(HttpHeaderNames.COOKIE.toString(), builder.toString()); } + public enum PixivIllustType { + /** + * 插画 + */ + ILLUST(0), + + /** + * 漫画 + */ + MANGA(1), + + /** + * 动图 + */ + UGOIRA(2), + ; + + public final int typeId; + + PixivIllustType(int typeId) { + this.typeId = typeId; + } + + /** + * 通过typeId搜索PixivIllustType + * @param typeId 接口属性"illustType"的值 + * @return 如果搜索到匹配的IllustType则返回, 未找到返回null + */ + public static PixivIllustType getIllustTypeById(int typeId) { + for (PixivIllustType illustType : PixivIllustType.values()) { + if(illustType.typeId == typeId) { + return illustType; + } + } + return null; + } + + public static PixivIllustType getIllustTypeByPreLoadData(int illustId, JsonObject preLoadDataObject) { + JsonObject illustData; + if(preLoadDataObject.has("illust")) { + illustData = preLoadDataObject.getAsJsonObject("illust").getAsJsonObject(String.valueOf(illustId)); + } else if(preLoadDataObject.has(String.valueOf(illustId))) { + illustData = preLoadDataObject.getAsJsonObject(String.valueOf(illustId)); + } else { + illustData = preLoadDataObject; + } + + if(illustData.get("illustId").getAsInt() != illustId) { + return null; + } + + if(illustData.has("illustType")) { + return getIllustTypeById(illustData.get("illustType").getAsInt()); + } else { + return null; + } + } + + } + }