Skip to content

Commit

Permalink
2.8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Flameish committed Jul 8, 2020
1 parent c4d6c6d commit 72d5629
Show file tree
Hide file tree
Showing 25 changed files with 1,698 additions and 432 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ Novel Grabber was build in java with: <br>
* [epublib](https://github.com/psiegman/epublib)
* [webdrivermanager](https://github.com/bonigarcia/webdrivermanager)
* [selenium ](https://selenium.dev/)
* [Simple Java Mail ](https://github.com/bbottema/simple-java-mail/)

11 changes: 6 additions & 5 deletions src/files/about.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

CREDITS:
- json.simple https://code.google.com/archive/p/json-simple/
- jsoup https://jsoup.org/
- webdrivermanager https://github.com/bonigarcia/webdrivermanager
- selenium https://selenium.dev/
- Images https://icons8.com/
* [jsoup](https://www.jsoup.org/)
* [json-simple](https://code.google.com/archive/p/json-simple/)
* [epublib](https://github.com/psiegman/epublib)
* [webdrivermanager](https://github.com/bonigarcia/webdrivermanager)
* [selenium ](https://selenium.dev/)
* [Simple Java Mail ](https://github.com/bbottema/simple-java-mail/)
Binary file added src/files/images/download_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/files/images/starred_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/files/images/unstarred_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions src/grabber/Chapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void saveChapter(Novel novel) {
}
} catch (IOException | IllegalArgumentException e) {
e.printStackTrace();
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window,"[ERROR]"+e.getMessage());
}
status = 2;
Expand All @@ -70,7 +70,7 @@ void saveChapter(Novel novel) {
if (novel.host.url.equals("https://tapread.com/")) chapterContent = doc;

if (chapterContent == null) {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window,"[ERROR]Chapter container (" + novel.host.chapterContainer + ") not found.");
}
return;
Expand All @@ -96,7 +96,7 @@ void saveChapter(Novel novel) {
}

novel.metadata.wordCount = novel.metadata.wordCount + GrabberUtils.getWordCount(chapterContent.toString());
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.pagesCountLbl.setText(String.valueOf(novel.metadata.wordCount / 300));
}

Expand Down Expand Up @@ -128,12 +128,12 @@ void saveChapter(Novel novel) {
out.println(EPUB.htmlFoot);
} catch (IOException e) {
e.printStackTrace();
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window, "[ERROR]"+e.getMessage());
}
} finally {
status = 1;
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window, "[INFO]"+name+" saved.");
}
System.out.println("[INFO]"+name+" saved.");
Expand Down
2 changes: 1 addition & 1 deletion src/grabber/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Driver(Novel novel) {
}

private void driverSetup() {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window, "[INFO]Starting headerless browser...");
}
switch (novel.options.browser) {
Expand Down
41 changes: 31 additions & 10 deletions src/grabber/EPUB.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import nl.siegmann.epublib.domain.Resource;
import nl.siegmann.epublib.epub.EpubWriter;
import system.init;
import system.persistent.Settings;

import javax.imageio.IIOException;
import javax.imageio.ImageIO;
Expand Down Expand Up @@ -37,7 +38,7 @@ public EPUB(Novel novel) {

public void writeEpub() {
try {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window, "[INFO]Writing epub...");
}
Book book = new Book();
Expand All @@ -64,7 +65,7 @@ public void writeEpub() {
}
// Set cover image & page
if (novel.metadata.bookCover != null && !novel.metadata.bookCover.isEmpty()) {
if (novel.options.window.equals("auto")) {
if (novel.options.window.equals("auto") || novel.options.window.equals("checker")) {
// Add cover image as a resource
inputStream = new FileInputStream(novel.options.saveLocation + "/images/" + novel.metadata.bookCover);
resource = new Resource(inputStream, novel.metadata.bookCover);
Expand Down Expand Up @@ -132,10 +133,30 @@ public void writeEpub() {
// Create EpubWriter
EpubWriter epubWriter = new EpubWriter();
// Write the Book as Epub
epubWriter.write(book, new FileOutputStream(novel.options.saveLocation +
File.separator + novel.metadata.bookAuthor + " - " + novel.metadata.bookTitle + ".epub"));
//novel.gui.appendText(novel.window, "[INFO]Epub successfully created.");

String epubFilename;
switch (Settings.getEPUBOutputFormat()) {
case 0:
epubFilename = (novel.metadata.bookAuthor + " - " + novel.metadata.bookTitle + ".epub").replaceAll(" ","");
epubWriter.write(book, new FileOutputStream(novel.options.saveLocation
+ "/" + epubFilename));
break;
case 1:
epubFilename = (novel.metadata.bookTitle + " - " + novel.metadata.bookAuthor + ".epub").replaceAll(" ","");
epubWriter.write(book, new FileOutputStream(novel.options.saveLocation
+ "/" + epubFilename));
break;
case 2:
epubFilename = (novel.metadata.bookTitle + ".epub").replaceAll(" ", "");
epubWriter.write(book, new FileOutputStream(novel.options.saveLocation
+ "/" + epubFilename));
break;
default:
epubFilename = (novel.metadata.bookAuthor + " - " + novel.metadata.bookTitle + ".epub").replaceAll(" ","");
epubWriter.write(book, new FileOutputStream(novel.options.saveLocation
+ "/" + epubFilename));
break;
}
novel.epubFilename = epubFilename;
// Delete image and chapter files
Path chaptersFolder = Paths.get(novel.options.saveLocation + "/chapters");
Path imagesFolder = Paths.get(novel.options.saveLocation + "/images");
Expand Down Expand Up @@ -179,7 +200,7 @@ public void createCoverPage() {
} catch (IOException e) {
e.printStackTrace();
System.out.println("[ERROR]Could not write cover image to file.");
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window, "[ERROR]Could not write cover image to file.");
}
}
Expand All @@ -195,7 +216,7 @@ public void createCoverPage() {
out.print("</div>" + NL + htmlFoot);
novel.extraPages.add(fileName);
} catch (IOException e) {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window,e.getMessage());

}
Expand All @@ -215,7 +236,7 @@ public void createToc() {
out.print("</p>" + NL + htmlFoot);
novel.extraPages.add(fileName);
} catch (IOException e) {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window,e.getMessage());

}
Expand All @@ -232,7 +253,7 @@ public void createDescPage() {
out.print("</div>" + NL + htmlFoot);
novel.extraPages.add(fileName);
} catch (IOException e) {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText(novel.options.window,e.getMessage());
}
e.printStackTrace();
Expand Down
8 changes: 4 additions & 4 deletions src/grabber/GrabberUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ static void downloadImage(String src, Novel currGrab) {
currGrab.imageLinks.add(src);
currGrab.imageNames.add(name);

if(init.window != null) {
if(init.window != null && !currGrab.options.window.equals("checker")) {
init.window.appendText(currGrab.options.window, "[INFO]" + name + " saved.");
}
//General catch
} catch (Throwable e) {
e.printStackTrace();
if(init.window != null) {
if(init.window != null && !currGrab.options.window.equals("checker")) {
init.window.appendText(currGrab.options.window, "[ERROR]Failed to save " + name);
}
}
Expand Down Expand Up @@ -115,7 +115,7 @@ static BufferedImage getBufferedCover(String src, Novel novel) {
//General catch
} catch (Throwable e) {
e.printStackTrace();
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.appendText("auto", "[ERROR]Failed to get" + name);
}
}
Expand Down Expand Up @@ -158,7 +158,7 @@ public static int ordinalIndexOf(String str, String substr, int n) {
/**
* Freeze thread for selected wait time.
*/
static void sleep(int waitTime) {
public static void sleep(int waitTime) {
try {
Thread.sleep(waitTime);
} catch (InterruptedException ex) {
Expand Down
23 changes: 11 additions & 12 deletions src/grabber/Metadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,19 +36,18 @@ void getTitle() {
if (!novel.host.bookTitleSelector.isEmpty()) {
if (novel.tableOfContent.select(novel.host.bookTitleSelector) != null && !novel.tableOfContent.select(novel.host.bookTitleSelector).isEmpty()) {
bookTitle = novel.tableOfContent.select(novel.host.bookTitleSelector).first().text().replaceAll("[\\\\/:*?\"<>|]", "");
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoBookTitle.setText(bookTitle);
}
} else {
bookTitle = "Unknown";
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoBookTitle.setText("Unknown");

}
}
} else {
bookTitle = "Unknown";
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoBookTitle.setText("Unknown");
}
}
Expand All @@ -71,18 +70,18 @@ void getAuthor() {
if (!novel.host.bookAuthorSelector.isEmpty()) {
if (novel.tableOfContent.select(novel.host.bookAuthorSelector) != null && !novel.tableOfContent.select(novel.host.bookAuthorSelector).isEmpty()) {
bookAuthor = novel.tableOfContent.select(novel.host.bookAuthorSelector).first().text();
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoAuthor.setText(bookAuthor);
}
} else {
bookAuthor = "Unknown";
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoAuthor.setText("Unknown");
}
}
} else {
bookAuthor = "Unknown";
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoAuthor.setText("Unknown");
}
}
Expand All @@ -98,7 +97,7 @@ void getTags() {

// Display book subjects on GUI
int maxNumberOfSubjects = 0;
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoBookSubjects.setText("<html>");
for (String eachTag : bookSubjects) {
init.window.autoBookSubjects.setText(init.window.autoBookSubjects.getText() + eachTag + ", ");
Expand All @@ -116,22 +115,22 @@ void getTags() {
}
} else {
bookSubjects.add("Unknown");
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoBookSubjects.setText("Unknown");

}
}
} else {
bookSubjects.add("Unknown");
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoBookSubjects.setText("Unknown");
}
}
}

void getChapterNumber() {
if (!novel.chapters.isEmpty()) {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.autoChapterAmount.setText(String.valueOf(novel.chapters.size()));
init.window.autoGetNumberButton.setEnabled(true);
}
Expand All @@ -154,7 +153,7 @@ void getCover() {
}
bufferedCover = GrabberUtils.getBufferedCover(coverLink, novel);
if(!novel.imageNames.isEmpty()) {
if(init.window != null) {
if(init.window != null && !novel.options.window.equals("checker")) {
init.window.setBufferedCover(bufferedCover);
}
bookCover = novel.imageNames.get(0);
Expand Down
12 changes: 6 additions & 6 deletions src/grabber/Novel.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class Novel {
List<String> extraPages = new ArrayList<>();
List<String> imageLinks = new ArrayList<>();
List<String> imageNames = new ArrayList<>();

public String epubFilename;
public Novel() {
}

Expand All @@ -59,7 +59,7 @@ public void getChapterList() {

public void downloadChapters() throws Exception {
System.out.println("[INFO]Starting download...");
if(init.window != null) {
if(init.window != null && !options.window.equals("checker")) {
init.window.setMaxProgress(options.window, options.lastChapter-options.firstChapter+1);
}
if(reGrab) {
Expand All @@ -85,15 +85,15 @@ public void downloadChapters() throws Exception {
if (Files.exists(chaptersFolder)) GrabberUtils.deleteFolderAndItsContent(chaptersFolder);
} catch (IOException e) {
e.printStackTrace();
if(init.window != null) {
if(init.window != null && !options.window.equals("checker")) {
init.window.appendText(options.window, e.getMessage());
}
}
throw new Exception("[INFO]Grabbing stopped.");
}
chapters.get(i).saveChapter(this);

if(init.window != null) {
if(init.window != null && !options.window.equals("checker")) {
init.window.updateProgress(options.window);
}

Expand All @@ -117,14 +117,14 @@ public void getMetadata() {
*/
public void report() {
System.out.println("[INFO]Output: "+options.saveLocation + " " + metadata.bookAuthor + " - " + metadata.bookTitle + ".epub");
if(init.window != null) {
if(init.window != null && !options.window.equals("checker")) {
init.window.appendText(options.window,"[INFO]Finished.");
}
if(options.invertOrder) Collections.reverse(chapters);
// Print failed chapters
for(Chapter chapter: chapters) {
if(chapter.status == 2)
if(init.window != null) {
if(init.window != null && !options.window.equals("checker")) {
init.window.appendText(options.window,"[WARN]Failed to grab: " +chapter.name);
}
}
Expand Down
Loading

0 comments on commit 72d5629

Please sign in to comment.