Search in sources :

Example 1 with HosterListEntry

use of de.herrlock.manga.index.entity.HosterListEntry 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 2 with HosterListEntry

use of de.herrlock.manga.index.entity.HosterListEntry in project Manga by herrlock.

the class HosterImpl method getAvailabile.

public Collection<HosterListEntry> getAvailabile(@SuppressWarnings("unused") final IndexerConfiguration conf) {
    HosterListEntry hosterListEntry = new HosterListEntry();
    hosterListEntry.setName("&lt;no&nbsp;entries&gt;");
    hosterListEntry.setUrl(getDetails().baseUrl());
    return Arrays.asList(hosterListEntry);
}
Also used : HosterListEntry(de.herrlock.manga.index.entity.HosterListEntry)

Example 3 with HosterListEntry

use of de.herrlock.manga.index.entity.HosterListEntry in project Manga by herrlock.

the class MangaPandaChapterList 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, "/alphabetical");
        doc = Utils.getDocument(listUrl, conf);
    } catch (IOException ex) {
        throw new MDRuntimeException(ex);
    }
    Elements elements = doc.select("div.series_col ul.series_alpha > 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 4 with HosterListEntry

use of de.herrlock.manga.index.entity.HosterListEntry in project Manga by herrlock.

the class Indexer method createJsonIndex.

public static JsonArray createJsonIndex(final IndexerConfiguration conf) {
    Index index = createIndex(conf);
    JsonArrayBuilder arrayBuilder = Json.createArrayBuilder();
    for (HosterList hosterList : index.getHosters()) {
        for (HosterListEntry hosterListEntry : hosterList.getMangas()) {
            arrayBuilder.add(// 
            Json.createObjectBuilder().add("hosterName", // 
            hosterList.getHosterName()).add("name", // 
            hosterListEntry.getName()).add("url", hosterListEntry.getUrl()));
        }
    }
    return arrayBuilder.build();
}
Also used : HosterList(de.herrlock.manga.index.entity.HosterList) Index(de.herrlock.manga.index.entity.Index) HosterListEntry(de.herrlock.manga.index.entity.HosterListEntry) JsonArrayBuilder(javax.json.JsonArrayBuilder)

Example 5 with HosterListEntry

use of de.herrlock.manga.index.entity.HosterListEntry in project Manga by herrlock.

the class Indexer method createIndexFor.

private static HosterList createIndexFor(final Hoster hoster, final IndexerConfiguration conf) {
    logger.traceEntry("({})", hoster);
    Collection<HosterListEntry> elements = hoster.getAvailabile(conf);
    Collection<HosterListEntry> mangas = new TreeSet<>(HosterListEntry.NAME_COMPARATOR);
    mangas.addAll(elements);
    // select random elements from the list
    // final int AMOUNT = 10;
    // final java.util.Random random = new java.util.Random(
    // Long.parseLong( new java.text.SimpleDateFormat( "yyMMdd" ).format( new java.util.Date() ) ) );
    // for ( int i = 0; i < Math.min( elements.size(), AMOUNT ); i++ ) {
    // int rnd = random.nextInt( elements.size() );
    // HosterListEntry entry = com.google.common.collect.Iterables.get( elements, rnd );
    // mangas.add( entry );
    // }
    HosterList hosterList = new HosterList();
    hosterList.setHosterName(hoster.getName());
    hosterList.setMangas(mangas);
    return hosterList;
}
Also used : HosterList(de.herrlock.manga.index.entity.HosterList) TreeSet(java.util.TreeSet) HosterListEntry(de.herrlock.manga.index.entity.HosterListEntry)

Aggregations

HosterListEntry (de.herrlock.manga.index.entity.HosterListEntry)5 TreeSet (java.util.TreeSet)3 MDRuntimeException (de.herrlock.manga.exceptions.MDRuntimeException)2 HosterList (de.herrlock.manga.index.entity.HosterList)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URL (java.net.URL)2 Document (org.jsoup.nodes.Document)2 Element (org.jsoup.nodes.Element)2 Elements (org.jsoup.select.Elements)2 Index (de.herrlock.manga.index.entity.Index)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1