[Add] PixivDownload 增加对排行榜获取失败抛出异常的信息;

[Fix] PixivURL.RankingContentType 修复isSupportedMode判断错误的问题;
[Fix] RankingUpdateTimer 调整每日更新时间(12:10 -> 12:30)以尝试修复排行榜更新时机过早的问题;
This commit is contained in:
LamGC 2020-04-27 12:32:25 +08:00
parent 22e74e8cd5
commit c2c49d2355
3 changed files with 7 additions and 5 deletions

View File

@ -31,7 +31,7 @@ public class RankingUpdateTimer {
cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + 1); cal.set(Calendar.DAY_OF_YEAR, cal.get(Calendar.DAY_OF_YEAR) + 1);
} }
cal.set(Calendar.HOUR_OF_DAY, 12); cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 10); cal.set(Calendar.MINUTE, 30);
cal.set(Calendar.SECOND, 0); cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0); cal.set(Calendar.MILLISECOND, 0);

View File

@ -299,6 +299,7 @@ public class PixivDownload {
*/ */
public List<JsonObject> getRanking(PixivURL.RankingContentType contentType, PixivURL.RankingMode mode, public List<JsonObject> getRanking(PixivURL.RankingContentType contentType, PixivURL.RankingMode mode,
Date time, int rankStart, int range) throws IOException { Date time, int rankStart, int range) throws IOException {
Objects.requireNonNull(time);
if(!Objects.requireNonNull(contentType).isSupportedMode(Objects.requireNonNull(mode))) { if(!Objects.requireNonNull(contentType).isSupportedMode(Objects.requireNonNull(mode))) {
throw new IllegalArgumentException("ContentType不支持指定的RankingMode: ContentType: " + contentType.name() + ", Mode: " + mode.name()); throw new IllegalArgumentException("ContentType不支持指定的RankingMode: ContentType: " + contentType.name() + ", Mode: " + mode.name());
} else if(rankStart <= 0) { } else if(rankStart <= 0) {
@ -322,7 +323,7 @@ public class PixivDownload {
String responseBody = EntityUtils.toString(response.getEntity()); String responseBody = EntityUtils.toString(response.getEntity());
log.debug("ResponseBody: {}", responseBody); log.debug("ResponseBody: {}", responseBody);
if(response.getStatusLine().getStatusCode() != 200) { if(response.getStatusLine().getStatusCode() != 200) {
throw new IOException("Http Response Error: " + response.getStatusLine()); throw new IOException("Http Response Error: '" + response.getStatusLine() + "', ResponseBody: '" + responseBody + '\'');
} }
JsonArray resultArray = gson.fromJson(responseBody, JsonObject.class).getAsJsonArray("contents"); JsonArray resultArray = gson.fromJson(responseBody, JsonObject.class).getAsJsonArray("contents");
@ -432,13 +433,14 @@ public class PixivDownload {
THUMB_MINI THUMB_MINI
} }
/** /**
* 获取帐号所有的收藏插画并以输入流形式提供 * 获取帐号所有的收藏插画并以输入流形式提供
* @return 获取所有链接的InputStream, 请注意关闭InputStream * @return 获取所有链接的InputStream, 请注意关闭InputStream
* @throws IOException 当获取时发生异常则直接抛出 * @throws IOException 当获取时发生异常则直接抛出
* @deprecated 该方法可能会导致已经打开的InputStream超时, 使图片获取失败,
* 请直接使用{@linkplain #getCollectionAsInputStream(PageQuality, BiConsumer)}
*/ */
@Deprecated
public Set<Map.Entry<String, InputStream>> getCollectionAsInputStream(PageQuality quality) throws IOException { public Set<Map.Entry<String, InputStream>> getCollectionAsInputStream(PageQuality quality) throws IOException {
HashSet<Map.Entry<String, InputStream>> illustInputStreamSet = new HashSet<>(); HashSet<Map.Entry<String, InputStream>> illustInputStreamSet = new HashSet<>();
getCollectionAsInputStream(quality, (link, inputStream) -> illustInputStreamSet.add(new AbstractMap.SimpleEntry<>(link, inputStream))); getCollectionAsInputStream(quality, (link, inputStream) -> illustInputStreamSet.add(new AbstractMap.SimpleEntry<>(link, inputStream)));

View File

@ -336,7 +336,7 @@ public class PixivURL {
* @return 如果支持返回true * @return 如果支持返回true
*/ */
public boolean isSupportedMode(RankingMode mode) { public boolean isSupportedMode(RankingMode mode) {
return Arrays.binarySearch(supportedMode, mode) != -1; return Arrays.binarySearch(supportedMode, mode) < 0;
} }
} }