flathub-infra / website

Monorepo with website and API
https://flathub.org
Apache License 2.0
232 stars 88 forks source link

Show OARS information #114

Open JakobDev opened 2 years ago

JakobDev commented 2 years ago

The OARS informations are currently missing on the Website

razzeee commented 1 year ago

I've been playing around with this for some days, trying to use the c api via pygobject to construct a content rating and call the minimum age method. But it seems like python still hates me.

https://github.com/ximion/appstream/blob/ad04eb71fa85b6c2fb5c62948cf01320407dc0ac/qt/contentrating.cpp#L109

razzeee commented 8 months ago

When we do this, we should also expose it via schema.org if possible https://schema.org/contentRating

xi commented 4 months ago

I am currently looking into this. I want to document my progress so far:

The code that was used in gnome-software was upstreamed in https://github.com/ximion/appstream/commit/18c8b18d5a131669fa25a01d283a06f896ca438c

We probably want to do something like this:

import gi

gi.require_version("AppStream", "1.0")
from gi.repository import AppStream

LEVELS = {
    'unknown': AppStream.ContentRatingValue.UNKNOWN,
    'none': AppStream.ContentRatingValue.NONE,
    'mild': AppStream.ContentRatingValue.MILD,
    'moderate': AppStream.ContentRatingValue.MODERATE,
    'intense': AppStream.ContentRatingValue.INTENSE,
}

def get_content_rating_summary(data: dict, locale: str) -> tuple[str, str]:
    system = AppStream.ContentRatingSystem.from_locale(locale)

    age = max([
        AppStream.ContentRating.attribute_to_csm_age(key, LEVELS[value])
        for key, value in data.items()
    ], default=0)

    return (
        AppStream.ContentRatingSystem.format_age(system, age),
        AppStream.ContentRatingSystem.to_string(system),
    )

print(get_content_rating_summary({
    'violence-cartoon': 'moderate',
    'violence-fantasy': 'intense',
}, 'de_DE'))
# ('6', 'USK')
sidt4 commented 1 month ago

I think this issue should be addressed as a priority. Refer https://github.com/flathub/net.krafting.PleasureDVR/issues/2.