darkdragn / party

A quick *.party downloader
84 stars 12 forks source link

Kemono not working for some services where id isn't numeric #5

Closed HornyProgrammer closed 1 year ago

HornyProgrammer commented 1 year ago

Solution: in user.py -> User -> get_user(...) the return should be

   try:
        attr = "id"
        return next(
            (i for i in users if i.service == service and getattr(i, attr) == search)
        )
    except StopIteration:
        attr = "name"
        return next(
            (i for i in users if i.service == service and getattr(i, attr) == search)
        )

and remove attr = "id" if search.isnumeric() else "name" Why? Some of the new services have ids which are not numeric. Therefore this starts with id as default, if it doesn't work then moves to using the name attribute. After testing it on my own this works. This doesn't fix all the services as some still don't like to work but it fixes the ones where id isn't number

tldr: make user.py User.get_user(...) the following

@classmethod
def get_user(cls, base_url: str, service: str, search: str):
    """Return a User object from a match against service and search.

    Args:
        base_url: kemono.party or coomer.party
        service: { kemono: [patreon, fanbox, fantia, etc...], coomer: [onlyfans]}
        search: user id or user name
    Returns:
        User
    """
    users = cls.generate_users(base_url)
    try:
        attr = "id"
        return next(
            (i for i in users if i.service == service and getattr(i, attr) == search)
        )
    except StopIteration:
        attr = "name"
        return next(
            (i for i in users if i.service == service and getattr(i, attr) == search)
        )