use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.
the class Main method printVersion.
private static void printVersion() {
logger.traceEntry();
final Manifest manifest;
final URL mangaLauncherJarUrl = Main.class.getProtectionDomain().getCodeSource().getLocation();
logger.debug("Reading Manifest from jar at {}", mangaLauncherJarUrl);
try (JarInputStream j = new JarInputStream(mangaLauncherJarUrl.openStream())) {
Manifest m = j.getManifest();
manifest = MoreObjects.firstNonNull(m, new Manifest());
} catch (IOException ex) {
throw new MDRuntimeException(ex);
}
final StringWriter stringWriter = new StringWriter();
final PrintWriter printwriter = new PrintWriter(stringWriter);
printwriter.println();
Attributes infoAttributes = manifest.getAttributes("Info");
logger.debug("infoAttributes: {}", infoAttributes);
Attributes gitAttributes = manifest.getAttributes("Git");
logger.debug("gitAttributes: {}", gitAttributes);
if (infoAttributes == null || gitAttributes == null) {
printwriter.println("Cannot read all data, probably a development-version launched from an IDE.");
} else {
printwriter.println("MangaDownloader");
printwriter.println(" Version: " + infoAttributes.getValue("Version"));
printwriter.println();
printwriter.println("Details: ");
printwriter.println(" Built at: " + infoAttributes.getValue("Built-At"));
printwriter.println(" Commit: " + gitAttributes.getValue("Commit") + ":" + gitAttributes.getValue("Branch") + " (" + gitAttributes.getValue("Date") + ")");
}
logger.info(stringWriter);
}
use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.
the class MangaFoxChapterList method getAvailabile.
@Override
public Collection<HosterListEntry> getAvailabile(final IndexerConfiguration conf) {
Document doc;
final URL baseUrl;
try {
baseUrl = new URL(getDetails().baseUrl());
URL listUrl = new URL(baseUrl, "/manga/");
doc = Utils.getDocument(listUrl, conf);
} catch (IOException ex) {
throw new MDRuntimeException(ex);
}
Elements elements = doc.select("div#page div.manga_list > ul > li > a");
Collection<HosterListEntry> entries = new TreeSet<>(HosterListEntry.NAME_COMPARATOR);
for (Element element : elements) {
HosterListEntry entry = new HosterListEntry();
entry.setName(element.text());
try {
entry.setUrl(new URL(baseUrl, element.attr("href")).toExternalForm());
} catch (MalformedURLException ex) {
logger.catching(Level.DEBUG, ex);
}
entries.add(entry);
}
return entries;
}
use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.
the class IndexerMain method writeIndex.
public static void writeIndex(final IndexerConfiguration conf) {
try {
// the index-directory
final Path indexDir = Files.createDirectories(Paths.get("index"));
// write data.js
logger.debug("Writing index-data");
final Path dataJs = indexDir.resolve("data.js");
exportDataJs(dataJs, conf);
// write index.html
logger.debug("Copying index-html");
final Path indexHtml = indexDir.resolve("index.html");
copyIndexHtml(indexHtml);
// unzip DataTables
logger.debug("Unzipping DataTables");
final Path datatablesDir = Files.createDirectories(indexDir.resolve("DataTables"));
unzipDatatablesZip(datatablesDir);
} catch (IOException ex) {
throw new MDRuntimeException(ex);
}
}
use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.
the class MDownloader method downloadChapter.
/**
* downloads the Chapter with the "name"of {@code key} and the pictures from {@code urlMap}<br>
* adds every Chapter to the DownloadQueueContainer and starts the download
*
* @param key
* the name of the chapter (in general it is a number as String)
* @param entries
* a map containing the URLs for the pictures
* @see DownloadQueueContainer#downloadPages()
*/
private void downloadChapter(final String key, final EntryList<Integer, URL> entries) {
logger.traceEntry("key: {}", key);
logger.info("Download chapter {} ({} pages)", key, entries.size());
File chapterFolder = new File(getTargetFolder(), key);
if (chapterFolder.exists() || chapterFolder.mkdirs()) {
// add pictures to queue
this.dqc.addEntryList(chapterFolder, entries);
// start download
this.dqc.downloadPages();
} else {
throw new MDRuntimeException(chapterFolder + " does not exists and could not be created");
}
logger.info("finished chapter {}", key);
}
use of de.herrlock.manga.exceptions.MDRuntimeException in project Manga by herrlock.
the class ViewPage method execute.
/**
* Creates the new ViewPage-instance and prints the html to the destination
*
* @param folder
* the folder to save the created files into
*/
public static void execute(final File folder) {
logger.trace(folder);
ViewPage viewPage = new ViewPage(folder);
Path indexhtml = folder.toPath().resolve("index.html");
try {
viewPage.saveAt(indexhtml);
viewPage.copyFiles();
} catch (IOException ex) {
throw new MDRuntimeException(ex);
}
}
Aggregations