Skip to content

Commit

Permalink
2.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Flameish committed Sep 14, 2019
1 parent 9277bcf commit f4e99b8
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 65 deletions.
17 changes: 16 additions & 1 deletion src/grabber/Download.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public class Download {
boolean getImages;
boolean allChapters;
boolean invertOrder;
public boolean autoChapterToChapter;
long startTime = System.nanoTime();
int firstChapter;
int lastChapter;
Expand All @@ -58,6 +59,9 @@ public Download(GUI myGUI) {
currHostSettings = new HostSettings(host, tocUrl);
blacklistedTags = currHostSettings.blacklistedTags;
// Functions
if (HostSettings.autoChapterToChapterWebsitesList.contains(gui.autoHostSelection.getSelectedItem().toString())) {
autoChapterToChapter = true;
}
autoFetchChapters.getChapters(this);
autoFetchChapters.getMetadata(this);
}
Expand Down Expand Up @@ -126,8 +130,19 @@ public void startAutoDownload() {
}
// Getting the chapters again if it was stopped previously
if (autoFetchChapters.killTask) autoFetchChapters.getChapters(this);

autoFetchChapters.killTask = false;
autoFetchChapters.downloadChapters(this);
if (autoChapterToChapter) {
String[] chapterInfo = {
gui.autoFirstChapterURL.getText(),
gui.autoLastChapterURL.getText(),
currHostSettings.nextChapterBtn
};
chapterContainer = currHostSettings.chapterContainer;
autoFetchChapters.processChaptersToChapters(chapterInfo, this);
} else {
autoFetchChapters.downloadChapters(this);
}
if (!successfulFilenames.isEmpty() && !autoFetchChapters.killTask) {
switch ((String) gui.exportSelection.getSelectedItem()) {
case "Calibre":
Expand Down
54 changes: 51 additions & 3 deletions src/grabber/HostSettings.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
package grabber;

import java.util.Arrays;
import java.util.List;

Expand All @@ -12,12 +11,21 @@ public class HostSettings {
"Royal Road",
"Gravity Tales",
"Volare Novels",
"Light Novels Translations",
"Creative Novels",
"WordExcerpt",
"BoxNovel",
"LiberSpark",
"BoxNovel",
"Wordrain",
"Comrademao",
"Light Novels Translations",
"Chrysanthemum Garden"
};
private static String[] autoChapterToChapterWebsites = {
"Comrademao",
"Creative Novels"
};
public static List<String> autoChapterToChapterWebsitesList = Arrays.asList(autoChapterToChapterWebsites);


public String chapterLinkSelecter;
String titleHostName;
Expand All @@ -26,6 +34,7 @@ public class HostSettings {
public List<String> blacklistedTags;
int ordinalIndexForBaseNovel;
String chapterContainer;
String nextChapterBtn;
String bookTitleSelector;
String bookAuthorSelector;
String bookSubjectSelector;
Expand Down Expand Up @@ -150,6 +159,45 @@ public HostSettings(String domain, String urla) {
bookAuthorSelector = "";
bookSubjectSelector = ".novel-container a[href^=https://chrysanthemumgarden.com/genre/]";
break;
case "comrademao":
host = "https://comrademao.com/";
ordinalIndexForBaseNovel = 0;
chapterLinkSelecter = "";
chapterContainer = "article div";
nextChapterBtn = "a.btn.btn-default.btn-sm:eq(2)";
titleHostName = "";
blacklistedTags = Arrays.asList("div#CollapseRaw");
bookTitleSelector = "div.wrap-content h4";
bookCoverSelector = "div.wrap-thumbnail img";
bookAuthorSelector = "div.author";
bookSubjectSelector = "a[rel=tag]";
break;
case "creativenovels":
host = "https://creativenovels.com/";
ordinalIndexForBaseNovel = 0;
chapterLinkSelecter = "";
chapterContainer = ".entry-content";
nextChapterBtn = "a.x-btn.nextkey";
titleHostName = "";
blacklistedTags = Arrays.asList(".mNS", ".support-placement");
bookTitleSelector = "div.e45344-16.x-text.bK_C";
bookCoverSelector = "img.book_cover";
bookAuthorSelector = "div.e45344-17.x-text.bK_C a";
bookSubjectSelector = "div.genre_novel";
break;
case "wordrain":
host = "https://wordrain69.com/";
ordinalIndexForBaseNovel = 5;
chapterLinkSelecter = "ul.main.version-chap li a:not([title])";
chapterContainer = ".text-left";
nextChapterBtn = "";
titleHostName = "-Wordrain69";
//blacklistedTags = Arrays.asList("");
bookTitleSelector = ".post-title h1";
bookCoverSelector = ".summary_image img";
bookAuthorSelector = ".author-content a";
bookSubjectSelector = ".genres-content a";
break;
}
}
}
1 change: 0 additions & 1 deletion src/grabber/Shared.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,6 @@ static void saveChapterWithHTML(String url, int chapterNumber, String chapterNam
// Getting the next chapter URL from the "nextChapterBtn" href for Chapter-To-Chapter.
if (!currGrab.nextChapterBtn.equals("NOT_SET"))
currGrab.nextChapterURL = doc.select(currGrab.nextChapterBtn).first().absUrl("href");

Element chapterContent = doc.select(chapterContainer).first();
// Remove unwanted tags from chapter container.
if (!(currGrab.blacklistedTags == null)) {
Expand Down
56 changes: 50 additions & 6 deletions src/grabber/autoFetchChapters.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@ static void getChapters(Download currGrab) {
// Connect to webpage
Document doc = Jsoup.connect(currGrab.currHostSettings.url).get();
// Get chapter links and names.
Elements chapterItems = doc.select(currGrab.currHostSettings.chapterLinkSelecter);
Elements links = chapterItems.select("a[href]");
for (Element chapterLink : links) {
currGrab.chapterLinks.add(chapterLink.attr("abs:href"));
currGrab.chaptersNames.add(chapterLink.text());
if (!currGrab.autoChapterToChapter) {
Elements chapterItems = doc.select(currGrab.currHostSettings.chapterLinkSelecter);
Elements links = chapterItems.select("a[href]");
for (Element chapterLink : links) {
currGrab.chapterLinks.add(chapterLink.attr("abs:href"));
currGrab.chaptersNames.add(chapterLink.text());
}
}
currGrab.tocDoc = doc;
} catch (IllegalArgumentException | IOException e) {
Expand Down Expand Up @@ -141,11 +143,15 @@ static void getMetadata(Download currGrab) {
currGrab.bookSubjects = null;
currGrab.gui.autoBookSubjects.setText("");
}
// Chapter
// Chapter number
if (!currGrab.chapterLinks.isEmpty()) {
currGrab.gui.autoChapterAmount.setText(String.valueOf(currGrab.chapterLinks.size()));
currGrab.gui.autoGetNumberButton.setEnabled(true);
}
if (currGrab.autoChapterToChapter) {
currGrab.gui.autoChapterAmount.setText("Unknown");
currGrab.gui.autoGetNumberButton.setEnabled(false);
}
// Cover
if (!currGrab.currHostSettings.bookCoverSelector.isEmpty()) {
if (doc.select(currGrab.currHostSettings.bookCoverSelector) != null && !doc.select(currGrab.currHostSettings.bookCoverSelector).isEmpty()) {
Expand Down Expand Up @@ -219,6 +225,44 @@ private static void processAllChapters(Download currGrab) {
}
}

/**
* Handles downloading chapter to chapter.
*/
static void processChaptersToChapters(String[] args, Download currGrab) {
currGrab.gui.appendText(currGrab.window, "[INFO]Connecting...");
currGrab.gui.setMaxProgress(currGrab.window, 9001);
String nextChapter = args[0];
String lastChapter = args[1];
currGrab.nextChapterBtn = args[2];
int chapterNumber = 0;
while (true) {
chapterNumber++;
Shared.saveChapterWithHTML(nextChapter, chapterNumber, "Chapter " + chapterNumber, currGrab.chapterContainer, currGrab);
nextChapter = currGrab.nextChapterURL;
if (nextChapter.equals(lastChapter) || (nextChapter + "/").equals(lastChapter)) {
chapterNumber++;
Shared.sleep(currGrab.waitTime);
currGrab.nextChapterBtn = "NOT_SET";
Shared.saveChapterWithHTML(nextChapter, chapterNumber, "Chapter " + chapterNumber, currGrab.chapterContainer, currGrab);
break;
}
if (killTask) {
currGrab.gui.appendText(currGrab.window, "[INFO]Stopped.");
Path chaptersFolder = Paths.get(currGrab.saveLocation + "/chapters");
Path imagesFolder = Paths.get(currGrab.saveLocation + "/images");
try {
if (Files.exists(imagesFolder)) Shared.deleteFolderAndItsContent(imagesFolder);
if (Files.exists(chaptersFolder)) Shared.deleteFolderAndItsContent(chaptersFolder);
} catch (IOException e) {
currGrab.gui.appendText(currGrab.window, e.getMessage());
e.printStackTrace();
}
return;
}
Shared.sleep(currGrab.waitTime);
}
}

/**
* Displays chapter name and chapter number.
* TODO: pass doc directly.
Expand Down
Loading

0 comments on commit f4e99b8

Please sign in to comment.