[Change] BotCommandProcess 将各命令中'page'参数更名为'p'以简化命令;

[Change] PixivSearchLinkBuilder 更改类名(PixivSearchBuilder -> PixivSearchLinkBuilder);
[Add] PixivURL 增加接口常量;
[Change] Main, CacheStoreCentral, PixivSearchLinkBuilderTest 适配PixivSearchLinkBuilder的更改;
This commit is contained in:
LamGC 2020-06-12 17:06:04 +08:00
parent 62eabce8f6
commit 5e030c12b2
6 changed files with 74 additions and 60 deletions

View File

@ -13,7 +13,7 @@ import net.lamgc.cgj.bot.framework.cli.ConsoleMain;
import net.lamgc.cgj.bot.framework.coolq.CQConfig;
import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
import net.lamgc.cgj.pixiv.PixivDownload;
import net.lamgc.cgj.pixiv.PixivSearchBuilder;
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
import net.lamgc.cgj.pixiv.PixivURL;
import net.lamgc.plps.PixivLoginProxyServer;
import net.lamgc.utils.base.runner.Argument;
@ -254,24 +254,24 @@ public class Main {
@Argument(name = "excludeKeywords", force = false) String excludeKeywords,
@Argument(name = "contentOption", force = false) String contentOption
) throws IOException {
PixivSearchBuilder searchBuilder = new PixivSearchBuilder(Strings.isNullOrEmpty(content) ? "" : content);
PixivSearchLinkBuilder searchBuilder = new PixivSearchLinkBuilder(Strings.isNullOrEmpty(content) ? "" : content);
if (type != null) {
try {
searchBuilder.setSearchType(PixivSearchBuilder.SearchType.valueOf(type.toUpperCase()));
searchBuilder.setSearchType(PixivSearchLinkBuilder.SearchType.valueOf(type.toUpperCase()));
} catch (IllegalArgumentException e) {
log.warn("不支持的SearchType: {}", type);
}
}
if(area != null) {
try {
searchBuilder.setSearchArea(PixivSearchBuilder.SearchArea.valueOf(area));
searchBuilder.setSearchArea(PixivSearchLinkBuilder.SearchArea.valueOf(area));
} catch (IllegalArgumentException e) {
log.warn("不支持的SearchArea: {}", area);
}
}
if(contentOption != null) {
try {
searchBuilder.setSearchContentOption(PixivSearchBuilder.SearchContentOption.valueOf(contentOption));
searchBuilder.setSearchContentOption(PixivSearchLinkBuilder.SearchContentOption.valueOf(contentOption));
} catch (IllegalArgumentException e) {
log.warn("不支持的SearchContentOption: {}", contentOption);
}
@ -310,7 +310,7 @@ public class Main {
JsonObject resultBody = jsonObject.getAsJsonObject("body");
for(PixivSearchBuilder.SearchArea searchArea : PixivSearchBuilder.SearchArea.values()) {
for(PixivSearchLinkBuilder.SearchArea searchArea : PixivSearchLinkBuilder.SearchArea.values()) {
if(!resultBody.has(searchArea.jsonKey) || resultBody.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data").size() == 0) {
//log.info("返回数据不包含 {}", searchArea.jsonKey);
continue;

View File

@ -12,7 +12,7 @@ import net.lamgc.cgj.bot.event.BufferMessageEvent;
import net.lamgc.cgj.bot.sort.PreLoadDataComparator;
import net.lamgc.cgj.pixiv.PixivDownload;
import net.lamgc.cgj.pixiv.PixivDownload.PageQuality;
import net.lamgc.cgj.pixiv.PixivSearchBuilder;
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
import net.lamgc.cgj.pixiv.PixivURL;
import net.lamgc.utils.base.runner.Argument;
import net.lamgc.utils.base.runner.Command;
@ -310,7 +310,7 @@ public class BotCommandProcess {
@Argument(name = "in", force = false) String includeKeywords,
@Argument(name = "ex", force = false) String excludeKeywords,
@Argument(name = "option", force = false) String contentOption,
@Argument(name = "page", force = false, defaultValue = "1") int pagesIndex
@Argument(name = "p", force = false, defaultValue = "1") int pagesIndex
) throws IOException {
log.info("正在执行搜索...");
JsonObject resultBody = CacheStoreCentral.getCentral()
@ -326,7 +326,7 @@ public class BotCommandProcess {
log.warn("参数转换异常!将使用默认值(" + limit + ")", e);
}
int totalCount = 0;
for (PixivSearchBuilder.SearchArea searchArea : PixivSearchBuilder.SearchArea.values()) {
for (PixivSearchLinkBuilder.SearchArea searchArea : PixivSearchLinkBuilder.SearchArea.values()) {
if (!resultBody.has(searchArea.jsonKey) ||
resultBody.getAsJsonObject(searchArea.jsonKey).getAsJsonArray("data").size() == 0) {
log.debug("返回数据不包含 {}", searchArea.jsonKey);
@ -493,7 +493,7 @@ public class BotCommandProcess {
@Argument(name = "$fromGroup") long fromGroup,
@Argument(name = "id") int illustId,
@Argument(name = "quality", force = false) PixivDownload.PageQuality quality,
@Argument(name = "page", force = false, defaultValue = "1") int pageIndex
@Argument(name = "p", force = false, defaultValue = "1") int pageIndex
) {
return CacheStoreCentral.getCentral().getImageById(fromGroup, illustId, quality, pageIndex);
}

View File

@ -9,7 +9,7 @@ import net.lamgc.cgj.bot.BotCommandProcess;
import net.lamgc.cgj.bot.SettingProperties;
import net.lamgc.cgj.bot.boot.BotGlobal;
import net.lamgc.cgj.pixiv.PixivDownload;
import net.lamgc.cgj.pixiv.PixivSearchBuilder;
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
import net.lamgc.cgj.pixiv.PixivURL;
import net.lamgc.cgj.util.URLs;
import net.lamgc.utils.encrypt.MessageDigestUtils;
@ -386,17 +386,17 @@ public final class CacheStoreCentral {
String includeKeywords,
String excludeKeywords,
String contentOption) throws IOException {
PixivSearchBuilder searchBuilder = new PixivSearchBuilder(Strings.isNullOrEmpty(content) ? "" : content);
PixivSearchLinkBuilder searchBuilder = new PixivSearchLinkBuilder(Strings.isNullOrEmpty(content) ? "" : content);
if (type != null) {
try {
searchBuilder.setSearchType(PixivSearchBuilder.SearchType.valueOf(type.toUpperCase()));
searchBuilder.setSearchType(PixivSearchLinkBuilder.SearchType.valueOf(type.toUpperCase()));
} catch (IllegalArgumentException e) {
log.warn("不支持的SearchType: {}", type);
}
}
if (area != null) {
try {
searchBuilder.setSearchArea(PixivSearchBuilder.SearchArea.valueOf(area));
searchBuilder.setSearchArea(PixivSearchLinkBuilder.SearchArea.valueOf(area));
} catch (IllegalArgumentException e) {
log.warn("不支持的SearchArea: {}", area);
}
@ -404,7 +404,7 @@ public final class CacheStoreCentral {
if (contentOption != null) {
try {
searchBuilder.setSearchContentOption(
PixivSearchBuilder.SearchContentOption.valueOf(contentOption.trim().toUpperCase()));
PixivSearchLinkBuilder.SearchContentOption.valueOf(contentOption.trim().toUpperCase()));
} catch (IllegalArgumentException e) {
log.warn("不支持的SearchContentOption: {}", contentOption);
}

View File

@ -16,7 +16,7 @@ import java.util.Objects;
* @see PixivURL#PIXIV_SEARCH_CONTENT_URL
*/
@SuppressWarnings("ALL")
public class PixivSearchBuilder {
public class PixivSearchLinkBuilder {
private final String content;
@ -42,7 +42,7 @@ public class PixivSearchBuilder {
private Date startDate = null;
private Date endDate = null;
public PixivSearchBuilder(String searchContent) {
public PixivSearchLinkBuilder(String searchContent) {
this.content = Objects.requireNonNull(searchContent);
}
@ -99,7 +99,7 @@ public class PixivSearchBuilder {
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
PixivSearchBuilder that = (PixivSearchBuilder) o;
PixivSearchLinkBuilder that = (PixivSearchLinkBuilder) o;
return page == that.page &&
wgt == that.wgt &&
hgt == that.hgt &&
@ -141,7 +141,7 @@ public class PixivSearchBuilder {
@Override
public String toString() {
return "PixivSearchBuilder{" +
return "PixivSearchLinkBuilder{" +
"content='" + content + '\'' +
", searchArea=" + searchArea +
", searchMode=" + searchMode +
@ -161,7 +161,7 @@ public class PixivSearchBuilder {
'}';
}
public PixivSearchBuilder setSearchArea(SearchArea searchArea) {
public PixivSearchLinkBuilder setSearchArea(SearchArea searchArea) {
this.searchArea = Objects.requireNonNull(searchArea);
return this;
}
@ -202,50 +202,50 @@ public class PixivSearchBuilder {
return searchContent.toString();
}
public PixivSearchBuilder setSearchMode(SearchMode searchMode) {
public PixivSearchLinkBuilder setSearchMode(SearchMode searchMode) {
this.searchMode = Objects.requireNonNull(searchMode);
return this;
}
public PixivSearchBuilder setSearchType(SearchType searchType) {
public PixivSearchLinkBuilder setSearchType(SearchType searchType) {
this.searchType = Objects.requireNonNull(searchType);
return this;
}
public PixivSearchBuilder setSearchOrder(SearchOrder searchOrder) {
public PixivSearchLinkBuilder setSearchOrder(SearchOrder searchOrder) {
this.searchOrder = Objects.requireNonNull(searchOrder);
return this;
}
public PixivSearchBuilder setSearchContentOption(SearchContentOption searchContentOption) {
public PixivSearchLinkBuilder setSearchContentOption(SearchContentOption searchContentOption) {
this.searchContentOption = Objects.requireNonNull(searchContentOption);
return this;
}
public PixivSearchBuilder setRatioOption(RatioOption ratioOption) {
public PixivSearchLinkBuilder setRatioOption(RatioOption ratioOption) {
this.ratioOption = Objects.requireNonNull(ratioOption);
return this;
}
public PixivSearchBuilder setDateRange(Date startDate, Date endDate) {
public PixivSearchLinkBuilder setDateRange(Date startDate, Date endDate) {
this.startDate = startDate;
this.endDate = endDate;
return this;
}
public PixivSearchBuilder setMaxSize(int width, int height) {
public PixivSearchLinkBuilder setMaxSize(int width, int height) {
this.wgt = width;
this.hgt = height;
return this;
}
public PixivSearchBuilder setMinSize(int width, int height) {
public PixivSearchLinkBuilder setMinSize(int width, int height) {
this.wlt = width;
this.hlt = height;
return this;
}
public PixivSearchBuilder setPage(int pageIndex) {
public PixivSearchLinkBuilder setPage(int pageIndex) {
if (pageIndex <= 0) {
throw new IllegalArgumentException("Invalid pageIndex: " + pageIndex);
}
@ -253,22 +253,22 @@ public class PixivSearchBuilder {
return this;
}
public PixivSearchBuilder addExcludeKeyword(String keyword) {
public PixivSearchLinkBuilder addExcludeKeyword(String keyword) {
excludeKeywords.add(keyword);
return this;
}
public PixivSearchBuilder removeExcludeKeyword(String keyword) {
public PixivSearchLinkBuilder removeExcludeKeyword(String keyword) {
excludeKeywords.remove(keyword);
return this;
}
public PixivSearchBuilder addIncludeKeyword(String keyword) {
public PixivSearchLinkBuilder addIncludeKeyword(String keyword) {
includeKeywords.add(keyword);
return this;
}
public PixivSearchBuilder removeIncludeKeyword(String keyword) {
public PixivSearchLinkBuilder removeIncludeKeyword(String keyword) {
includeKeywords.remove(keyword);
return this;
}

View File

@ -13,52 +13,52 @@ import java.util.GregorianCalendar;
public class PixivURL {
public static final String PIXIV_INDEX_URL = "https://www.pixiv.net";
public final static String PIXIV_INDEX_URL = "https://www.pixiv.net";
/**
* P站预登陆url
*/
public static final String PIXIV_LOGIN_PAGE_URL = "https://accounts.pixiv.net/login?lang=zh&source=pc&view_type=page&ref=wwwtop_accounts_index";
public final static String PIXIV_LOGIN_PAGE_URL = "https://accounts.pixiv.net/login?lang=zh&source=pc&view_type=page&ref=wwwtop_accounts_index";
/**
* P站登录请求url
*/
public static final String PIXIV_LOGIN_URL = "https://accounts.pixiv.net/api/login?lang=zh";
public final static String PIXIV_LOGIN_URL = "https://accounts.pixiv.net/api/login?lang=zh";
/**
* P站搜索请求url
* @deprecated 该接口已被替换, 请使用{@link PixivSearchBuilder}构造搜索Url
* @see PixivSearchBuilder
* @deprecated 该接口已被替换, 请使用{@link PixivSearchLinkBuilder}构造搜索Url
* @see PixivSearchLinkBuilder
*/
@Deprecated
private static final String PIXIV_SEARCH_URL = "https://www.pixiv.net/search.php";
private final static String PIXIV_SEARCH_URL = "https://www.pixiv.net/search.php";
/**
* P站搜索用户url
* 需要替换的参数:
* {nick} - 用户昵称部分名称
* @deprecated 该接口已被替换, 请使用{@link PixivSearchBuilder}构造搜索Url
* @see PixivSearchBuilder
* @deprecated 该接口已被替换, 请使用{@link PixivSearchLinkBuilder}构造搜索Url
* @see PixivSearchLinkBuilder
*/
@Deprecated
public static final String PIXIV_SEARCH_USER_URL = PIXIV_SEARCH_URL + "?s_mode=s_usr&nick={nick}";
public final static String PIXIV_SEARCH_USER_URL = PIXIV_SEARCH_URL + "?s_mode=s_usr&nick={nick}";
/**
* P站搜索插画url
* 需要替换的参数:
* {word} - 插画相关文本
* @deprecated 该接口已被替换, 请使用{@link PixivSearchBuilder}构造搜索Url
* @see PixivSearchBuilder
* @deprecated 该接口已被替换, 请使用{@link PixivSearchLinkBuilder}构造搜索Url
* @see PixivSearchLinkBuilder
*/
@Deprecated
public static final String PIXIV_SEARCH_TAG_URL = PIXIV_SEARCH_URL + "?s_mode=s_tag&word={word}";
public final static String PIXIV_SEARCH_TAG_URL = PIXIV_SEARCH_URL + "?s_mode=s_tag&word={word}";
/**
* P站插图下载链接获取url
* 需要替换的文本:
* {illustId} - 插画ID
*/
public static final String PIXIV_ILLUST_API_URL = "https://www.pixiv.net/ajax/illust/{illustId}/pages";
public final static String PIXIV_ILLUST_API_URL = "https://www.pixiv.net/ajax/illust/{illustId}/pages";
/**
* P站用户插图列表获取API
@ -67,42 +67,42 @@ public class PixivURL {
* {userId} - 用户ID
*/
//{"error":false,"message":"","body":{"illusts":{"74369837":null,"70990542":null,"70608653":null,"69755191":null,"69729450":null,"69729416":null,"69503608":null,"69288766":null,"69083882":null,"69051458":null,"68484200":null,"68216927":null,"68216866":null,"68192333":null,"67915106":null,"67914932":null,"67854803":null,"67854745":null,"67854670":null,"67787211":null,"67772199":null,"67770637":null,"67754861":null,"67754804":null,"67754726":null,"67740486":null,"67740480":null,"67740450":null,"67740434":null,"67726337":null,"67499196":null,"67499163":null,"67499145":null,"67499111":null,"67499085":null,"67499038":null,"67498987":null,"67473178":null,"66271465":null,"63682753":null,"63682697":null,"59385148":null,"59383265":null,"59383240":null,"59383227":null,"59383173":null},"manga":[],"novels":[],"mangaSeries":[],"novelSeries":[],"pickup":[],"bookmarkCount":{"public":{"illust":1,"novel":0},"private":{"illust":0,"novel":0}}}}
public static final String PIXIV_USER_ILLUST_LIST_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/all";
public final static String PIXIV_USER_ILLUST_LIST_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/all";
/**
* 能够同时获取插图信息的用户插图列表获取API
* 需要替换的文本:
* {userId} - 用户ID
*/
public static final String PIXIV_USER_TOP_ILLUST_LIST_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/top";
public final static String PIXIV_USER_TOP_ILLUST_LIST_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/top";
/**
* P站单图详情页url
* 需要替换的文本:
* {illustId} - 插画ID
*/
public static final String PIXIV_ILLUST_MEDIUM_URL = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id={illustId}";
public final static String PIXIV_ILLUST_MEDIUM_URL = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id={illustId}";
/**
* P站多图详情页url
* 需要替换的文本:
* {illustId} - 插画ID
*/
public static final String PIXIV_ILLUST_MANGA_URL = "https://www.pixiv.net/member_illust.php?mode=manga&illust_id={illustId}";
public final static String PIXIV_ILLUST_MANGA_URL = "https://www.pixiv.net/member_illust.php?mode=manga&illust_id={illustId}";
/**
* P站用户页面url
* 需要替换的文本:
* {userId} - 用户ID
*/
public static final String PIXIV_USER_URL = "https://www.pixiv.net/member.php?id={userId}";
public final static String PIXIV_USER_URL = "https://www.pixiv.net/member.php?id={userId}";
/**
* P站插图信息获取API
* 这个API能获取插图基本信息但不能获取大小
* 请使用{@link #getPixivIllustInfoAPI(int[])}获取URL
*/
private static final String PIXIV_GET_ILLUST_INFO_URL = "https://www.pixiv.net/ajax/illust/recommend/illusts?";
private final static String PIXIV_GET_ILLUST_INFO_URL = "https://www.pixiv.net/ajax/illust/recommend/illusts?";
/**
* P站获取用户所有插图ID的Api
@ -110,7 +110,15 @@ public class PixivURL {
* 需要替换的文本:
* {userId} - 用户ID
*/
public static final String PIXIV_GET_USER_ALL_ILLUST_ID_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/all";
public final static String PIXIV_GET_USER_ALL_ILLUST_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/all";
/**
* P站获取用户推荐插画及用户基本数据
* 这个API能获得作者的部分(推荐)作品, 每个作品有详细数据, 还能获取作者主页信息(比如主页说明, 看板图)
* 需要替换的文本:
* {userId} - 用户ID
*/
public final static String PIXIV_GET_USER_TOP_ILLUST_URL = "https://www.pixiv.net/ajax/user/{userId}/profile/top";
/**
* P站标签搜索URL
@ -118,7 +126,7 @@ public class PixivURL {
* 需要替换的文本:
* {content} - 大致tag内容
*/
public static final String PIXIV_TAG_SEARCH_URL = "https://www.pixiv.net/ajax/search/tags/{content}";
public final static String PIXIV_TAG_SEARCH_URL = "https://www.pixiv.net/ajax/search/tags/{content}";
/**
* 获取动图下载链接和拼接数据.
@ -128,11 +136,17 @@ public class PixivURL {
*/
public final static String PIXIV_GET_UGOIRA_META_URL = "https://www.pixiv.net/ajax/illust/{illustId}/ugoira_meta";
/**
* 获取自己帐号的部分数据(目前仅能获取: 关注数, 粉丝数和看板图)
* 需要登录.
*/
public final static String PIXIV_GET_USER_EXTRA_URL = "https://www.pixiv.net/ajax/user/extra";
/**
* 请求时带上需要退出的Cookies
* 无论成功与否都会返回302重定向到{@linkplain #PIXIV_LOGIN_PAGE_URL 登录页面}
*/
public static final String PIXIV_LOGOUT_URL = "https://www.pixiv.net/logout.php";
public final static String PIXIV_LOGOUT_URL = "https://www.pixiv.net/logout.php";
/**
* 构造P站获取插图信息的Api Url
@ -279,7 +293,7 @@ public class PixivURL {
/**
* Pixiv搜索接口.<br/>
* 要使用该链接请使用{@link PixivSearchBuilder}构造链接.<br/>
* 要使用该链接请使用{@link PixivSearchLinkBuilder}构造链接.<br/>
* 需要替换的参数: <br/>
* content - 搜索内容
*/

View File

@ -3,23 +3,23 @@ package net.lamgc.cgj.pixiv;
import org.junit.Assert;
import org.junit.Test;
public class PixivSearchBuilderTest {
public class PixivSearchLinkBuilderTest {
@Test
public void buildTest() {
PixivSearchBuilder builder = new PixivSearchBuilder("hololive");
PixivSearchLinkBuilder builder = new PixivSearchLinkBuilder("hololive");
builder.addIncludeKeyword("35").addIncludeKeyword("okayu").addIncludeKeyword("百鬼あやめ");
System.out.println(builder.buildURL());
}
@Test
public void equalsTest() {
Assert.assertEquals(new PixivSearchBuilder("风景"), new PixivSearchBuilder("风景"));
Assert.assertEquals(new PixivSearchLinkBuilder("风景"), new PixivSearchLinkBuilder("风景"));
}
@Test
public void hashCodeTest() {
Assert.assertEquals(new PixivSearchBuilder("风景").hashCode(), new PixivSearchBuilder("风景").hashCode());
Assert.assertEquals(new PixivSearchLinkBuilder("风景").hashCode(), new PixivSearchLinkBuilder("风景").hashCode());
}
}