Search in sources :

Example 1 with HosterList

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

the class Indexer method createIndex.

public static Index createIndex(final IndexerConfiguration conf) {
    logger.traceEntry("({})", conf);
    Iterable<Hoster> values;
    if (conf.getUrl() == null) {
        values = Hosters.values();
    } else {
        values = ImmutableSet.of(Hosters.tryGetHostByURL(conf.getUrl()));
    }
    Collection<HosterList> hosterEntries = new TreeSet<>(HosterList.HOSTER_NAME_COMPARATOR);
    for (Hoster hoster : values) {
        HosterList indexFor = createIndexFor(hoster, conf);
        hosterEntries.add(indexFor);
    }
    Index index = new Index();
    index.setHosters(hosterEntries);
    return index;
}
Also used : HosterList(de.herrlock.manga.index.entity.HosterList) TreeSet(java.util.TreeSet) Hoster(de.herrlock.manga.host.Hoster) Index(de.herrlock.manga.index.entity.Index)

Example 2 with HosterList

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

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

HosterList (de.herrlock.manga.index.entity.HosterList)3 HosterListEntry (de.herrlock.manga.index.entity.HosterListEntry)2 Index (de.herrlock.manga.index.entity.Index)2 TreeSet (java.util.TreeSet)2 Hoster (de.herrlock.manga.host.Hoster)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1