Search in sources :

Example 1 with AttributeType

use of me.devsaki.hentoid.enums.AttributeType in project Hentoid by avluis.

the class SearchActivity method updateAttributeTypeButton.

/**
 * Update the text of a given attribute type button based on the given SparseIntArray and relevant type(s)
 *
 * @param button    Button whose text to update
 * @param attrCount Entry count in every attribute type (key = attribute type code; value = count)
 * @param types     Type(s) to fetch the count for
 */
private void updateAttributeTypeButton(@NonNull final TextView button, @NonNull final SparseIntArray attrCount, AttributeType... types) {
    if (0 == types.length)
        return;
    int count = 0;
    for (AttributeType type : types) count += attrCount.get(type.getCode(), 0);
    button.setText(format("%s (%s)", StringHelper.capitalizeString(getString(types[0].getDisplayName())), count));
    button.setEnabled(count > 0);
}
Also used : AttributeType(me.devsaki.hentoid.enums.AttributeType)

Example 2 with AttributeType

use of me.devsaki.hentoid.enums.AttributeType in project Hentoid by avluis.

the class MusesContent method update.

@Nullable
public Content update(@NonNull final Content content, @Nonnull String url, boolean updateImages) {
    // Gallery pages are the only ones whose gallery links end with numbers
    // The others are album lists
    int nbImages = 0;
    List<String> imagesUrls = new ArrayList<>();
    for (Element thumbLink : thumbLinks) {
        String href = thumbLink.attr("href");
        int numSeparator = href.lastIndexOf('/');
        if (StringHelper.isNumeric(href.substring(numSeparator + 1))) {
            Element img = thumbLink.select("img").first();
            if (null == img)
                continue;
            String src = ParseHelper.getImgSrc(img);
            if (src.isEmpty())
                continue;
            imagesUrls.add(src);
            nbImages++;
        }
    }
    if (nbImages < thumbLinks.size() / 3)
        return new Content().setStatus(StatusContent.IGNORED);
    content.setSite(Site.MUSES);
    String theUrl = canonicalUrl.isEmpty() ? url : canonicalUrl;
    if (theUrl.isEmpty() || 0 == nbImages)
        return content.setStatus(StatusContent.IGNORED);
    content.setUrl(theUrl.replace(Site.MUSES.getUrl(), "").replace("https://comics.8muses.com", ""));
    // == Circle (publisher), Artist and Series
    AttributeMap attributes = new AttributeMap();
    if (breadcrumbs.size() > 1) {
        // Default : book title is the last breadcrumb
        String bookTitle = StringHelper.capitalizeString(breadcrumbs.get(breadcrumbs.size() - 1).text());
        if (breadcrumbs.size() > 2) {
            // Element 1 is always the publisher (using CIRCLE as publisher never appears on the Hentoid UI)
            String publisher = breadcrumbs.get(1).text().toLowerCase();
            if (!nonLegitPublishers.contains(publisher))
                ParseHelper.parseAttribute(attributes, AttributeType.CIRCLE, breadcrumbs.get(1), false, Site.MUSES);
            if (breadcrumbs.size() > 3) {
                // Element 2 is either the author or the series, depending on the publisher
                AttributeType type = AttributeType.SERIE;
                if (publishersWithAuthors.contains(publisher))
                    type = AttributeType.ARTIST;
                ParseHelper.parseAttribute(attributes, type, breadcrumbs.get(2), false, Site.MUSES);
                // Add series to book title if it isn't there already
                if (AttributeType.SERIE == type) {
                    String series = breadcrumbs.get(2).text();
                    if (!bookTitle.toLowerCase().startsWith(series.toLowerCase()))
                        bookTitle = series + " - " + bookTitle;
                }
                if (breadcrumbs.size() > 4) {
                    // All that comes after element 2 contributes to the book title
                    boolean first = true;
                    StringBuilder bookTitleBuilder = new StringBuilder();
                    for (int i = 3; i < breadcrumbs.size(); i++) {
                        if (first)
                            first = false;
                        else
                            bookTitleBuilder.append(" - ");
                        bookTitleBuilder.append(breadcrumbs.get(i).text());
                    }
                    bookTitle = bookTitleBuilder.toString();
                }
            }
        }
        content.setTitle(StringHelper.removeNonPrintableChars(bookTitle));
    }
    if (updateImages) {
        // Cover is duplicated in the code below; no need to decrease nbImages here
        content.setQtyPages(nbImages);
        String[] thumbParts;
        int index = 0;
        List<ImageFile> images = new ArrayList<>();
        // Cover
        ImageFile cover = ImageFile.fromImageUrl(index++, Site.MUSES.getUrl() + imagesUrls.get(0), StatusContent.SAVED, nbImages);
        content.setCoverImageUrl(cover.getUrl());
        cover.setIsCover(true);
        images.add(cover);
        // Images
        for (String u : imagesUrls) {
            thumbParts = u.split("/");
            if (thumbParts.length > 3) {
                // Large dimensions; there's also a medium variant available (fm)
                thumbParts[2] = "fl";
                String imgUrl = Site.MUSES.getUrl() + "/" + thumbParts[1] + "/" + thumbParts[2] + "/" + thumbParts[3];
                // We infer actual book page images have the same format as their thumbs
                images.add(ImageFile.fromImageUrl(index++, imgUrl, StatusContent.SAVED, nbImages));
            }
        }
        content.setImageFiles(images);
    }
    // Tags are not shown on the album page, but on the picture page (!)
    try {
        Document doc = HttpHelper.getOnlineDocument(Site.MUSES.getUrl() + thumbLinks.get(thumbLinks.size() - 1).attr("href"));
        if (doc != null) {
            Elements elements = doc.select(".album-tags a[href*='/search/tag']");
            if (!elements.isEmpty())
                ParseHelper.parseAttributes(attributes, AttributeType.TAG, elements, false, Site.MUSES);
        }
    } catch (IOException e) {
        Timber.e(e);
    }
    content.putAttributes(attributes);
    return content;
}
Also used : ImageFile(me.devsaki.hentoid.database.domains.ImageFile) Element(org.jsoup.nodes.Element) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Document(org.jsoup.nodes.Document) Elements(org.jsoup.select.Elements) AttributeMap(me.devsaki.hentoid.database.domains.AttributeMap) Content(me.devsaki.hentoid.database.domains.Content) StatusContent(me.devsaki.hentoid.enums.StatusContent) AttributeType(me.devsaki.hentoid.enums.AttributeType) Nullable(javax.annotation.Nullable)

Example 3 with AttributeType

use of me.devsaki.hentoid.enums.AttributeType in project Hentoid by avluis.

the class LusciousBookMetadata method update.

public Content update(@NonNull Content content, boolean updateImages) {
    content.setSite(Site.LUSCIOUS);
    AlbumInfo info = data.album.get;
    if (null == info || null == info.url || null == info.title)
        return content.setStatus(StatusContent.IGNORED);
    content.setUrl(info.url);
    content.setTitle(StringHelper.removeNonPrintableChars(info.title));
    // result.setQtyPages(info.number_of_pictures);  <-- does not reflect the actual number of pictures reachable via the Luscious API / website
    content.setCoverImageUrl(info.cover.url);
    AttributeMap attributes = new AttributeMap();
    if (info.language != null) {
        String name = StringHelper.removeNonPrintableChars(info.language.title.replace(" Language", ""));
        Attribute attribute = new Attribute(AttributeType.LANGUAGE, name, RELATIVE_URL_PREFIX + info.language.url, Site.LUSCIOUS);
        attributes.add(attribute);
    }
    if (info.tags != null)
        for (TagInfo tag : info.tags) {
            String name = StringHelper.removeNonPrintableChars(tag.text);
            if (name.contains(":"))
                // Clean all tags starting with "Type :" (e.g. "Artist : someguy")
                name = name.substring(name.indexOf(':') + 1).trim();
            AttributeType type = AttributeType.TAG;
            if (tag.url.startsWith("/tags/artist:"))
                type = AttributeType.ARTIST;
            else if (tag.url.startsWith("/tags/parody:"))
                type = AttributeType.SERIE;
            else if (tag.url.startsWith("/tags/character:"))
                type = AttributeType.CHARACTER;
            else if (tag.url.startsWith("/tags/series:"))
                type = AttributeType.SERIE;
            else if (tag.url.startsWith("/tags/group:"))
                type = AttributeType.ARTIST;
            Attribute attribute = new Attribute(type, name, RELATIVE_URL_PREFIX + tag.url, Site.LUSCIOUS);
            attributes.add(attribute);
        }
    content.putAttributes(attributes);
    if (updateImages) {
        content.setImageFiles(Collections.emptyList());
        content.setQtyPages(0);
    }
    return content;
}
Also used : AttributeMap(me.devsaki.hentoid.database.domains.AttributeMap) Attribute(me.devsaki.hentoid.database.domains.Attribute) AttributeType(me.devsaki.hentoid.enums.AttributeType)

Example 4 with AttributeType

use of me.devsaki.hentoid.enums.AttributeType in project Hentoid by avluis.

the class PixivIllustMetadata method getAttributes.

public List<Attribute> getAttributes() {
    List<Attribute> result = new ArrayList<>();
    if (error || null == body || null == body.illust_details)
        return result;
    IllustBody illustData = body;
    Attribute attribute = new Attribute(AttributeType.ARTIST, illustData.getUserName(), Site.PIXIV.getUrl() + "user/" + illustData.getUserId(), Site.PIXIV);
    result.add(attribute);
    for (Pair<String, String> tag : illustData.getTags()) {
        String name = StringHelper.removeNonPrintableChars(tag.second);
        AttributeType type = AttributeType.TAG;
        attribute = new Attribute(type, name, Site.PIXIV.getUrl() + "tags/" + tag.first, Site.PIXIV);
        result.add(attribute);
    }
    return result;
}
Also used : Attribute(me.devsaki.hentoid.database.domains.Attribute) AttributeType(me.devsaki.hentoid.enums.AttributeType) ArrayList(java.util.ArrayList)

Example 5 with AttributeType

use of me.devsaki.hentoid.enums.AttributeType in project Hentoid by avluis.

the class ObjectBoxDAO method pagedAttributeSearch.

private AttributeQueryResult pagedAttributeSearch(@NonNull List<AttributeType> attrTypes, String filter, List<Attribute> attrs, boolean filterFavourites, int sortOrder, int pageNum, int itemPerPage, boolean bookCompletedOnly, boolean bookNotCompletedOnly) {
    AttributeQueryResult result = new AttributeQueryResult();
    if (!attrTypes.isEmpty()) {
        if (attrTypes.get(0).equals(AttributeType.SOURCE)) {
            result.attributes.addAll(db.selectAvailableSources(attrs));
            result.totalSelectedAttributes = result.attributes.size();
        } else {
            for (AttributeType type : attrTypes) {
                // TODO fix sorting when concatenating both lists
                result.attributes.addAll(db.selectAvailableAttributes(type, attrs, filter, filterFavourites, sortOrder, pageNum, itemPerPage, bookCompletedOnly, bookNotCompletedOnly));
                result.totalSelectedAttributes += db.countAvailableAttributes(type, attrs, filter, filterFavourites, bookCompletedOnly, bookNotCompletedOnly);
            }
        }
    }
    return result;
}
Also used : AttributeType(me.devsaki.hentoid.enums.AttributeType)

Aggregations

AttributeType (me.devsaki.hentoid.enums.AttributeType)14 Attribute (me.devsaki.hentoid.database.domains.Attribute)8 AttributeMap (me.devsaki.hentoid.database.domains.AttributeMap)8 ArrayList (java.util.ArrayList)7 Collectors.toList (com.annimon.stream.Collectors.toList)5 EnumMap (java.util.EnumMap)5 List (java.util.List)5 Map (java.util.Map)5 Content (me.devsaki.hentoid.database.domains.Content)5 StatusContent (me.devsaki.hentoid.enums.StatusContent)5 Nullable (javax.annotation.Nullable)3 SparseIntArray (android.util.SparseIntArray)2 Group (me.devsaki.hentoid.database.domains.Group)2 ImageFile (me.devsaki.hentoid.database.domains.ImageFile)2 Site (me.devsaki.hentoid.enums.Site)2 Context (android.content.Context)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 NonNull (androidx.annotation.NonNull)1