Fixed File Parsing to use new Pixiv Site Layout.

pull/1/head
sigonasr2 5 years ago
parent 044f8b77dd
commit dd7f62e50e
  1. BIN
      Tagger/Tagger.jar
  2. 16
      Tagger/src/PixivManager.java
  3. 7
      Tagger/src/Tagger.java
  4. 13
      Tagger/src/utils.java

Binary file not shown.

@ -37,7 +37,7 @@ public class PixivManager {
bwOutput = new BufferedWriter(fwOutput);
for (String s : imageTag.pixiv_image_list) {
String url = "https://www.pixiv.net/member_illust.php?mode=medium&illust_id="+s;
String url = "https://www.pixiv.net/en/artworks/"+s;
try {
if (!new File("downloadedData/temp"+s+".html").exists()) {
System.out.println("Starting download of "+url+" ...");
@ -45,7 +45,8 @@ public class PixivManager {
String[] data = utils.readFromFile("downloadedData/temp"+s+".html");
int scriptEndLine = 0;
while (scriptEndLine<data.length) {
if (data[scriptEndLine].contains("return Object.freeze(arg)")) {
if (data[scriptEndLine].contains("<meta name=\"preload-data\" id=\"meta-preload-data\" content='")) {
System.out.println("Found JSON Target line at line "+scriptEndLine+". :: "+data[scriptEndLine] );
break;
}
scriptEndLine++;
@ -60,9 +61,12 @@ public class PixivManager {
try {
fw = new FileWriter(finaldata);
BufferedWriter bw = new BufferedWriter(fw);
int cutpos = data[scriptEndLine+1].indexOf("})(")+3;
if (cutpos<data[scriptEndLine+1].length()) {
bw.write(data[scriptEndLine+1].substring(cutpos,data[scriptEndLine+1].indexOf(");</script>")));
System.out.println(data[scriptEndLine]);
int cutpos = data[scriptEndLine].indexOf("<meta name=\"preload-data\" id=\"meta-preload-data\" content='")+58;
System.out.println(data[scriptEndLine].length()+"///"+data[scriptEndLine].indexOf("}}}'>")+"///"+cutpos);
if (cutpos<data[scriptEndLine].length()) {
bw.write(data[scriptEndLine].substring(cutpos,data[scriptEndLine].indexOf("}}}'>")+3));
System.out.println(data[scriptEndLine].substring(cutpos,data[scriptEndLine].indexOf("}}}'>")+3));
}
bw.close();
fw.close();
@ -72,7 +76,7 @@ public class PixivManager {
JSONObject jsonData = utils.readJsonFromFile("finaltemp");
//System.out.println(Arrays.deepToString(JSONObject.getNames(jsonData.getJSONObject("preload"))));
//System.out.println(Arrays.deepToString(JSONObject.getNames(jsonData.getJSONObject("preload").getJSONObject("illust"))));
JSONArray tagsArray = jsonData.getJSONObject("preload").getJSONObject("illust").getJSONObject(s).getJSONObject("tags").getJSONArray("tags");
JSONArray tagsArray = jsonData.getJSONObject("illust").getJSONObject(s).getJSONObject("tags").getJSONArray("tags");
for (int i=0;i<tagsArray.length();i++) {
boolean hasEnglishTag=false;
JSONObject tag = tagsArray.getJSONObject(i);

@ -33,10 +33,15 @@ public class Tagger {
}
//Process tool = Runtime.getRuntime().exec("tool.exe -exif:XPKeywords=\""+sb.toString()+"\" "+imagetoTag.getAbsolutePath()+" -overwrite_original_in_place -P");
String command = "tool.exe -exif:XPKeywords=\""+sb.toString()+"\" "+imagetoTag.getAbsolutePath()+" -overwrite_original_in_place -P";
String command = "tool.exe -exif:XPKeywords=\""+sb.toString()+"\" \""+imagetoTag.getAbsolutePath()+"\" -overwrite_original_in_place -P";
CommandLine cmdLine = CommandLine.parse(command);
DefaultExecutor executor = new DefaultExecutor();
int exitValue = executor.execute(cmdLine);
try {
Thread.sleep(300);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}

@ -10,6 +10,7 @@ import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.net.ConnectException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
@ -267,10 +268,14 @@ public class utils {
//connection.setRequestMethod("GET");
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("User-Agent", "Mozilla/5.0");
ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
try {
ReadableByteChannel rbc = Channels.newChannel(connection.getInputStream());
FileOutputStream fos = new FileOutputStream(file);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
} catch (ConnectException e) {
System.out.println("Failed to connect, moving on...");
}
}
public static JSONArray readJsonArrayFromUrl(String url, String file, boolean writeToFile) throws IOException, JSONException {

Loading…
Cancel
Save