feat: scripts

This commit is contained in:
2025-04-05 16:57:26 +08:00
parent bd4fe63cdc
commit 3e996ffab3
62 changed files with 4905 additions and 0 deletions

104
scripts/doubanbook.js Normal file
View File

@@ -0,0 +1,104 @@
#! /usr/bin/env runjs
var oss = require('component-oss.js');
var fastJSON = require('component-json-ex.js');
oss.requireJARs();
requireJAR('jsoup-1.8.1.jar');
var Jsoup = Packages.org.jsoup.Jsoup;
var IOUtil = Packages.me.hatter.tools.commons.io.IOUtil;
var KeyValue = Packages.me.hatter.tools.commons.network.HttpRequest.KeyValue;
var main = () => {
if ($ARGS.length < 1) {
println('No args!!!');
return;
}
var config = $$.rFile('~', '.jssp/config/osssendfile.json').string();
var configJSON = JSON.parse(config);
var url = $ARGS[0];
var content = $$.httpRequest().url(url).get().toString();
var doc = Jsoup.parse(content);
var title = doc.select("#wrapper h1 span").get(0).text();
var bigImg = doc.select(".subject #mainpic a").get(0).attr("href");
var smallImg = doc.select(".subject #mainpic a img").get(0).attr("src");
var bookInfo = doc.select(".subject #info").get(0).text().replaceAll("\\b([^ ]*:)", "\n$1").trim();
var bookAttrs = $$.linkedMap();
$ARR(IOUtil.readToList(bookInfo)).forEach((l) => {
l = l.trim();
var indexOfComma = l.indexOf(':');
var k = l.substring(0, indexOfComma).trim();
var v = l.substring(indexOfComma + 1).trim();
bookAttrs.put(k, v);
});
println('[INFO] Book details:');
println('Name : ' + title);
println('Big img : ' + bigImg);
println('Small img : ' + smallImg);
println('Detail info : ' + fastJSON.prettyJavaJSON(bookAttrs));
print('Confirm [Y/N]:');
var confirm = java.lang.System.console().readLine();
if (!(confirm && $STR(confirm.trim()).toLowerCase() == 'y')) {
xprintln('[ERROR] Y or y is not selected, end!');
return;
}
var uploadImg = (imgUrl) => {
println('[INFO] Send image: ' + imgUrl);
var params = $$.list();
params.add(new KeyValue('jsonp', '1'));
params.add(new KeyValue('token', configJSON.token));
params.add(new KeyValue('url', imgUrl));
params.add(new KeyValue('title', title + imgUrl.substring(imgUrl.lastIndexOf('.'))));
params.add(new KeyValue('keywords', 'Book,Image,Book Cover'));
params.add(new KeyValue('description', 'Book: ' + title + ', url: ' + url + ', detail: ' + fastJSON.prettyJavaJSON(bookAttrs)));
var res = $$.httpRequest().url('https://playsecurity.org/doc/addDoc.jsonp').post(params);
var resJSON = JSON.parse(res);
if (resJSON.status == 200) {
xprintln('[SUCCESS] Send image to doc list successed: ' + res);
} else {
xprintln('[FAIL] Send image to doc list failed: ' + res);
throw ('[FAIL] Send image to doc list failed: ' + res);
}
return 'https://playsecurity.org/getdoc/' + resJSON['id'] + '_' + resJSON['etag'] + '/' + imgUrl.substring(imgUrl.lastIndexOf('/') + 1);
};
var newSmallImg = uploadImg(smallImg);
var newBigImg = newSmallImg;
if ($STR(smallImg) != $STR(bigImg)) {
newBigImg = uploadImg(bigImg);
}
{
println('[INFO] Send book info')
var params = $$.list();
params.add(new KeyValue('jsonp', '1'));
params.add(new KeyValue('token', configJSON.token));
params.add(new KeyValue('url', url));
params.add(new KeyValue('title', title));
params.add(new KeyValue('type', ''));
params.add(new KeyValue('bigImg', newBigImg));
params.add(new KeyValue('smallImg', newSmallImg));
params.add(new KeyValue('bookInfo', $$.stringify(bookAttrs)));
var res = $$.httpRequest().url('https://playsecurity.org/book/addBook.jsonp').post(params);
var resJSON = JSON.parse(res);
if (resJSON.status == 200) {
xprintln('[SUCCESS] Send book to book list successed: ' + res);
} else {
xprintln('[FAIL] Send book to book list failed: ' + res);
throw ('[FAIL] Send book to book list failed: ' + res);
}
}
};
main();