Search in sources :

Example 1 with MDRuntimeException

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);
}
Also used : StringWriter(java.io.StringWriter) JarInputStream(java.util.jar.JarInputStream) Attributes(java.util.jar.Attributes) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException) Manifest(java.util.jar.Manifest) URL(java.net.URL) PrintWriter(java.io.PrintWriter)

Example 2 with MDRuntimeException

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;
}
Also used : MalformedURLException(java.net.MalformedURLException) TreeSet(java.util.TreeSet) Element(org.jsoup.nodes.Element) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) HosterListEntry(de.herrlock.manga.index.entity.HosterListEntry) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) URL(java.net.URL)

Example 3 with MDRuntimeException

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);
    }
}
Also used : Path(java.nio.file.Path) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException)

Example 4 with MDRuntimeException

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);
}
Also used : MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) File(java.io.File)

Example 5 with MDRuntimeException

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);
    }
}
Also used : Path(java.nio.file.Path) MDRuntimeException(de.herrlock.manga.exceptions.MDRuntimeException) IOException(java.io.IOException)

Aggregations

MDRuntimeException (de.herrlock.manga.exceptions.MDRuntimeException)13 IOException (java.io.IOException)11 URL (java.net.URL)6 InputStream (java.io.InputStream)4 MalformedURLException (java.net.MalformedURLException)3 HosterListEntry (de.herrlock.manga.index.entity.HosterListEntry)2 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 URLClassLoader (java.net.URLClassLoader)2 Path (java.nio.file.Path)2 Properties (java.util.Properties)2 TreeSet (java.util.TreeSet)2 Attributes (java.util.jar.Attributes)2 Manifest (java.util.jar.Manifest)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 Predicate (com.google.common.base.Predicate)1 MDException (de.herrlock.manga.exceptions.MDException)1 Index (de.herrlock.manga.index.entity.Index)1