Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fail when connecting to "Habitación principal" #5

Closed
vlad88sv opened this issue Aug 25, 2020 · 9 comments
Closed

Fail when connecting to "Habitación principal" #5

vlad88sv opened this issue Aug 25, 2020 · 9 comments

Comments

@vlad88sv
Copy link

Hi, thank you for making available your project!

I have an issue when attempting: chromecast_mpris -n "Habitación principal"

On Chrome this works OK:
image

Does this tool support tilde (áéíóú) in the name?

@vlad88sv
Copy link
Author

chromecast_mpris -l 10 -n "Habitación principal"
DEBUG:pychromecast.discovery:add_service _googlecast._tcp.local., Chromecast-406c2bcdd5995755059b5bb045326056._googlecast._tcp.local.
DEBUG:pychromecast:_get_chromecast_from_service {'Chromecast-406c2bcdd5995755059b5bb045326056._googlecast._tcp.local.'}
INFO:pychromecast:Querying device status
DEBUG:pychromecast.discovery:get_info_from_service resolved service Chromecast-406c2bcdd5995755059b5bb045326056._googlecast._tcp.local. to service_info ServiceInfo(type='_googlecast._tcp.local.', name='Chromecast-406c2bcdd5995755059b5bb045326056._googlecast._tcp.local.', addresses=[b'\xc0\xa8\x00\xa5'], port=8009, weight=0, priority=0, server='406c2bcd-d599-5755-059b-5bb045326056.local.', properties={b'id': b'406c2bcdd5995755059b5bb045326056', b'cd': b'6E597F9967700486035F4FCC5CFCE5B3', b'rm': b'97AB710A769C3FFD', b've': b'05', b'md': b'Chromecast', b'ic': b'/setup/icon.png', b'fn': b'Habitaci\xc3\xb3n principal', b'ca': b'200709', b'st': b'0', b'bs': b'FA8FCA70AEFA', b'nf': b'1', b'rs': b''})
DEBUG:pychromecast.dial:Resolved service Chromecast-406c2bcdd5995755059b5bb045326056._googlecast._tcp.local. to 192.168.0.165
DEBUG:urllib3.connectionpool:Starting new HTTP connection (1): 192.168.0.165:8008
DEBUG:urllib3.connectionpool:http://192.168.0.165:8008 "GET /setup/eureka_info?options=detail HTTP/1.1" 200 1351
Traceback (most recent call last):
File "/usr/local/bin/chromecast_mpris", line 8, in <module>
sys.exit(cmd())
File "/usr/lib/python3/dist-packages/click/core.py", line 764, in __call__
return self.main(*args, **kwargs)
File "/usr/lib/python3/dist-packages/click/core.py", line 717, in main
rv = self.invoke(ctx)
File "/usr/lib/python3/dist-packages/click/core.py", line 956, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/usr/lib/python3/dist-packages/click/core.py", line 555, in invoke
return callback(*args, **kwargs)
File "/usr/local/lib/python3.8/dist-packages/chromecast_mpris/command.py", line 14, in cmd
main(name, log_level)
File "/usr/local/lib/python3.8/dist-packages/chromecast_mpris/main.py", line 33, in main
mpris = create_adapters_and_server(name)
File "/usr/local/lib/python3.8/dist-packages/chromecast_mpris/main.py", line 14, in create_adapters_and_server
chromecast = get_chromecast(chromecast_name)
File "/usr/local/lib/python3.8/dist-packages/chromecast_mpris/base.py", line 73, in get_chromecast
if chromecast.name.lower() == name:
AttributeError: 'list' object has no attribute 'name'

@alexdelorenzo
Copy link
Owner

Thanks for opening an issue and providing logs with your report. To fix your issue, please use the latest version on PyPI:

pip3 install chromecast_mpris==0.2.6

Using this version, I renamed my Chromecast to "Habitación principal" and was able to use chromecast_mpris to connect to and control it.

~ ❯ chromecast_mpris -n "Habitación principal"                                                                                
INFO:pychromecast:Querying device status                                                                                      
INFO:mpris_server.server:MPRIS server connected to D-Bus session bus
INFO:pychromecast.controllers:Receiver:setting volume to 1.0

@vlad88sv
Copy link
Author

Nice thank you!!! it worked 99.99% great!!! or probably this is an issue with KDE widget?

image

@alexdelorenzo
Copy link
Owner

Nice thank you!!! it worked 99.99% great!!! or probably this is an issue with KDE widget?

image

Awesome, glad it worked!

I'll look into the MPRIS and D-Bus spec to see if it allows for accented characters. As a compatibility mitigation, chromecast_mpris currently strips non-alphabetic, non-numeric and non-ASCII characters from the MPRIS interface name, which explains why your Chromecast's name appears the way it does.

@alexdelorenzo
Copy link
Owner

So I looked into the MPRIS spec, and it has this to say about interface names:

Note: According to the D-Bus specification, the unique identifier "must only contain the ASCII characters '[A-Z][a-z][0-9]_-'" and "must not begin with a digit".

Right now chromecast_mpris just omits invalid characters until a valid interface name is left, or it generates a valid name randomly.

As this isn't an issue that I'll run into, I do want to solve it in a way that makes sense to users who do run into it. Options as I see them are:

  1. Leave it as is
  2. Map and replace common accented characters with their ASCII relatives
  3. Generate a D-Bus identifier instead of doing character removal or replacement
  4. Allow the user to override the interface name when invoking chromecast_mpris

Option 2 is a problem of enumerating i18n edge cases and replacing them with valid ASCII characters. That's something that I'd rather avoid, so I'm leaning on option 4 by allowing the user to override the interface name via the CLI.

Does that seem like a good solution, @vlad88sv?

@vlad88sv
Copy link
Author

Thank you so much for the research effort!!!

I would say #2 would be lovely from a user experience perspective, and #4 is like a good option to have irregardless of #2 being implemented, just my 2cts.

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from unicodedata import normalize
trans_tab = dict.fromkeys(map(ord, u'\u0301\u0308'), None)
s="Habitación principal"
s = normalize('NFKC', normalize('NFKD', s).translate(trans_tab))
print(s)

This outputs:
Habitacion principal

@alexdelorenzo
Copy link
Owner

alexdelorenzo commented Aug 27, 2020

Thanks for the code example, I played with it and it made me reconsider option 2. I found Unidecode, which suits this use case well and I implemented it in chromecast_mpris's dependency, mpris_server.

You can try it out by upgrading both via pip:

pip3 install chromecast_mpris==0.2.8 mpris_server==0.2.8

I haven't tested it out with a Chromecast with an accent in its name, though. If you find the time, try it out and let me know how it goes.

edit: the correct version is 0.2.8, not 0.2.7

@vlad88sv
Copy link
Author

Works perfectly now! thank you!!!

image

@alexdelorenzo
Copy link
Owner

Awesome, glad to hear it!

I'm going to close this issue, please feel free to comment or re-open it should anyone encounter this issue again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants