Skip to content
This repository has been archived by the owner on Jan 19, 2022. It is now read-only.

Commit

Permalink
Merge pull request #3 from megoRU/beta
Browse files Browse the repository at this point in the history
Version 2.1.5 | Stable

1. Теперь текст чистый*

*Не содержит кода html. Проверено на 15 фанфиках. Возможно где-то будет появляться. Тогда будем фиксить!
  • Loading branch information
megoRU authored Nov 13, 2020
2 parents 459d7c0 + a5a6628 commit c0b18f3
Showing 1 changed file with 46 additions and 14 deletions.
60 changes: 46 additions & 14 deletions src/main/java/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.ImageIcon;
Expand All @@ -31,6 +30,7 @@ public class Main extends JFrame {
private static final String regexURL = "https?:\\/\\/?[\\dfincbook.net\\/readfic]+\\/[0-9]+\\/[0-9]+[#a-z_]+";
private static final String regexURL2 = "https?:\\/\\/?[\\dfincbook.net\\/readfic]+\\/[0-9]+\\/[0-9]+";
private static final String regexURL3 = "https?:\\/\\/?[\\dfincbook.net\\/readfic]+\\/[0-9]+";
private static final String regexURL4 = "https?:\\/\\/?[\\dfincbook.net\\/readfic]+\\/[0-9]+.+";
private static final String pathForHTML = "C:/Users/" + userName + "/Desktop/site.txt";

private javax.swing.JTextField jTextField1;
Expand Down Expand Up @@ -160,15 +160,19 @@ private void jTextField1ActionPerformed(ActionEvent evt) {
}

public void parsing(String textFromJText) {
if (!textFromJText.matches(regexURL) && !textFromJText.matches(regexURL2) && !textFromJText
.matches(regexURL3)) {
if (!textFromJText.matches(regexURL)
&& !textFromJText.matches(regexURL2)
&& !textFromJText.matches(regexURL3)
&& !textFromJText.matches(regexURL4)) {
jTextField1.setText("URL адрес неверный!");
jTextField1.setText("");
return;
}
try {
if (textFromJText.matches(regexURL) || textFromJText.matches(regexURL2) || textFromJText
.matches(regexURL3)) {
if (textFromJText.matches(regexURL)
|| textFromJText.matches(regexURL2)
|| textFromJText.matches(regexURL3)
|| textFromJText.matches(regexURL4)) {

Document doc = Jsoup.connect(textFromJText)
.data("query", "Java")
Expand All @@ -177,10 +181,9 @@ public void parsing(String textFromJText) {
.cookie("auth", "token")
.get();
//Парсит название
String title = doc.title();
String title2 = title.replaceAll(":", " ");
int titleIndex = title2.indexOf("—");
String textTitle = title2.substring(0, titleIndex - 1);
String title = doc.title().replaceAll(":", " ");
int titleIndex = title.indexOf("—");
String textTitle = title.substring(0, titleIndex - 1);

URL url;
InputStream is = null;
Expand All @@ -193,9 +196,25 @@ public void parsing(String textFromJText) {
FileWriter writerFile = new FileWriter(pathForHTML, StandardCharsets.UTF_8);

//Сохраняем просто в файл site.html
//форматируем текст
while ((lines = brs.readLine()) != null) {
writerFile
.write(lines.replaceAll(" ", "").trim() + System.getProperty("line.separator"));
writerFile.write(lines
.replaceAll(" ", "")
.trim()
.replaceAll("</b>", "")
.replaceAll("</div>", "")
.replaceAll("</i>", "")
.replaceAll("<i>", "")
.replaceAll("<p align=\"center\" style=\"margin: 0;\">", "")
.replaceAll("</p>", "")
.replaceAll("<div class=\"part-comment-bottom mx-10 mx-xs-5\">", "")
.replaceAll("<strong>", "")
.replaceAll("</strong>", "")
.replaceAll("<div class=\"urlize\">", "")
.replaceAll("<br />", "")
.replaceAll("<p align=\"right\" style=\"margin: 0;\"><b>", "")
.replaceAll("<p align=\"right\" style=\"margin: 0;\">", "")
+ System.getProperty("line.separator"));
}

is.close();
Expand Down Expand Up @@ -236,6 +255,7 @@ public void parsing(String textFromJText) {

public static void delete(String filePathIn, String filePathOut, int toRemove) {
int count = 0;
int first = 0;
File inputFile = new File(filePathIn);
File tempFile = new File(filePathOut);
try {
Expand All @@ -247,8 +267,20 @@ public static void delete(String filePathIn, String filePathOut, int toRemove) {
while ((currentLine = reader.readLine()) != null) {
count++;
if (count < toRemove) {

}
if (count >= toRemove) {
if (count > toRemove) {
if (first < 1) {
first++;
int length = currentLine.length();
int symbol = currentLine.lastIndexOf(">") + 1;
String firstLine = currentLine.substring(symbol, length);
bufferWriter.write(firstLine + System.getProperty("line.separator"));
continue;
}
if (first > 1) {
bufferWriter.write(currentLine.trim() + System.getProperty("line.separator"));
}
bufferWriter.write(currentLine.trim() + System.getProperty("line.separator"));
}
}
Expand Down Expand Up @@ -290,7 +322,7 @@ public static int linesFirst(String filePathIn) {
try {
File inputFile = new File(filePathIn);
BufferedReader reader = new BufferedReader(new FileReader(inputFile));
String needWorld = "itemprop=\"articleBody\"";
String needWorld = "articleBody";
while (!reader.readLine().trim().contains(needWorld)) {
lineCount++;
}
Expand All @@ -313,7 +345,7 @@ public static int linesSecond(String filePathIn) {
lineCount++;
}
reader.close();
return lineCount;
return lineCount - 2;
} catch (Exception e) {
e.printStackTrace();
}
Expand Down

0 comments on commit c0b18f3

Please sign in to comment.