paul-nameless / tg

terminal telegram client
The Unlicense
932 stars 76 forks source link

Sticker view is broken #236

Closed delightfuldude closed 2 years ago

delightfuldude commented 3 years ago

From the readme.md:

_"to open stickers and animated ones (thumbnail preview) you need to set in mailcap appropriate handler and have app which will open webp file:

image/webp; mpv %s "_

This does not work anymore, although mpv is able to view WebP on my system. When I'm pressing "l" to open the sticker, nothing happens. I am on Arch Linux.

Noodlez1232 commented 3 years ago

I'd like to expand on this. I've gotten the error message from doing this here:

ERROR [2021-08-22 16:36:41,356] controllers.py:776 - handle | Error happend in key handle loop
Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/tg/controllers.py", line 770, in handle
    res = fun(self, repeat_factor)  # type: ignore
  File "/usr/lib/python3.9/site-packages/tg/controllers.py", line 56, in _no_repeat_factor
    return fun(self)
  File "/usr/lib/python3.9/site-packages/tg/controllers.py", line 528, in open_current_msg
    self._open_msg(msg)
  File "/usr/lib/python3.9/site-packages/tg/controllers.py", line 500, in _open_msg
    path = msg.local_path
  File "/usr/lib/python3.9/site-packages/tg/msg.py", line 125, in local_path
    return doc["local"]["path"]
KeyError: 'local'
JingMatrix commented 3 years ago

I solved this problem by modifying this function https://github.com/paul-nameless/tg/blob/751156535897f513ab6f15e5167a928953c60fa6/tg/msg.py#L39

as:

def get_doc(cls, msg: Dict[str, Any], deep: int = 10) -> Dict[str, Any]:
        doc = msg["content"]
        _type = doc["@type"]
        fields = cls.fields_mapping.get(_type)
        if fields is None:
            log.error("msg type not supported: %s", _type)
            return {}
        for field in fields[:deep]:
            if isinstance(field, int):
                doc = doc[field]
            else:
                doc = doc.get(field)
            if 'file' in doc:
                return doc["file"]
            if doc is None:
                return {}
        return doc
milescajus commented 3 years ago

I solved this problem by modifying this function

https://github.com/paul-nameless/tg/blob/751156535897f513ab6f15e5167a928953c60fa6/tg/msg.py#L39

This only worked for me by also modifying this function: https://github.com/paul-nameless/tg/blob/751156535897f513ab6f15e5167a928953c60fa6/tg/utils.py#L82 in order to get around the current absence of WebP in Python's mimetypes module. This means the guess_type() function returns None for WebP and thus defaults to open or xdg-open to handle the file, bypassing the mailcap file. For example:

    if file_path.split(".")[-1] == "webp":
            mtype = "image/webp"
    else:
            mtype, _ = mimetypes.guess_type(file_path)

This would also be needed anywhere else guess_type() is used, until WebP is included in mimetypes (which will be nice to avoid hacky workarounds like this).

banderlog commented 2 years ago

I assume that this fix is not released yet, so that's why pip installed version do not open stickers?

UPD: Yes, it is. And I had to set xdg-open defaults for image/webp, mailcap was not working for it.

And I had to set xdg-open defaults for image/webp, mailcap was not working for it, while still working for other image extensions.

BTW, is there a way to open animated stickers?

And I keep getting segmentation fault: https://github.com/paul-nameless/tg/issues/252