mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-07-03 13:57:26 +00:00
* [Add] 为Ranking命令增加翻页功能; [Change] BotCommandProcess 为`ranking`方法增加`pageIndex`参数, 增加对起始排名的计算, 移除起始排名的固定值, 改按pageIndex计算; [Fix] CacheStoreCentral 修复`getRankingInfoByCache`方法中潜在的排行榜返回错误的问题; [Delete] PixivDownload 移除无用的两个方法; [Change] PixivDownload 调整`@SuppressWarnings`注解的范围; * [Change] 调整搜索接口返回数据中Attribute的Enum存放位置; [Change] PixivSearchLinkBuilder 调整SuppressWarnings注解; [Deprecated] PixivSearchLinkBuilder.SearchArea.jsonKey 将属性标记deprecated; [Add] PixivSearchAttribute 增加搜索结果属性枚举类, 用于代替`PixivSearchLinkBuilder.SearchArea.jsonKey`; * [Add] 增加PixivSearchLinkBuilder中内部属性的getter, 增加Pixiv工具类; [Update] PixivSearchAttribute 补充Javadoc; [Add] PixivSearchLinkBuilder 增加大部分属性的getter方法; [Add] PixivUtils 增加Pixiv工具类, 并添加通过字符串参数构造PixivSearchLinkBuilder的方法; * [Fix] 修复搜索命令中area参数区分大小写的问题; [Fix] PixivUtils 修复area参数解析时区分大小写的问题; * [Fix] 修复搜索参数Area不在缓存标识范围内的问题; [Fix] CacheStoreCentral 调整搜索功能的缓存Key形式, 移除Url不变部分, 增加Area部分到缓存标识中; * [Add] 为搜索命令优化翻页功能; [Change] BotCommandProcess 重制search命令, 增加用于获取范围相关搜索结果页面的`getSearchResult`方法, 调整消息格式; * [Update] 优化搜索命令中的去重方法; [Update] BotCommandProcess 调整搜索命令, 使用HashSet对artworkList进行去重; * [Delete] 移除无用的`getSearchBody(String, ...)`方法; [Delete] CacheStoreCentral 移除无用的方法;
This commit is contained in:
84
src/main/java/net/lamgc/cgj/util/PixivUtils.java
Normal file
84
src/main/java/net/lamgc/cgj/util/PixivUtils.java
Normal file
@ -0,0 +1,84 @@
|
||||
package net.lamgc.cgj.util;
|
||||
|
||||
import com.google.common.base.Strings;
|
||||
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
/**
|
||||
* Pixiv工具类
|
||||
*/
|
||||
public final class PixivUtils {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(PixivUtils.class);
|
||||
|
||||
private PixivUtils() {}
|
||||
|
||||
/**
|
||||
* 快速构造一个PixivSearchLinkBuilder
|
||||
* @param content 搜索内容
|
||||
* @param type 搜索类型
|
||||
* @param area 搜索范围
|
||||
* @param includeKeywords 包含关键词
|
||||
* @param excludeKeywords 排除关键词
|
||||
* @param contentOption 内容级别选项
|
||||
* @param pageIndex 搜索页数
|
||||
* @return 返回PixivSearchLinkBuilder对象
|
||||
* @see PixivSearchLinkBuilder
|
||||
*/
|
||||
public static PixivSearchLinkBuilder buildSearchLinkBuilderFromString(
|
||||
String content,
|
||||
String type,
|
||||
String area,
|
||||
String includeKeywords,
|
||||
String excludeKeywords,
|
||||
String contentOption,
|
||||
int pageIndex
|
||||
) {
|
||||
PixivSearchLinkBuilder searchBuilder = new PixivSearchLinkBuilder(Strings.isNullOrEmpty(content) ? "" : content);
|
||||
if (type != null) {
|
||||
try {
|
||||
searchBuilder.setSearchType(PixivSearchLinkBuilder.SearchType.valueOf(type.trim().toUpperCase()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("不支持的SearchType: {}", type);
|
||||
}
|
||||
}
|
||||
if (area != null) {
|
||||
try {
|
||||
searchBuilder.setSearchArea(PixivSearchLinkBuilder.SearchArea.valueOf(area.trim().toUpperCase()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("不支持的SearchArea: {}", area);
|
||||
}
|
||||
}
|
||||
if (contentOption != null) {
|
||||
try {
|
||||
searchBuilder.setSearchContentOption(
|
||||
PixivSearchLinkBuilder.SearchContentOption.valueOf(contentOption.trim().toUpperCase()));
|
||||
} catch (IllegalArgumentException e) {
|
||||
log.warn("不支持的SearchContentOption: {}", contentOption);
|
||||
}
|
||||
}
|
||||
|
||||
if (!Strings.isNullOrEmpty(includeKeywords)) {
|
||||
for (String keyword : includeKeywords.split(";")) {
|
||||
searchBuilder.removeExcludeKeyword(keyword.trim());
|
||||
searchBuilder.addIncludeKeyword(keyword.trim());
|
||||
log.trace("已添加关键字: {}", keyword);
|
||||
}
|
||||
}
|
||||
if (!Strings.isNullOrEmpty(excludeKeywords)) {
|
||||
for (String keyword : excludeKeywords.split(";")) {
|
||||
searchBuilder.removeIncludeKeyword(keyword.trim());
|
||||
searchBuilder.addExcludeKeyword(keyword.trim());
|
||||
log.trace("已添加排除关键字: {}", keyword);
|
||||
}
|
||||
}
|
||||
|
||||
if(pageIndex > 0) {
|
||||
searchBuilder.setPage(pageIndex);
|
||||
}
|
||||
|
||||
return searchBuilder;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user