mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
Merge branch 'master' of github.com:LamGC/ContentGrabbingJi
This commit is contained in:
commit
cbe0a38f59
11
pom.xml
11
pom.xml
@ -162,17 +162,6 @@
|
|||||||
<artifactId>ktor-server-core</artifactId>
|
<artifactId>ktor-server-core</artifactId>
|
||||||
<version>${ktor.version}</version>
|
<version>${ktor.version}</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.lamgc</groupId>
|
|
||||||
<artifactId>PixivLoginProxyServer</artifactId>
|
|
||||||
<version>1.1.1</version>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.slf4j</groupId>
|
|
||||||
<artifactId>slf4j-log4j12</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.squareup</groupId>
|
<groupId>com.squareup</groupId>
|
||||||
<artifactId>gifencoder</artifactId>
|
<artifactId>gifencoder</artifactId>
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package net.lamgc.cgj;
|
package net.lamgc.cgj;
|
||||||
|
|
||||||
import com.github.monkeywie.proxyee.proxy.ProxyConfig;
|
|
||||||
import com.github.monkeywie.proxyee.proxy.ProxyType;
|
|
||||||
import com.google.common.base.Strings;
|
import com.google.common.base.Strings;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.JsonArray;
|
import com.google.gson.JsonArray;
|
||||||
@ -15,10 +13,10 @@ import net.lamgc.cgj.bot.framework.mirai.MiraiMain;
|
|||||||
import net.lamgc.cgj.pixiv.PixivDownload;
|
import net.lamgc.cgj.pixiv.PixivDownload;
|
||||||
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
import net.lamgc.cgj.pixiv.PixivSearchLinkBuilder;
|
||||||
import net.lamgc.cgj.pixiv.PixivURL;
|
import net.lamgc.cgj.pixiv.PixivURL;
|
||||||
import net.lamgc.plps.PixivLoginProxyServer;
|
|
||||||
import net.lamgc.utils.base.runner.Argument;
|
import net.lamgc.utils.base.runner.Argument;
|
||||||
import net.lamgc.utils.base.runner.ArgumentsRunner;
|
import net.lamgc.utils.base.runner.ArgumentsRunner;
|
||||||
import net.lamgc.utils.base.runner.Command;
|
import net.lamgc.utils.base.runner.Command;
|
||||||
|
import net.lamgc.utils.encrypt.MessageDigestUtils;
|
||||||
import org.apache.http.HttpHost;
|
import org.apache.http.HttpHost;
|
||||||
import org.apache.http.HttpResponse;
|
import org.apache.http.HttpResponse;
|
||||||
import org.apache.http.client.CookieStore;
|
import org.apache.http.client.CookieStore;
|
||||||
@ -52,6 +50,14 @@ public class Main {
|
|||||||
private static HttpHost proxy;
|
private static HttpHost proxy;
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
public static void main(String[] args) throws IOException, ClassNotFoundException {
|
||||||
|
if(args.length != 0 && args[0].equalsIgnoreCase("buildpassword")) {
|
||||||
|
ArgumentsRunner.run(Main.class, args);
|
||||||
|
} else {
|
||||||
|
standardStart(args);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void standardStart(String[] args) throws IOException, ClassNotFoundException {
|
||||||
log.info("ContentGrabbingJi 正在启动...");
|
log.info("ContentGrabbingJi 正在启动...");
|
||||||
log.debug("Args: {}, LogsPath: {}", Arrays.toString(args), System.getProperty("cgj.logsPath"));
|
log.debug("Args: {}, LogsPath: {}", Arrays.toString(args), System.getProperty("cgj.logsPath"));
|
||||||
log.debug("运行目录: {}", System.getProperty("user.dir"));
|
log.debug("运行目录: {}", System.getProperty("user.dir"));
|
||||||
@ -62,16 +68,9 @@ public class Main {
|
|||||||
proxy = BotGlobal.getGlobal().getProxy();
|
proxy = BotGlobal.getGlobal().getProxy();
|
||||||
File cookieStoreFile = new File(BotGlobal.getGlobal().getDataStoreDir(), "cookies.store");
|
File cookieStoreFile = new File(BotGlobal.getGlobal().getDataStoreDir(), "cookies.store");
|
||||||
if(!cookieStoreFile.exists()) {
|
if(!cookieStoreFile.exists()) {
|
||||||
log.warn("未找到cookies.store文件, 是否启动PixivLoginProxyServer? (yes/no)");
|
log.warn("未找到cookies.store文件, 请检查数据存放目录下是否存在'cookies.store'文件!");
|
||||||
try(Scanner scanner = new Scanner(System.in)) {
|
System.exit(1);
|
||||||
if(scanner.nextLine().trim().equalsIgnoreCase("yes")) {
|
return;
|
||||||
startPixivLoginProxyServer();
|
|
||||||
} else {
|
|
||||||
System.exit(1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(cookieStoreFile));
|
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(cookieStoreFile));
|
||||||
cookieStore = (CookieStore) ois.readObject();
|
cookieStore = (CookieStore) ois.readObject();
|
||||||
@ -85,6 +84,13 @@ public class Main {
|
|||||||
System.exit(0);
|
System.exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Command
|
||||||
|
public static void buildPassword(@Argument(name = "password") String password) {
|
||||||
|
System.out.println("Password: " +
|
||||||
|
Base64.getEncoder().encodeToString(MessageDigestUtils.encrypt(password.getBytes(),
|
||||||
|
MessageDigestUtils.Algorithm.MD5)));
|
||||||
|
}
|
||||||
|
|
||||||
@Command
|
@Command
|
||||||
public static void botMode(@Argument(name = "args", force = false) String argsStr) {
|
public static void botMode(@Argument(name = "args", force = false) String argsStr) {
|
||||||
MiraiMain main = new MiraiMain();
|
MiraiMain main = new MiraiMain();
|
||||||
@ -349,57 +355,6 @@ public class Main {
|
|||||||
log.info("这里啥都没有哟w");
|
log.info("这里啥都没有哟w");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void saveCookieStoreToFile() throws IOException {
|
|
||||||
log.info("正在保存CookieStore...");
|
|
||||||
File outputFile = new File(BotGlobal.getGlobal().getDataStoreDir(), "cookies.store");
|
|
||||||
if(!outputFile.exists() && !outputFile.createNewFile()){
|
|
||||||
log.error("保存CookieStore失败.");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ObjectOutputStream stream = new ObjectOutputStream(new FileOutputStream(outputFile));
|
|
||||||
stream.writeObject(cookieStore);
|
|
||||||
stream.flush();
|
|
||||||
stream.close();
|
|
||||||
log.info("CookieStore保存成功.");
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void startPixivLoginProxyServer(){
|
|
||||||
ProxyConfig proxyConfig = null;
|
|
||||||
if(proxy != null) {
|
|
||||||
proxyConfig = new ProxyConfig(ProxyType.HTTP, proxy.getHostName(), proxy.getPort());
|
|
||||||
}
|
|
||||||
PixivLoginProxyServer proxyServer = new PixivLoginProxyServer(proxyConfig);
|
|
||||||
Thread proxyServerStartThread = new Thread(() -> {
|
|
||||||
log.info("启动代理服务器...");
|
|
||||||
proxyServer.start(1006);
|
|
||||||
log.info("代理服务器已关闭.");
|
|
||||||
});
|
|
||||||
proxyServerStartThread.setName("LoginProxyServerThread");
|
|
||||||
proxyServerStartThread.start();
|
|
||||||
//System.console().readLine();
|
|
||||||
|
|
||||||
log.info("登录完成后, 使用\"done\"命令结束登录过程.");
|
|
||||||
try(Scanner scanner = new Scanner(System.in)) {
|
|
||||||
while(true) {
|
|
||||||
if (scanner.nextLine().equalsIgnoreCase("done")) {
|
|
||||||
log.info("关闭PLPS服务器...");
|
|
||||||
proxyServer.close();
|
|
||||||
cookieStore = proxyServer.getCookieStore();
|
|
||||||
try {
|
|
||||||
log.info("正在保存CookieStore...");
|
|
||||||
saveCookieStoreToFile();
|
|
||||||
log.info("CookieStore保存完成.");
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("CookieStore保存时发生异常, 本次CookieStore仅可在本次运行使用.", e);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
} else {
|
|
||||||
log.warn("要结束登录过程, 请使用\"done\"命令.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static File getStoreDir() {
|
private static File getStoreDir() {
|
||||||
if(!storeDir.exists() && !storeDir.mkdirs()) {
|
if(!storeDir.exists() && !storeDir.mkdirs()) {
|
||||||
log.error("创建文件夹失败!");
|
log.error("创建文件夹失败!");
|
||||||
|
Loading…
Reference in New Issue
Block a user